Create a gist now

Instantly share code, notes, and snippets.

An RSpec "undefined method" oddity
ubuntu-desktop-x64 :: ~/Code » rspec 2274040/undefined_method_oddity_spec.rb
FF
Failures:
1) UndefinedMethodOddity correctly complaints 'expected: 1 time, received: 2 times'
Failure/Error: subject.should_receive(:bar)
(#<UndefinedMethodOddity:0x000000010b7c68>).bar(any args)
expected: 1 time
received: 0 times
# ./2274040/undefined_method_oddity_spec.rb:17:in `block (2 levels) in <top (required)>'
2) UndefinedMethodOddity strangely complains about 'undefined method `bar' for #<UndefinedMethodOddity'
Failure/Error: subject.should_receive(:bar).with(1)
(#<UndefinedMethodOddity:0x00000001d85af8>).bar(1)
expected: 1 time
received: 0 times
# ./2274040/undefined_method_oddity_spec.rb:22:in `block (2 levels) in <top (required)>'
Finished in 0.00098 seconds
2 examples, 2 failures
Failed examples:
rspec ./2274040/undefined_method_oddity_spec.rb:16 # UndefinedMethodOddity correctly complaints 'expected: 1 time, received: 2 times'
rspec ./2274040/undefined_method_oddity_spec.rb:21 # UndefinedMethodOddity strangely complains about 'undefined method `bar' for #<UndefinedMethodOddity'
class UndefinedMethodOddity
def foo
self.bar 1
self.bar 2
end
def bar(arg)
end
end
describe UndefinedMethodOddity do
describe '#foo' do
it "correctly complaints 'expected: 1 time, received: 2 times'" do
subject.should_receive(:bar)
subject.foo
end
it "strangely complains about 'undefined method `bar' for #<UndefinedMethodOddity'" do
subject.should_receive(:bar).with(1)
subject.foo
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment