Sha256: 2e78730d1e1fd61bc276715b781974511909548e4eadb683b525a97af4a5c6c1

Contents?: true

Size: 1.88 KB

Versions: 2193

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,193 entries across 2,107 versions & 96 rubygems

Version Path
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/2.6.0/gems/rspec-mocks-3.10.2/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
mux_ruby-3.9.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
primary_connect_proto-0.19.0 vendor/bundle/ruby/3.0.0/gems/rspec-mocks-3.10.2/lib/rspec/mocks/verifying_message_expectation.rb
mux_ruby-3.8.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
primary_connect_proto-0.18.0 vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.10.2/lib/rspec/mocks/verifying_message_expectation.rb
primary_connect_proto-0.18.0 vendor/bundle/ruby/3.0.0/gems/rspec-mocks-3.10.2/lib/rspec/mocks/verifying_message_expectation.rb
primary_connect_proto-0.17.0 vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.10.2/lib/rspec/mocks/verifying_message_expectation.rb
primary_connect_proto-0.17.0 vendor/bundle/ruby/3.0.0/gems/rspec-mocks-3.10.2/lib/rspec/mocks/verifying_message_expectation.rb
cybrid_api_organization_ruby-0.50.4 vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
cybrid_api_id_ruby-0.50.4 vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
cybrid_api_bank_ruby-0.50.4 vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
cybrid_api_id_ruby-0.50.3 vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
cybrid_api_bank_ruby-0.50.3 vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
cybrid_api_organization_ruby-0.50.3 vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
cybrid_api_organization_ruby-0.50.2 vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
cybrid_api_bank_ruby-0.50.2 vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
cybrid_api_id_ruby-0.50.2 vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb
ory-client-0.2.0.alpha60 vendor/bundle/ruby/2.5.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/verifying_message_expectation.rb