Class: RSpec::Puppet::ManifestMatchers::CountGeneric
- Inherits:
-
Object
- Object
- RSpec::Puppet::ManifestMatchers::CountGeneric
- Defined in:
- lib/rspec-puppet/matchers/count_generic.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(type, count, *method) ⇒ CountGeneric
constructor
A new instance of CountGeneric.
- #matches?(catalogue) ⇒ Boolean
Constructor Details
#initialize(type, count, *method) ⇒ CountGeneric
Returns a new instance of CountGeneric.
4 5 6 7 8 9 10 11 12 |
# File 'lib/rspec-puppet/matchers/count_generic.rb', line 4 def initialize(type, count, *method) if type.nil? @type = method[0].to_s.gsub(/^have_(.+)_resource_count$/, '\1') else @type = type end @referenced_type = referenced_type(@type) @expected_number = count.to_i end |
Instance Method Details
#description ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rspec-puppet/matchers/count_generic.rb', line 34 def description desc = [] desc << "contain exactly #{@expected_number}" if @type == "class" desc << "#{@expected_number == 1 ? "class" : "classes" }" else unless @type == "resource" desc << "#{@referenced_type}" end desc << "#{@expected_number == 1 ? "resource" : "resources" }" end desc.join(" ") end |
#failure_message_for_should ⇒ Object
50 51 52 |
# File 'lib/rspec-puppet/matchers/count_generic.rb', line 50 def "expected that the catalogue would " + description + " but it contains #{@actual_number}" end |
#failure_message_for_should_not ⇒ Object
54 55 56 |
# File 'lib/rspec-puppet/matchers/count_generic.rb', line 54 def "expected that the catalogue would not " + description + " but it does" end |
#matches?(catalogue) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rspec-puppet/matchers/count_generic.rb', line 14 def matches?(catalogue) if @type == "resource" @actual_number = catalogue.resources.count do |res| !(['Class', 'Node'].include? res.type) end # Puppet automatically adds Stage[main] @actual_number = @actual_number - 1 else @actual_number = catalogue.resources.count do |res| res.type == @referenced_type end # Puppet automatically adds Class[main] and Class[Settings] @actual_number = @actual_number - 2 if @type == "class" end @actual_number == @expected_number end |