Class: Mocha::ParameterMatchers::Optionally

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

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Base

#&, #to_matcher, #|

Constructor Details

#initialize(*parameters) ⇒ Optionally

Returns a new instance of Optionally.



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

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

Instance Method Details

#matches?(available_parameters) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
# File 'lib/mocha/parameter_matchers/optionally.rb', line 37

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



47
48
49
# File 'lib/mocha/parameter_matchers/optionally.rb', line 47

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