Class: Mocha::ParameterMatchers::RegexpMatches

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

Overview

Parameter matcher which matches if specified regular expression matches actual paramter.

Instance Method Summary collapse

Methods inherited from Base

#&, #to_matcher, #|

Constructor Details

#initialize(regexp) ⇒ RegexpMatches

Returns a new instance of RegexpMatches


34
35
36
# File 'lib/mocha/parameter_matchers/regexp_matches.rb', line 34

def initialize(regexp)
  @regexp = regexp
end

Instance Method Details

#matches?(available_parameters) ⇒ Boolean

Returns:

  • (Boolean)

39
40
41
42
43
# File 'lib/mocha/parameter_matchers/regexp_matches.rb', line 39

def matches?(available_parameters)
  parameter = available_parameters.shift
  return false unless parameter.respond_to?(:=~)
  parameter =~ @regexp
end

#mocha_inspectObject


46
47
48
# File 'lib/mocha/parameter_matchers/regexp_matches.rb', line 46

def mocha_inspect
  "regexp_matches(#{@regexp.mocha_inspect})"
end