Class: Mocha::ParameterMatchers::HasEntry

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

Overview

Parameter matcher which matches when actual parameter contains expected Hash entry.

Instance Method Summary collapse

Methods inherited from Base

#&, #to_matcher, #|

Constructor Details

#initialize(key, value) ⇒ HasEntry


63
64
65
# File 'lib/mocha/parameter_matchers/has_entry.rb', line 63

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

Instance Method Details

#matches?(available_parameters) ⇒ Boolean


68
69
70
71
72
73
# File 'lib/mocha/parameter_matchers/has_entry.rb', line 68

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


76
77
78
# File 'lib/mocha/parameter_matchers/has_entry.rb', line 76

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