Class: Mocha::ParameterMatchers::Optionally

Inherits:
Base
  • Object
show all
Defined in:
lib/mocha/parameter_matchers/optionally.rb

Overview

Parameter matcher which allows optional parameters to be specified.

Instance Method Summary collapse

Methods inherited from Base

#&, #to_matcher, #|

Constructor Details

#initialize(*parameters) ⇒ Optionally


43
44
45
# File 'lib/mocha/parameter_matchers/optionally.rb', line 43

def initialize(*parameters)
  @matchers = parameters.map { |parameter| parameter.to_matcher }
end

Instance Method Details

#matches?(available_parameters) ⇒ Boolean


48
49
50
51
52
53
54
55
56
# File 'lib/mocha/parameter_matchers/optionally.rb', line 48

def matches?(available_parameters)
  index = 0
  while (available_parameters.length > 0) && (index < @matchers.length) do
    matcher = @matchers[index]
    return false unless matcher.matches?(available_parameters)
    index += 1
  end
  return true
end

#mocha_inspectObject


59
60
61
# File 'lib/mocha/parameter_matchers/optionally.rb', line 59

def mocha_inspect
  "optionally(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })"
end