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.
11 12 13 14 15 16 17 18 19 |
# File 'lib/rspec-puppet/matchers/parameter_matcher.rb', line 11 def initialize(parameter, value, type) @parameter = parameter @value = value @type = type @should_match = (type == :should) @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
48 49 50 |
# File 'lib/rspec-puppet/matchers/parameter_matcher.rb', line 48 def errors @errors end |
Instance Method Details
#matches?(resource) ⇒ true, false
Ensure that the actual parameter matches the expected parameter.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rspec-puppet/matchers/parameter_matcher.rb', line 27 def matches?(resource) actual = resource[@parameter] expected = @value actual = RSpec::Puppet::Sensitive.new(actual.unwrap) if actual.is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive) # 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) @errors << MatchError.new(@parameter, expected, actual, !@should_match) unless retval retval end |