lib/rspec/mocks/verifying_message_expecation.rb in rspec-mocks-3.0.0.beta1 vs lib/rspec/mocks/verifying_message_expecation.rb in rspec-mocks-3.0.0.beta2

- old
+ new

@@ -1,13 +1,14 @@ -require 'rspec/mocks/arity_calculator' +require 'rspec/mocks/method_signature_verifier' module RSpec module Mocks # A message expectation that knows about the real implementation of the # message being expected, so that it can verify that any expectations - # have the correct arity. + # have the valid arguments. + # @api private class VerifyingMessageExpectation < MessageExpectation # A level of indirection is used here rather than just passing in the # method itself, since method look up is expensive and we only want to # do it if actually needed. @@ -23,38 +24,37 @@ end # @override def with(*args, &block) unless ArgumentMatchers::AnyArgsMatcher === args.first - expected_arity = if ArgumentMatchers::NoArgsMatcher === args.first - 0 + expected_args = if ArgumentMatchers::NoArgsMatcher === args.first + [] elsif args.length > 0 - args.length + args else # No arguments given, this will raise. super end - ensure_arity!(expected_arity) + validate_arguments!(expected_args) end super end private - def ensure_arity!(actual) + def validate_arguments!(actual_args) return if method_reference.nil? - method_reference.when_defined do |method| - calculator = ArityCalculator.new(method) - unless calculator.within_range?(actual) + method_reference.with_signature do |signature| + verifier = MethodSignatureVerifier.new(signature, actual_args) + unless verifier.valid? # Fail fast is required, otherwise the message expecation will fail # as well ("expected method not called") and clobber this one. @failed_fast = true - @error_generator.raise_arity_error(calculator, actual) + @error_generator.raise_invalid_arguments_error(verifier) end end end end end end -