RSpec::Support.require_rspec_mocks'matchers/expectation_customization'moduleRSpecmoduleMocksmoduleMatchers# @privateclassReceiveincludeMatcherdefinitialize(message,block)@message=message@block=block@recorded_customizations=[]enddefname"receive"enddefdescriptiondescribable.description_for("receive")enddefsetup_expectation(subject,&block)warn_if_any_instance("expect",subject)@describable=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.unshiftExpectationCustomization.new(:never,[],nil)warn_if_any_instance("expect",subject)setup_expectation(subject,&block)endaliasdoes_not_match?setup_negative_expectationdefsetup_allowance(subject,&block)warn_if_any_instance("allow",subject)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)define_method(method)do|*args,&block|@recorded_customizations<<ExpectationCustomization.new(method,args,block)selfendruby2_keywords(method)ifModule.private_method_defined?(:ruby2_keywords)endprivatedefdescribable@describable||=DefaultDescribable.new(@message)enddefwarn_if_any_instance(expression,subject)returnunlessAnyInstance::Proxy===subjectRSpec.warning("`#{expression}(#{subject.klass}.any_instance).to` "\"is probably not what you meant, it does not operate on "\"any instance of `#{subject.klass}`. "\"Use `#{expression}_any_instance_of(#{subject.klass}).to` instead.")enddefsetup_mock_proxy_method_substitute(subject,method,block)proxy=::RSpec::Mocks.space.proxy_for(subject)setup_method_substitute(proxy,method,block)enddefsetup_any_instance_method_substitute(subject,method,block)proxy=::RSpec::Mocks.space.any_instance_proxy_for(subject)setup_method_substitute(proxy,method,block)enddefsetup_method_substitute(host,method,block,*args)args<<@message.to_symblock=move_block_to_last_customization(block)expectation=host.__send__(method,*args,&(@block||block))@recorded_customizations.eachdo|customization|customization.playback_onto(expectation)endexpectationenddefmove_block_to_last_customization(block)last=@recorded_customizations.lastreturnblockunlesslastlast.block||=blocknilend# MessageExpectation objects are able to describe themselves in detail.# We use this as a fall back when a MessageExpectation is not available.# @privateclassDefaultDescribabledefinitialize(message)@message=messageend# This is much simpler for the `any_instance` case than what the# user may want, but I'm not up for putting a bunch of effort# into full descriptions for `any_instance` expectations at this point :(.defdescription_for(verb)"#{verb}#{@message}"endendendendendend