测试优先Ruby Hello实验室

时间:2013-01-11 10:31:09

标签: ruby rspec

Alex Chaffee的测试优先红宝石课程教授如何使用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
  • Ruby版本1.9.3
  • rake 0.9.2.2
  • rspec version 2.12.2

3 个答案:

答案 0 :(得分:2)

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

 ├── hello.rb
 ├── hello_spec.rb
 └── index.html
Rakefile提供的

learn_ruby负责为加载路径添加正确的目录,因此您不必担心它,除非您在不理解的情况下将其更改为某个地方。

如果您仍然遇到问题,请发布Rakefile此处

答案 1 :(得分: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

答案 2 :(得分:0)

您是否尝试过从测试优先课程的根目录运行rake?

也有一半可能是正确的,也许他们一直在运行ruby 1.8,其中包含.到$ LOAD_PATH,而你运行的是1.9.3但是没有这样做,因为{{1}不需要等等。