Class: RSpec::Puppet::ManifestMatchers::ParameterMatcher
- Inherits:
-
Object
- Object
- RSpec::Puppet::ManifestMatchers::ParameterMatcher
- Includes:
- Errors
- Defined in:
- lib/rspec-puppet/matchers/parameter_matcher.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(parameter, value, type) ⇒ ParameterMatcher
constructor
A new instance of ParameterMatcher.
-
#matches?(resource) ⇒ true, false
Ensure that the actual parameter matches the expected parameter.
Constructor Details
#initialize(parameter, value, type) ⇒ ParameterMatcher
Returns a new instance of ParameterMatcher.
9 10 11 12 13 14 15 |
# File 'lib/rspec-puppet/matchers/parameter_matcher.rb', line 9 def initialize(parameter, value, type) @parameter, @value, @type = parameter, value, type @should_match = (type == :should) @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
47 48 49 |
# File 'lib/rspec-puppet/matchers/parameter_matcher.rb', line 47 def errors @errors end |
Instance Method Details
#matches?(resource) ⇒ true, false
Ensure that the actual parameter matches the expected parameter.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rspec-puppet/matchers/parameter_matcher.rb', line 23 def matches?(resource) @resource = resource actual = @resource[@parameter] expected = @value # Puppet flattens an array with a single value into just the value and # this can cause confusion when testing as people expect when you put # an array in, you'll get an array out. actual = [actual] if expected.is_a?(Array) && !actual.is_a?(Array) retval = check(expected, actual) unless retval @errors << MatchError.new(@parameter, expected, actual, !@should_match) end retval end |