views:

39

answers:

1

This is using RSpec2 - no matter what happens I seem to get the following error when an expectation is not matched. I'm sure (though I cannot try for a while) in version 1 the following code would state that the method 'methods' was not called.

The code snippet below demo's this problem - when un-commenting the method in initialize, the test will pass. Remove the comment and the generic error message is returned.

describe "Test" do
  it "should do" do
    my_mock = mock("my mock")
    my_mock.should_receive(:methods)
    obj = Shaun.new(my_mock)
  end
end

class Shaun
  def initialize(mock)
    #mock.methods
  end
end

Error

Failures:
  1) Test should do
C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_formatter.rb:138:in `block in find_failed_line':
 undefined method `downcase' for nil:NilClass (NoMethodError)
        from C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_formatter.rb:136:in `each'
        from C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_formatter.rb:136:in `detect'
        from C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_formatter.rb:136:in `find_failed_li
ne'
        from C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_formatter.rb:122:in `read_failed_li
ne'
        from C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_text_formatter.rb:27:in `block in d
ump_failures'

+1  A: 

Works fine over here, with rspec 2.0.1 and REE 1.8.7. Will need to check again with 1.9.2 as I don't have it on this system yet.

when commented:

Failures:
1) Test should do
   Failure/Error: my_mock.should_receive(:methods)
   (Mock "my mock").methods(any args)
       expected: 1 time
       received: 0 times
   # ./test_rspec.rb:4
Bitterzoet
Removed 2.0 and re-installed as version 2.0.1 and it works. Very strange. At least two people have had this problem too it seems, not just myself.
Finglas