Class: Mocha::ParametersMatcher
- Defined in:
- lib/mocha/parameters_matcher.rb
Instance Method Summary collapse
-
#initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], &matching_block) ⇒ ParametersMatcher
constructor
A new instance of ParametersMatcher.
- #match?(actual_parameters = []) ⇒ Boolean
- #matchers ⇒ Object
- #mocha_inspect ⇒ Object
- #parameters_match?(actual_parameters) ⇒ Boolean
Constructor Details
#initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], &matching_block) ⇒ ParametersMatcher
Returns a new instance of ParametersMatcher.
8 9 10 |
# File 'lib/mocha/parameters_matcher.rb', line 8 def initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], &matching_block) @expected_parameters, @matching_block = expected_parameters, matching_block end |
Instance Method Details
#match?(actual_parameters = []) ⇒ Boolean
12 13 14 15 16 17 18 |
# File 'lib/mocha/parameters_matcher.rb', line 12 def match?(actual_parameters = []) if @matching_block return @matching_block.call(*actual_parameters) else return parameters_match?(actual_parameters) end end |
#matchers ⇒ Object
31 32 33 |
# File 'lib/mocha/parameters_matcher.rb', line 31 def matchers @expected_parameters.map { |parameter| parameter.to_matcher } end |
#mocha_inspect ⇒ Object
24 25 26 27 28 29 |
# File 'lib/mocha/parameters_matcher.rb', line 24 def mocha_inspect signature = matchers.mocha_inspect signature = signature.gsub(/^\[|\]$/, '') signature = signature.gsub(/^\{|\}$/, '') if matchers.length == 1 "(#{signature})" end |
#parameters_match?(actual_parameters) ⇒ Boolean
20 21 22 |
# File 'lib/mocha/parameters_matcher.rb', line 20 def parameters_match?(actual_parameters) matchers.all? { |matcher| matcher.matches?(actual_parameters) } && (actual_parameters.length == 0) end |