我正在教自己ruby并且使用过Testfirst.org的课程,所以我之前使用过rspec,但是在不同的目录中。现在我正在完成以下指南:http://guides.railsgirls.com/testing-rspec/
...在第一个“rspec spec / lib / idea_spec.rb”我得到:
Amys-MacBook-Air:railsgirls alightholder$ rspec spec/lib/idea_spec.rb
/Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load': cannot load such file -- /Users/alightholder/Ruby/railsgirls_stuff/railsgirls/spec/lib/idea_spec.rb (LoadError)
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `each'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:96:in `setup'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:84:in `run'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:69:in `run'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/exe/rspec:4:in `<top (required)>'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/bin/rspec:19:in `load'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/bin/rspec:19:in `<main>'
这对我来说看起来像配置错误。我尝试在我的idea_spec.rb和/ spec /目录之间插入/ lib /文件夹,但这似乎没有帮助。我很确定我在正确的文件夹中,到目前为止,这个网站上没有任何指南是不准确或不完整的,所以我不知道为什么我收到加载错误而不是测试运行。< / p>
for“rspec spec / idea_spec.rb”我得到:
/Users/alightholder/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- idea (LoadError)
from /Users/alightholder/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/alightholder/Ruby/railsgirls_stuff/railsgirls/spec/idea_spec.rb:2:in `<top (required)>'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `each'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:96:in `setup'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:84:in `run'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:69:in `run'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/exe/rspec:4:in `<top (required)>'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/bin/rspec:19:in `load'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/bin/rspec:19:in `<main>'
答案 0 :(得分:0)
/Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load': cannot load such file -- /Users/alightholder/Ruby/railsgirls_stuff/railsgirls/spec/lib/idea_spec.rb (LoadError)
尝试执行rspec spec/idea_spec.rb
,即不要包含lib
。
看起来你已经在名为railsgirls
的目录中初始化了rspec,该目录应该生成一个名为spec
的子目录。在idea_spec.rb
目录中创建spec
后,该文件的路径应为spec/idea_spec.rb
,而不是spec/lib/idea_spec.rb
。我不知道为什么该指南的作者包括lib
。另外,请务必从rspec spec/idea_spec.rb
目录执行railsgirls
。
/Users/alightholder/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- idea (LoadError)
在idea_spec.rb
内,尝试更改
require "idea"
到
require "/Users/alightholder/Ruby/railsgirls_stuff/railsgirls/idea"
我假设您的idea.rb
位于您的railsgirls
目录中 - 如果不正确,请将我使用的绝对路径替换为您idea.rb
的正确绝对路径。< / p>
之后,如果您可以在没有收到LoadError的情况下运行rspec,那么请从
更改require "/Users/alightholder/Ruby/railsgirls_stuff/railsgirls/idea"
(即,给require
绝对路径)简单地
require_relative "../idea"