Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
Index: rspec/lib/spec/mocks/message_expectation.rb =================================================================== --- rspec/lib/spec/mocks/message_expectation.rb (revision 2360) +++ rspec/lib/spec/mocks/message_expectation.rb (working copy) @@ -20,7 +20,7 @@ @order_group = expectation_ordering @at_least = nil @at_most = nil - @args_to_yield = nil + @args_to_yield = [] end def expected_args @@ -62,7 +62,8 @@ end def and_yield(*args) - @args_to_yield = args + @args_to_yield << args + self end def matches(sym, args) @@ -83,7 +84,7 @@ if !@method_block.nil? return invoke_method_block(args) - elsif !@args_to_yield.nil? + elsif @args_to_yield.size > 0 return invoke_with_yield(block) elsif @consecutive return invoke_consecutive_return_block(args, block) @@ -109,10 +110,12 @@ if block.nil? @error_generator.raise_missing_block_error @args_to_yield end - if block.arity > -1 && @args_to_yield.length != block.arity - @error_generator.raise_wrong_arity_error @args_to_yield, block.arity + @args_to_yield.each do |this_args_to_yield| + if block.arity > -1 && this_args_to_yield.length != block.arity + @error_generator.raise_wrong_arity_error this_args_to_yield, block.arity + end + block.call(*this_args_to_yield) end - block.call(*@args_to_yield) end def invoke_consecutive_return_block(args, block)
This paste will be private.
From the Design Piracy series on my blog: