Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec Ruby Basic Example Error

Tags:

ruby

rspec

I'm trying to run the basic starter example for using rspec found here: http://rspec.info/.

When I type in the command prompt

ruby bowling_spec.rb

I get the following error

Test

# 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

Code

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

  def score
    0
  end
end

Error Message

internal:lib/rubygems/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 `'

like image 844
John Avatar asked Feb 22 '11 02:02

John


1 Answers

This is a great simple example to get started with rspec. To make everything work do the following:

  1. Place your bowling.rb file in lib/bowling.rb.
  2. Place your bowling_spec.rb file in spec/bowling_spec.rb.
  3. Run the command rspec spec/bowling_spec.rb if you are using rpsec 2.
  4. Run the command spec spec/bowling_spec.rb if you are using rspec 1.

Also, an updated example can be found here.

like image 174
Pan Thomakos Avatar answered Oct 16 '22 08:10

Pan Thomakos