def message_received(method_name, *args, &block)
expectation = find_matching_expectation(method_name, *args)
stub = find_matching_method_stub(method_name, *args)
if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
expectation.increase_actual_received_count! if expectation && expectation.actual_received_count_matters?
if expectation = find_almost_matching_expectation(method_name, *args)
expectation.advise(*args) unless expectation.expected_messages_received?
end
stub.invoke(*args, &block)
elsif expectation
expectation.invoke(*args, &block)
elsif expectation = find_almost_matching_expectation(method_name, *args)
expectation.advise(*args) if null_object? unless expectation.expected_messages_received?
raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(method_name) or null_object?)
elsif stub = find_almost_matching_stub(method_name, *args)
stub.advise(*args)
raise_unexpected_message_args_error(stub, *args)
elsif @object.is_a?(Class)
@object.superclass.send(method_name, *args, &block)
else
@object.__send__(:method_missing, method_name, *args, &block)
end
end