[rspec-users] Why does this stub doesn't work?

Haim Ashkenazi haim.ashkenazi at gmail.com
Sun Oct 24 11:21:30 EDT 2010


Hi

I wonder why this stub doesn't work:

# ruby 1.8.7, rspec 2.0.1
require 'rubygems'
require 'rspec'

Rspec.configure do |c|
  c.mock_with :rspec
end

class SayHello
  def say_hello
    "hello"
  end
end

describe "test string" do
  it "should interpret stub correctly" do
    SayHello.stub!(:say_hello).and_return('NO')
    sh = SayHello.new()
    sh.say_hello.should eql('NO')
  end
end

The result is:
tryouts ➤ rspec -f n test_spec.rb                                              

test string
  should interpret stub correctly (FAILED - 1)

Failures:
  1) test string should interpret stub correctly
     Failure/Error: sh.say_hello.should eql('NO')
     
     expected "NO"
          got "hello"
     
     (compared using eql?)
     # ./test_spec.rb:18

Finished in 0.0016 seconds
1 example, 1 failure
Any ideas?
Bye
Haim Ashkenazi



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101024/369fda1b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101024/369fda1b/attachment-0001.bin>


More information about the rspec-users mailing list