lib/caricature/expectation.rb in caricature-0.5.0 vs lib/caricature/expectation.rb in caricature-0.6.0
- old
+ new
@@ -22,11 +22,11 @@
# When you specify arguments other than +:any+ it will try to match the specified arguments in addition
# to the method name. It will then also return the first result it can find.
def find(method_name, mode=:instance, *args)
expectations = mode == :class ? @class_expectations : @instance_expectations
candidates = expectations.select { |exp| exp.method_name.to_s.to_sym == method_name.to_s.to_sym }
- is_single = args.empty? || args.first == :any || (candidates.size == 1 && candidates.first.any_args?)
+ is_single = args.empty? || (args.first.is_a?(Symbol) and args.first == :any) || (candidates.size == 1 && candidates.first.any_args?)
return candidates.first if is_single
second_pass = candidates.select {|exp| exp.args == args }
second_pass.first
end
@@ -38,11 +38,11 @@
module ExpectationSyntax
# tell the expection which arguments it needs to respond to
# there is a magic argument here +any+ which configures
# the expectation to respond to any arguments
def with(*args)
- @any_args = false unless args.first == :any
+ @any_args = args.first.is_a?(Symbol) and args.first == :any
@args = args
self
end
# tell the expectation it nees to return this value or the value returned by the block
@@ -52,10 +52,11 @@
@return_value ||= yield if block_given?
self
end
# tell the expectation it needs to raise an error with the specified arguments
+ alias_method :actual_raise, :raise
def raise(*args)
@error_args = args
self
end
@@ -125,10 +126,10 @@
end
# executes this expectation with its configuration
def execute(*margs)
ags = any_args? ? (margs.empty? ? :any : margs) : args
- raise *@error_args if has_error_args?
+ actual_raise *@error_args if has_error_args?
return return_value if has_return_value?
nil
end
end
\ No newline at end of file