1

I've installed rspec inside my test NitrousIO box for ruby/rails. I'm trying to run a simple test but got an error:

action@testbox-11814:~$ rspec thetest.rb                                                                                              
/home/action/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load suc
h file -- test (LoadError)                                                                                                            
        from /home/action/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'    
        from /home/action/thetest.rb:1:in `<top (required)>'                                                                          
        from /home/action/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.2/lib/rspec/core/configuration.rb:896:in `load'              
        from /home/action/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.2/lib/rspec/core/configuration.rb:896:in `block in load_spec_
files'                                                                                                                                
        from /home/action/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.2/lib/rspec/core/configuration.rb:896:in `each'              
        from /home/action/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.2/lib/rspec/core/configuration.rb:896:in `load_spec_files'   
        from /home/action/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.2/lib/rspec/core/command_line.rb:22:in `run'                 
        from /home/action/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.2/lib/rspec/core/runner.rb:80:in `run'                       
        from /home/action/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.2/lib/rspec/core/runner.rb:17:in `block in autorun'   

I just have two .rb files, "test" and "thetest", this last one is the spec, sorry for the names, that quite weird but I'm just starting with NitrousIO :)

The same problem occurs when I ommit the .rb running "rspec thetest"

4

1 回答 1

2

首先,您应该查看一些 rspec教程

这是一个简单而基本的示例,取自此处。在 NitrousIO 上的控制台中,键入:

gem install rspec
mkdir lib
mkdir spec
touch lib/bowling.rb
touch spec/bowling_spec.rb

库/保龄球.rb

require 'bowling'

describe Bowling, "#score" do
  it "returns 0 for all gutter game" do
    bowling = Bowling.new
    20.times { bowling.hit(0) }
    bowling.score.should == 0
  end
end

规格/保龄球规格.rb

class Bowling
  def hit(pins)
  end

  def score
    0
  end
end

然后运行:

rspec 规范/bowling_spec.rb

于 2013-07-12T11:51:06.657 回答