Permalink
Browse files

Simplify implementation of `and_throw`.

It can use an implementation block rather than needing to
maintain some extra state.
  • Loading branch information...
1 parent d9a7e36 commit 16d30dc4d55dc49d81a9c087e407dc5bcbcad637 @myronmarston myronmarston committed Dec 26, 2012
Showing with 2 additions and 5 deletions.
  1. +2 −5 lib/rspec/mocks/message_expectation.rb
@@ -20,7 +20,6 @@ def initialize(error_generator, expectation_ordering, expected_from, method_doub
@expected_received_count = expected_received_count
@argument_list_matcher = ArgumentListMatcher.new(ArgumentMatchers::AnyArgsMatcher.new)
@consecutive = false
- @args_to_throw = []
@order_group = expectation_ordering
@at_least = @at_most = @exactly = nil
@args_to_yield = []
@@ -156,8 +155,8 @@ def and_raise(exception = RuntimeError, message = nil)
#
# car.stub(:go).and_throw(:out_of_gas)
# car.stub(:go).and_throw(:out_of_gas, :level => 0.1)
- def and_throw(symbol, object = nil)
- @args_to_throw = [symbol, object].compact
+ def and_throw(*args)
+ self.implementation = Proc.new { throw *args }
end
# Tells the object to yield one or more args to a block when the message
@@ -194,8 +193,6 @@ def invoke(*args, &block)
@order_group.handle_order_constraint self
begin
- Kernel::throw(*@args_to_throw) unless @args_to_throw.empty?
-
default_return_val = call_with_yield(&block) if !@args_to_yield.empty? || @eval_context
if @consecutive

0 comments on commit 16d30dc

Please sign in to comment.