我申请AppAcademy并需要做一些练习,所以我根据https://github.com/appacademy/test-first-ruby
的要求下载了ZIP我将文件保存到桌面并在文件夹内运行bundle install
。然后通过终端我转到练习所在的spec文件夹并运行以下命令:
bundle exec rspec spec/00_hello_spec.rb
我收到以下错误:
Macintosh-2:spec Michael$ bundle exec rspec spec/00_hello_spec.rb
/Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core 2.99.1/lib/rspec/core/configuration.rb:1065:in `load': cannot load such file -- /Users/Michael/Desktop/RubyCodes/test-first-ruby-master/spec/spec/00_hello_spec.rb (LoadError)
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in `block in load_spec_files'
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in `each'
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in `load_spec_files'
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/command_line.rb:18:in `run'
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:103:in `run'
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:17:in `block in autorun'
我有ruby 2.1.3,bundler 1.7.9和rspec 2.99.1。
导致此错误的原因是什么?如何解决?
答案 0 :(得分:1)
看起来您可能正在从错误的目录运行命令。请考虑您的错误消息:
`load': cannot load such file -- /Users/Michael/Desktop/RubyCodes/test-first-ruby-master/spec/spec/00_hello_spec.rb (LoadError)
并注意spec
目录在错误消息的文件路径中出现两次。这意味着spec
目录中存在spec
目录。更可能只有一个spec
目录。在同一个终端上下文中,运行以下命令以启动一个目录级别:
cd ..
然后再次尝试你的命令:
bundle exec rspec spec/00_hello_spec.rb
您可以将cd
视为代表“更改目录”,而..
代表当前级别之上的一个目录级别(当前级别用.
表示)。
或者,您可以在spec
目录中运行以下命令:
bundle exec rspec 00_hello_spec.rb