Sha256: 2e78730d1e1fd61bc276715b781974511909548e4eadb683b525a97af4a5c6c1

Contents?: true

Size: 1.88 KB

Versions: 2190

Compression:

Stored size: 1.88 KB

Contents

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

Version data entries

2,190 entries across 2,104 versions & 96 rubygems

Version Path
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
mux_ruby-3.19.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
mux_ruby-3.18.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
mux_ruby-3.17.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.10.2/lib/rspec/mocks/verifying_message_expectation.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.10.2/lib/rspec/mocks/verifying_message_expectation.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.10.2/lib/rspec/mocks/verifying_message_expectation.rb
mux_ruby-3.15.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
mux_ruby-3.14.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
mux_ruby-3.13.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
mux_ruby-3.12.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rspec-mocks-3.11.0/lib/rspec/mocks/verifying_message_expectation.rb
mux_ruby-3.11.1 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
mux_ruby-3.11.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rspec-mocks-3.11.0/lib/rspec/mocks/verifying_message_expectation.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
primary_connect_proto-0.20.0 vendor/bundle/ruby/3.0.0/gems/rspec-mocks-3.10.2/lib/rspec/mocks/verifying_message_expectation.rb
primary_connect_proto-0.20.0 vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.10.2/lib/rspec/mocks/verifying_message_expectation.rb