Rspec Ruby基本示例错误

Joh*_*ohn 8 ruby rspec

我正在尝试运行使用rspec的基本启动示例:http://rspec.info/.

当我在命令提示符下键入时

ruby bowling_spec.rb

我收到以下错误

测试

# bowling_spec.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
Run Code Online (Sandbox Code Playgroud)

# bowling.rb
class Bowling
  def hit(pins)
  end

  def score
    0
  end
end
Run Code Online (Sandbox Code Playgroud)

错误信息

internal:lib/ruby​​gems/custom_require:29:in require': no such file to load -- bowling (LoadError) from <internal:lib/rubygems/custom_require>:29:inrequire'from bowling_spec.rb:2:in`

Pan*_*kos 16

这是一个开始使用rspec的简单示例.要使一切正常,请执行以下操作:

  1. 将bowling.rb文件放在lib/bowling.rb中.
  2. 将您的bowling_spec.rb文件放在spec/bowling_spec.rb中.
  3. rspec spec/bowling_spec.rb如果您使用的是rpsec 2,请运行该命令.
  4. spec spec/bowling_spec.rb如果使用rspec 1,请运行该命令.

此外,可以在此处找到更新的示例.