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
|
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
lambda { test_double(Puppet::Resource::Catalog, :classes => included_classes) }
end
let(:expected) { 'test_class' }
let(:included_classes) { [] }
it 'is not a diffable matcher' do
expect(matcher).not_to be_diffable
end
before do
allow(RSpec).to receive(:deprecate).with('include_class()', :replacement => 'contain_class()')
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.matches?(actual)).to be_truthy
end
end
context 'when the catalogue does not include the expected class' do
let(:included_classes) { ['something_else'] }
it 'returns false' do
expect(matcher.matches?(actual)).to be_falsey
end
end
end
describe '#failure_message_for_should', :if => rspec2? do
it 'provides a description and the expected class' do
matcher.matches?(actual)
expect(matcher.failure_message_for_should).to eq("expected that the catalogue would include Class[#{expected}]")
end
end
describe '#failure_message', :unless => rspec2? 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_for_should_not', :if => rspec2? 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
describe '#failure_message_when_negated', :unless => rspec2? 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
|