0

Alex Chaffee 的 test-first ruby​​ 课程教授如何使用 rspec。我目前坚持第一次练习,00_hello. 我按照指示创建了一个hello.rb包含代码的文件:

def hello
   "Hello!"
end

并将其放在00_hello带有hello_specs.rb. 当我rake从目录中输入终端时00_hello,我收到以下错误,这些错误与 rspec 错误不同:

(in /Users/stevenjli/Documents/App Academy/learn_ruby-master)
/Users/stevenjli/Documents/App Academy/learn_ruby-master/00_hello/hello_spec.rb:116:in `require':     cannot load such file -- hello (LoadError)
from /Users/stevenjli/Documents/App Academy/learn_ruby-master/00_hello/hello_spec.rb:116:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `load'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `block in load_spec_files'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `load_spec_files'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:22:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:80:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:17:in `block in autorun'
rake aborted!

/usr/local/rvm/rubies/ruby-1.9.3-p286/bin/ruby -S rspec /Users/stevenjli/Documents/App\         
Academy/learn_ruby-master/00_hello/hello_spec.rb -I/Users/stevenjli/Documents/App   
Academy/learn_ruby-master/00_hello -I/Users/stevenjli/Documents/App Academy/learn_ruby-master 
/00_hello/solution -f documentation -r ./rspec_config failed

我猜我的设置有问题。这是我正在使用的版本。

  • Mac OS 10.8.2
  • 红宝石版本 1.9.3
  • 耙 0.9.2.2
  • rspec 版本 2.12.2
4

3 回答 3

2

如果它对任何人有帮助,我在 ruby​​ 1.9.3 上遇到了完全相同的问题。我的解决方案是三方面的:

  1. gem install rspec; bundle update; bundle install
  2. cd进00_hello,然后编辑require行读取require './hello'
  3. rspec hello_spec.rb
于 2013-04-03T01:50:54.783 回答
2

检查 00_hello 文件夹的目录结构。应该是这样的

 ├── hello.rb
 ├── hello_spec.rb
 └── index.html

Rakefilegiven bylearn_ruby负责将正确的目录添加到加载路径,因此您不必担心它,除非您在不了解的情况下在某处更改了它。

如果您仍有问题,请Rakefile在此处发布

于 2013-01-12T03:50:54.527 回答
0

您是否尝试过从 test-first 课程的根目录运行 rake?

halfelf 也可能是对的,也许他们一直在运行包含.在 $LOAD_PATH 中的 ruby​​ 1.8,而您正在运行的 1.9.3 没有这样做,因为require_relativeetc没有必要。

于 2013-01-11T11:04:31.877 回答