Permalink
Browse files

Fix a regression.

When doing something like:

  double.stub(:foo).and_return(a, b)
  double.should_receive(:foo).once { a }
  double.foo

...it used to work, but in 2.10 it raises a NoMethodError (#size).
  • Loading branch information...
myronmarston committed May 17, 2012
1 parent eebee30 commit 132f99c8ac343d84b11eac560bcad6ce9c65b007
Showing with 17 additions and 1 deletion.
  1. +9 −1 lib/rspec/mocks/message_expectation.rb
  2. +8 −0 spec/rspec/mocks/block_return_value_spec.rb
@@ -34,7 +34,15 @@ def initialize(error_generator, expectation_ordering, expected_from, message, ex
def build_child(expected_from, expected_received_count, opts={}, &implementation)
child = clone
child.expected_from = expected_from
- child.implementation = implementation if implementation
+
+ if implementation
+ child.implementation = implementation
+
+ # A new block implementation is given, so the old multi-return
+ # implementation needs to be disabled
+ child.instance_variable_set(:@consecutive, false)
+ end
+
child.expected_received_count = expected_received_count
child.clear_actual_received_count!
new_gen = error_generator.clone
@@ -7,6 +7,14 @@
obj.should_receive(:foo) { 'bar' }
obj.foo.should eq('bar')
end
+
+ it "works when a multi-return stub has already been set" do
+ obj = Object.new
+ return_value = Object.new
+ obj.stub(:foo).and_return(return_value, nil)
+ obj.should_receive(:foo) { return_value }
+ obj.foo.should be(return_value)
+ end
end
describe "stub" do

0 comments on commit 132f99c

Please sign in to comment.