File: unique_values.rb

package info (click to toggle)
ruby-rspec-puppet 4.0.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,444 kB
  • sloc: ruby: 6,377; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 994 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module RSpec
  module Puppet
    module ManifestMatchers
      extend RSpec::Matchers::DSL

      matcher :have_unique_values_for_all do |type, attribute|
        match do |catalogue|
          catalogue.call.resources.select { |rsrc| rsrc.type == type.capitalize }
                   .group_by { |rsrc| rsrc[attribute.to_sym] }
                   .all? { |_, group| group.size == 1 }
        end

        description do
          "have unique attribute values for #{type.capitalize}[#{attribute.to_sym}]"
        end

        if RSpec::Version::STRING < '3'
          failure_message_for_should do |_actual|
            "expected that the catalogue would have no duplicate values for #{type.capitalize}[#{attribute.to_sym}]"
          end
        else
          failure_message do |_actual|
            "expected that the catalogue would have no duplicate values for #{type.capitalize}[#{attribute.to_sym}]"
          end
        end
      end
    end
  end
end