开发者

RSpec - generic failure message instead of useful output

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_mo开发者_JAVA技巧ck = 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'


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜