File: valid_provider_spec.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 (78 lines) | stat: -rw-r--r-- 2,130 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true

require 'spec_helper'

describe 'fake' do
  let :title do
    'foo'
  end

  it { is_expected.to be_valid_type }

  describe 'tests of the types' do
    {
      parameters: { baddies: %w[one two], goodies: %w[three four] },
      properties: { baddies: %w[five fix], goodies: %w[seven eight] },
      features: { baddies: %w[nine ten], goodies: %w[eleven twelve] }
    }.each do |k, v|
      describe "#{k} checks" do
        [v[:baddies], v[:baddies].first].each do |baddies|
          it "fails for #{baddies.size} baddies" do
            expect do
              expect(subject).to be_valid_type.send(:"with_#{k}", baddies)
            end.to raise_error(
              RSpec::Expectations::ExpectationNotMetError,
              /Invalid #{k}: #{Array(baddies).join(',')}/
            )
          end
        end

        [v[:goodies], v[:goodies].first].each do |goodies|
          it "passes with #{goodies.size} goodies" do
            expect(subject).to be_valid_type.send(:"with_#{k}", goodies)
          end
        end
      end
    end
  end

  describe 'tests that create a resource instance' do
    let :params do
      { three: 'value' }
    end

    it 'passes when providers match' do
      expect(subject).to be_valid_type.with_provider(:default)
    end

    it 'fails when provider does not match' do
      expect do
        expect(subject).to be_valid_type.with_provider(:non_matching)
      end.to raise_error(
        RSpec::Expectations::ExpectationNotMetError,
        /Expected provider: non_matching does not match: default/
      )
    end

    it 'passes when providers match' do
      expect(subject).to be_valid_type.with_provider(:default)
    end

    it 'fails with invalid parameters' do
      expect do
        expect(subject).to be_valid_type.with_set_attributes(
          four: 'three'
        )
      end.to raise_error(
        Puppet::Error,
        %r{Valid values match /\(one\|two\)/}
      )
    end

    it 'does not fail with valid parameters' do
      expect(subject).to be_valid_type.with_set_attributes(
        four: 'one'
      )
    end
  end
end