Sha256: 0b5c36c371c8f40e69fdf7a4bbfe95fd3db8b0e571fa4edaf58443a39ad2fe72

Contents?: true

Size: 929 Bytes

Versions: 20

Compression:

Stored size: 929 Bytes

Contents

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

module Mocha
  class ParametersMatcher
    def initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], &matching_block)
      @expected_parameters = expected_parameters
      @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 = signature.gsub(/^\{|\}$/, '') if matchers.length == 1
      "(#{signature})"
    end

    def matchers
      @expected_parameters.map(&:to_matcher)
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
mocha-1.16.1 lib/mocha/parameters_matcher.rb
mocha-1.15.1 lib/mocha/parameters_matcher.rb
mocha-1.16.0 lib/mocha/parameters_matcher.rb
mocha-1.15.0 lib/mocha/parameters_matcher.rb
mocha-1.14.0 lib/mocha/parameters_matcher.rb
mocha-1.13.0 lib/mocha/parameters_matcher.rb
mocha-1.12.0 lib/mocha/parameters_matcher.rb
mocha-1.11.2 lib/mocha/parameters_matcher.rb
mocha-1.11.1 lib/mocha/parameters_matcher.rb
mocha-1.11.0 lib/mocha/parameters_matcher.rb
mocha-1.10.2 lib/mocha/parameters_matcher.rb
mocha-1.10.1 lib/mocha/parameters_matcher.rb
mocha-1.10.0 lib/mocha/parameters_matcher.rb
mocha-1.10.0.beta.1 lib/mocha/parameters_matcher.rb
mocha-1.10.0.alpha lib/mocha/parameters_matcher.rb
mocha-1.9.0 lib/mocha/parameters_matcher.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/mocha-1.8.0/lib/mocha/parameters_matcher.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/mocha-1.8.0/lib/mocha/parameters_matcher.rb
mocha-1.8.0 lib/mocha/parameters_matcher.rb
mocha-1.7.0 lib/mocha/parameters_matcher.rb