Class: Mocha::ParameterMatchers::HasKey

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

Overview

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

Instance Method Summary collapse

Methods inherited from Base

#&, #to_matcher, #|

Constructor Details

#initialize(key) ⇒ HasKey

Returns a new instance of HasKey


33
34
35
# File 'lib/mocha/parameter_matchers/has_key.rb', line 33

def initialize(key)
  @key = key
end

Instance Method Details

#matches?(available_parameters) ⇒ Boolean

Returns:

  • (Boolean)

38
39
40
41
42
# File 'lib/mocha/parameter_matchers/has_key.rb', line 38

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

#mocha_inspectObject


45
46
47
# File 'lib/mocha/parameter_matchers/has_key.rb', line 45

def mocha_inspect
  "has_key(#{@key.mocha_inspect})"
end