Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

An RSpec "undefined method" oddity

View undefined_method_oddity_spec.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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'
View undefined_method_oddity_spec.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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
Something went wrong with that request. Please try again.