/usr/lib/ruby/vendor_ruby/rspec/mocks/verifying_message_expectation.rb is in ruby-rspec-mocks 3.4.0c3e0m1s1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | RSpec::Support.require_rspec_support '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 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.
#
# Conceptually the method reference makes more sense as a constructor
# argument since it should be immutable, but it is significantly more
# straight forward to build the object in pieces so for now it stays as
# an accessor.
attr_accessor :method_reference
def initialize(*args)
super
end
# @private
def with(*args, &block)
super(*args, &block).tap do
validate_expected_arguments! do |signature|
example_call_site_args = [:an_arg] * signature.min_non_kw_args
example_call_site_args << :kw_args_hash if signature.required_kw_args.any?
@argument_list_matcher.resolve_expected_args_based_on(example_call_site_args)
end
end
end
private
def validate_expected_arguments!
return if method_reference.nil?
method_reference.with_signature do |signature|
args = yield signature
verifier = Support::LooseSignatureVerifier.new(signature, args)
unless verifier.valid?
# Fail fast is required, otherwise the message expectation will fail
# as well ("expected method not called") and clobber this one.
@failed_fast = true
@error_generator.raise_invalid_arguments_error(verifier)
end
end
end
end
end
end
|