自定义Gem执行失败,并显示NoMethodError



我写了我的第一个gem (ruby新手警报!)为了将它部署到我的本地gem目录中,我运行:

bundle install
bundle exec rake install
此时,我尝试从命令行运行我的gem。我得到一个神秘的错误:
my_gem
Gem File Location:
C:/ruby193/lib/ruby/gems/1.9.1/gems/my_gem-0.0.1/Gemfile
fatal: Not a git repository (or any of the parent directories): .git
getting Gem.bin_path()
C:/ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler/rubygems_integration.rb:305:in `block in replace_bin_path': undefined method `name' for nil:NilClass (NoMethodError)
    from C:/ruby193/lib/ruby/gems/1.9.1/gems/my_gem-0.0.1/bin/my_gem:20:in `<top (required)>'
    from C:/ruby193/bin/my_gem:23:in `load'
    from C:/ruby193/bin/my_gem:23:in `<main>'

当我运行bundle install时,它用自己的代码替换了bin/my_gem的内容。我确实添加了修改这个文件稍微尝试调试。失败似乎发生在Gem.bin_path中。以下是bin/my_gem目录的内容:

#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'my_gem' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
   Pathname.new(__FILE__).realpath)
puts "Gem File Location: "
puts(ENV['BUNDLE_GEMFILE'])
require 'rubygems'
require 'bundler/setup'
puts "getting Gem.bin_path()"
path = Gem.bin_path('my_gem', 'my_gem') # this is the line that causes the error
puts "Gem.bin_path(): #{path}"
load Gem.bin_path('my_gem', 'my_gem')

我不知道下一步要做什么,除了重新开始一个新的宝石。什么好主意吗?

看起来你遇到这个问题了https://github.com/bundler/bundler/issues/2838

因为Bundler记得传递给install的标志,如果您过去曾经运行过bundle install --binstubs,它将在随后运行bundle install时重新生成binstub。您可以运行bundle config --delete bin来删除该设置,然后恢复原始的可执行文件。

相关内容

最新更新