Class: Mocha::ParameterMatchers::HasEntry

Inherits:
Base show all
Defined in:
lib/mocha/parameter_matchers/has_entry.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Base

#&, #to_matcher, #|

Constructor Details

#initialize(key, value) ⇒ HasEntry

Returns a new instance of HasEntry.



38
39
40
# File 'lib/mocha/parameter_matchers/has_entry.rb', line 38

def initialize(key, value)
  @key, @value = key, value
end

Instance Method Details

#matches?(available_parameters) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/mocha/parameter_matchers/has_entry.rb', line 42

def matches?(available_parameters)
  parameter = available_parameters.shift
  return false unless parameter.respond_to?(:keys) && parameter.respond_to?(:[])
  matching_keys = parameter.keys.select { |key| @key.to_matcher.matches?([key]) }
  matching_keys.any? { |key| @value.to_matcher.matches?([parameter[key]]) }
end

#mocha_inspectObject



49
50
51
# File 'lib/mocha/parameter_matchers/has_entry.rb', line 49

def mocha_inspect
  "has_entry(#{@key.mocha_inspect} => #{@value.mocha_inspect})"
end