floehopper/mocha — Issue #52: Unstubbing one method causes an ExpectationError if calling a non-unstubbed method
Author: saikat
Created: 2012-01-09 23:17:02+00:00
State: open

Reproduction:

class Foo
def self.bar
puts 'hi'
end
def self.car
puts 'bye'
end
end

>> Foo.stubs(:bar => 'bar', :car => 'car')
=> #, @parameters_matcher=#]>, @return_values=#]>, @side_effects=[], @yield_parameters=#, @mock=Foo, @backtrace=["/Library/Ruby/Gems/1.8/gems/mocha-0.10.0/lib/mocha/argument_iterator.rb:12:in `call'", "/Library/Ruby/Gems/1.8/gems/mocha-0.10.0/lib/mocha/argument_iterator.rb:12:in `each'", "/Library/Ruby/Gems/1.8/gems/mocha-0.10.0/lib/mocha/argument_iterator.rb:11:in `each'", "/Library/Ruby/Gems/1.8/gems/mocha-0.10.0/lib/mocha/object.rb:97:in `stubs'", "(irb):11:in `irb_binding'", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/workspace.rb:52"], @ordering_constraints=[], @cardinality=#>
>> Foo.bar
=> "bar"
>> Foo.car
=> "car"
>> Foo.unstub(:bar)
=> [:bar]
>> Foo.car
Mocha::ExpectationError: unexpected invocation: Foo.car()
satisfied expectations:
- allowed any number of times, invoked once: Foo.car(any_parameters)
- allowed any number of times, invoked once: Foo.bar(any_parameters)

from (irb):15

I would not have expected Foo.car to throw an exception here.