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 79 80 81 82 83 84 85 86 87
|
require 'spec_helper'
require 'rspec-puppet/support'
# is_expected.to not available with rspec 2.14, which is only used for puppet < 3
describe RSpec::Puppet::TypeAliasMatchers::AllowValue, :if => Puppet.version.to_f >= 3.0 do
subject { RSpec::Puppet::TypeAliasMatchers::AllowValue.new(values) }
let(:catalogue) { double('catalogue builder') }
describe "one matching value" do
let (:values) { ['circle'] }
before { allow(catalogue).to receive(:call).with('circle') }
describe '#matches?' do
it { expect(subject.matches?(catalogue)).to be true }
end
describe '#description' do
it { expect(subject.description).to eq('match value "circle"') }
end
end
describe "one incorrect value" do
let (:values) { ['circle'] }
before { allow(catalogue).to receive(:call).with('circle').and_raise(Puppet::Error.new('expected a Shape value, got circle')) }
describe '#matches?' do
it { expect(subject.matches?(catalogue)).to be false }
end
describe '#description' do
it { expect(subject.description).to eq('match value "circle"') }
end
describe '#failure_message' do
before { subject.matches?(catalogue) }
it { expect(subject.failure_message).to eq('expected that the type alias would match value "circle" but it raised the error expected a Shape value, got circle') }
end
describe '#failure_message_when_negated' do
it { expect(subject.failure_message_when_negated).to eq('expected that the type alias would not match value "circle" but it does') }
end
end
describe "multiple matching values" do
let (:values) { ['circle', 'square'] }
before do
allow(catalogue).to receive(:call).with('circle')
allow(catalogue).to receive(:call).with('square')
end
describe '#matches?' do
it { expect(subject.matches?(catalogue)).to be true }
end
describe '#description' do
it { expect(subject.description).to eq('match values "circle", "square"') }
end
end
describe "mixed matching/incorrect values" do
let (:values) { ['circle', 'square', 'triangle'] }
before do
allow(catalogue).to receive(:call).with('circle').and_raise(Puppet::Error.new('expected a Shape value, got circle'))
allow(catalogue).to receive(:call).with('triangle').and_raise(Puppet::Error.new('expected a Shape value, got triangle'))
allow(catalogue).to receive(:call).with('square')
end
describe '#matches?' do
it { expect(subject.matches?(catalogue)).to be false }
end
describe '#description' do
it { expect(subject.description).to eq('match values "circle", "square", "triangle"') }
end
describe '#failure_message' do
before { subject.matches?(catalogue) }
it { expect(subject.failure_message).to eq('expected that the type alias would match values "circle", "square", "triangle" but it raised the errors expected a Shape value, got circle, expected a Shape value, got triangle') }
end
describe '#failure_message_when_negated' do
it { expect(subject.failure_message_when_negated).to eq('expected that the type alias would not match values "circle", "square", "triangle" but it does') }
end
end
end
|