moduleRSpecmoduleMocksmoduleMatchersclassReceivedefinitialize(message,block)@message=message@block=block@recorded_customizations=[]# MRI, JRuby and RBX report the caller inconsistently; MRI# reports an extra "in `new'" line in the backtrace that the# others do not include. The safest way to find the right# line is to search for the first line BEFORE rspec/mocks/syntax.rb.@backtrace_line=caller.finddo|line|!line.split(':').first.end_with?('rspec/mocks/syntax.rb')endenddefsetup_expectation(subject,&block)setup_mock_proxy_method_substitute(subject,:add_message_expectation,block)endaliasmatches?setup_expectationdefsetup_negative_expectation(subject,&block)# ensure `never` goes first for cases like `never.and_return(5)`,# where `and_return` is meant to raise an error@recorded_customizations.unshiftCustomization.new(:never,[],nil)setup_expectation(subject,&block)endaliasdoes_not_match?setup_negative_expectationdefsetup_allowance(subject,&block)setup_mock_proxy_method_substitute(subject,:add_stub,block)enddefsetup_any_instance_expectation(subject,&block)setup_any_instance_method_substitute(subject,:should_receive,block)enddefsetup_any_instance_negative_expectation(subject,&block)setup_any_instance_method_substitute(subject,:should_not_receive,block)enddefsetup_any_instance_allowance(subject,&block)setup_any_instance_method_substitute(subject,:stub,block)endMessageExpectation.public_instance_methods(false).eachdo|method|nextifmethod_defined?(method)class_eval(<<-RUBY)
def #{method}(*args, &block)
@recorded_customizations << Customization.new(#{method.inspect}, args, block)
self
end
RUBYendprivatedefsetup_mock_proxy_method_substitute(subject,method,block)proxy=::RSpec::Mocks.proxy_for(subject)setup_method_substitute(proxy,method,block,@backtrace_line)enddefsetup_any_instance_method_substitute(subject,method,block)any_instance_recorder=::RSpec::Mocks.any_instance_recorder_for(subject)setup_method_substitute(any_instance_recorder,method,block)enddefsetup_method_substitute(host,method,block,*args)args<<@message.to_symexpectation=host.__send__(method,*args,&(@block||block))@recorded_customizations.eachdo|customization|customization.playback_onto(expectation)endexpectationendclassCustomizationdefinitialize(method_name,args,block)@method_name=method_name@args=args@block=blockenddefplayback_onto(expectation)expectation.__send__(@method_name,*@args,&@block)endendendendendend