Sha256: 66b058484e10c69b823a84c3a5bca3b72cb74ff8c4d9e26c2c8adc13f43ab105

Contents?: true

Size: 930 Bytes

Versions: 10

Compression:

Stored size: 930 Bytes

Contents

require 'mocha/inspect'
require 'mocha/parameter_matchers'

module Mocha
  class ParametersMatcher
    def initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], expectation = nil, &matching_block)
      @expected_parameters = expected_parameters
      @expectation = expectation
      @matching_block = matching_block
    end

    def match?(actual_parameters = [])
      if @matching_block
        @matching_block.call(*actual_parameters)
      else
        parameters_match?(actual_parameters)
      end
    end

    def parameters_match?(actual_parameters)
      matchers.all? { |matcher| matcher.matches?(actual_parameters) } && actual_parameters.empty?
    end

    def mocha_inspect
      signature = matchers.mocha_inspect
      signature = signature.gsub(/^\[|\]$/, '')
      "(#{signature})"
    end

    def matchers
      @expected_parameters.map { |p| p.to_matcher(@expectation) }
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
mocha-2.4.0 lib/mocha/parameters_matcher.rb
mocha-2.2.0 lib/mocha/parameters_matcher.rb
mocha-2.1.0 lib/mocha/parameters_matcher.rb
mocha-2.0.4 lib/mocha/parameters_matcher.rb
mocha-2.0.3 lib/mocha/parameters_matcher.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/mocha-2.0.2/lib/mocha/parameters_matcher.rb
mocha-2.0.2 lib/mocha/parameters_matcher.rb
mocha-2.0.1 lib/mocha/parameters_matcher.rb
mocha-2.0.0 lib/mocha/parameters_matcher.rb
mocha-2.0.0.alpha.1 lib/mocha/parameters_matcher.rb