定位gem文件的问题?

时间:2012-03-08 22:16:29

标签: ruby rubygems rvm

我正在尝试在this教程之后构建Ruby Gem,但我无法配置rspec,因为它无法找到我的gem。

$ gem list | grep gemname
gemname (0.0.1.alpha)

$ rake spec
/Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/bin/ruby -S rspec ./spec/gemname_spec.rb
/Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such  file -- gemname (LoadError)
    from /Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/rudolph9/Developer/gemname/spec/spec_helper.rb:2:in `<top (required)>'
    from /Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/rudolph9/Developer/gemname/spec/gemname_spec.rb:1:in `<top (required)>'
    from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load'
    from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
    from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
    from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
    from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
    from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
    from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
rake aborted!
/Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/bin/ruby -S rspec ./spec/gemname_spec.rb failed

Tasks: TOP => default => spec
(See full trace by running task with --trace) 

我这可能与使用rvm或者前面提到的教程中配置rake文件的方式有关,但我不确定。

造成这个问题的原因是什么?

2 个答案:

答案 0 :(得分:1)

看起来这是从require文件中的spec_helper.rb冒出来的。您的主要宝石类是否与宝石的名称相同?你应该要求主类而不是宝石的名字。尝试将require语句改为以下之一,看看是否得到了不同的结果。

require 'gemname'
# Or
require 'gemname.rb'
# Or
require './path/to/gemname.rb'

我还会尝试从IRB中要求该课程,看看它会起作用的情况。

答案 1 :(得分:0)

当您构建一个gem并希望通过它的名称来命名时,您需要提供:

lib/gemname.rb

这个文件中的内容不太重要,只是你想要的其他内容:

require 'gemname/nothing'

此文件也存在:

lib/gemname/nothing.rb