class Mocha::ParameterMatchers::HasEntries

Parameter matcher which matches when actual parameter contains all expected Hash entries.

Public Class Methods

new(entries, exact: false) click to toggle source

@private

# File lib/mocha/parameter_matchers/has_entries.rb, line 33
def initialize(entries, exact: false)
  @entries = entries
  @exact = exact
end

Public Instance Methods

matches?(available_parameters) click to toggle source

@private

# File lib/mocha/parameter_matchers/has_entries.rb, line 39
def matches?(available_parameters)
  parameter = available_parameters.shift
  return false unless parameter
  return false unless parameter.respond_to?(:keys)
  return false if @exact && @entries.length != parameter.keys.length

  has_entry_matchers = @entries.map { |key, value| HasEntry.new(key, value) }
  AllOf.new(*has_entry_matchers).matches?([parameter])
end
mocha_inspect() click to toggle source

@private

# File lib/mocha/parameter_matchers/has_entries.rb, line 50
def mocha_inspect
  @exact ? @entries.mocha_inspect : "has_entries(#{@entries.mocha_inspect})"
end