File: include_class_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 (63 lines) | stat: -rw-r--r-- 1,803 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
# frozen_string_literal: true

require 'spec_helper_unit'

describe 'RSpec::Puppet::ManifestMatchers.include_class' do
  subject(:matcher) { Class.new { extend RSpec::Puppet::ManifestMatchers }.include_class(expected) }

  let(:actual) do
    -> { instance_double(Puppet::Resource::Catalog, classes: included_classes) }
  end

  let(:expected) { 'test_class' }
  let(:included_classes) { [] }

  before do
    allow(RSpec).to receive(:deprecate).with('include_class()', replacement: 'contain_class()')
  end

  it 'is not a diffable matcher' do
    expect(matcher).not_to be_diffable
  end

  describe '#description' do
    it 'includes the expected class name' do
      expect(matcher.description).to eq("include Class[#{expected}]")
    end
  end

  describe '#matches?' do
    context 'when the catalogue includes the expected class' do
      let(:included_classes) { [expected] }

      it 'returns true' do
        expect(matcher).to be_matches(actual)
      end
    end

    context 'when the catalogue does not include the expected class' do
      let(:included_classes) { ['something_else'] }

      it 'returns false' do
        expect(matcher).not_to be_matches(actual)
      end
    end
  end

  describe '#failure_message' do
    it 'provides a description and the expected class' do
      matcher.matches?(actual)
      expect(matcher.failure_message).to eq("expected that the catalogue would include Class[#{expected}]")
    end
  end

  describe '#failure_message_when_negated' do
    let(:included_classes) { [expected] }

    it 'provides a description and the expected class' do
      pending 'not implemented'
      matcher.matches?(actual)
      expect(matcher.failure_message_when_negated).to eq("expected that the catalogue would not include Class[#{expected}]")
    end
  end
end