Skip to content

Commit

Permalink
Use contain_exactly to assert results
Browse files Browse the repository at this point in the history
This is a more native way to assert results, meaning asserting the size
is redundant.
  • Loading branch information
ekohl committed Jun 9, 2024
1 parent 7335831 commit cdeac2d
Showing 1 changed file with 38 additions and 84 deletions.
122 changes: 38 additions & 84 deletions spec/rspec_puppet_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,22 @@
is_expected.to be_a Hash
end

it 'has 5 elements' do
expect(subject.size).to eq 5
end

it 'returns supported OS' do
expect(subject.keys.sort).to eq %w(
debian-7-x86_64
debian-8-x86_64
redhat-5-x86_64
redhat-6-x86_64
redhat-7-x86_64
expect(subject.keys).to contain_exactly(
'debian-7-x86_64',
'debian-8-x86_64',
'redhat-5-x86_64',
'redhat-6-x86_64',
'redhat-7-x86_64',
)
end

it 'is able to filter the received OS facts' do
allow(described_class).to receive(:spec_facts_os_filter).and_return('redhat')
expect(subject.keys.sort).to eq %w(
redhat-5-x86_64
redhat-6-x86_64
redhat-7-x86_64
expect(subject.keys).to contain_exactly(
'redhat-5-x86_64',
'redhat-6-x86_64',
'redhat-7-x86_64',
)
end
end
Expand Down Expand Up @@ -288,24 +284,20 @@
is_expected.to be_a Hash
end

it 'has 4 elements' do
expect(subject.size).to eq 4
end

it 'returns supported OS' do
expect(subject.keys.sort).to eq %w(
debian-7-x86_64
debian-8-x86_64
redhat-5-x86_64
redhat-6-x86_64
expect(subject.keys).to contain_exactly(
'debian-7-x86_64',
'debian-8-x86_64',
'redhat-5-x86_64',
'redhat-6-x86_64',
)
end

it 'is able to filter the received OS facts' do
allow(described_class).to receive(:spec_facts_os_filter).and_return('redhat')
expect(subject.keys.sort).to eq %w(
redhat-5-x86_64
redhat-6-x86_64
expect(subject.keys).to contain_exactly(
'redhat-5-x86_64',
'redhat-6-x86_64',
)
end
end
Expand All @@ -325,12 +317,8 @@
expect(factsets).to be_a(Hash)
end

it 'returns a single fact set' do
expect(factsets.size).to eq(1)
end

it 'returns a fact set for the specified release' do
expect(factsets).to include('redhat-7-x86_64' => include(:operatingsystemmajrelease => '7'))
expect(factsets).to match('redhat-7-x86_64' => include(:operatingsystemmajrelease => '7'))
end
end

Expand All @@ -352,20 +340,16 @@
)
}

let(:expected_fact_sets) do
['ubuntu-12.04-x86_64', 'ubuntu-14.04-x86_64', 'ubuntu-16.04-x86_64']
end

it 'returns a hash' do
expect(subject).to be_a Hash
end

it 'has 3 elements' do
expect(subject.size).to eq(expected_fact_sets.size)
end

it 'returns supported OS' do
expect(subject.keys.sort).to eq(expected_fact_sets)
expect(subject.keys).to contain_exactly(
'ubuntu-12.04-x86_64',
'ubuntu-14.04-x86_64',
'ubuntu-16.04-x86_64',
)
end
end

Expand All @@ -390,14 +374,10 @@
expect(subject).to be_a Hash
end

it 'has 1 elements' do
expect(subject.size).to eq 1
end

it 'returns supported OS' do
expect(subject.keys.sort).to eq [
expect(subject.keys).to contain_exactly(
'freebsd-13-amd64',
]
)
end
end

Expand All @@ -422,14 +402,10 @@
expect(subject).to be_a Hash
end

it 'has 1 elements' do
expect(subject.size).to eq 1
end

it 'returns supported OS' do
expect(subject.keys.sort).to eq [
expect(subject.keys).to contain_exactly(
'openbsd-7-amd64',
]
)
end
end

Expand All @@ -453,13 +429,9 @@
expect(subject).to be_a Hash
end

it 'has 1 elements' do
expect(subject.size).to eq 1
end

it 'returns supported OS' do
expect(subject.keys.sort).to eq %w(
solaris-11-i86pc
expect(subject.keys).to contain_exactly(
'solaris-11-i86pc',
)
end
end
Expand All @@ -485,15 +457,11 @@
expect(subject).to be_a Hash
end

it 'has 1 elements' do
expect(subject.size).to eq 1
end

it 'returns supported OS' do
# NOTE: See FACT-1827 for details on the IBM,8284-22A part
# That has to match whatever hardware generated the facts file.
expect(subject.keys.sort).to eq %w(
aix-7100-IBM,8284-22A
expect(subject.keys).to contain_exactly(
'aix-7100-IBM,8284-22A',
)
end
end
Expand All @@ -519,32 +487,28 @@
let(:release) { ['7'] }

it { is_expected.to be_a(Hash) }
it { is_expected.to have_attributes(:size => 1) }
it { is_expected.to include('windows-7-x86_64' => an_instance_of(Hash)) }
it { is_expected.to match('windows-7-x86_64' => an_instance_of(Hash)) }
end

context 'with a revision release' do
let(:release) { ['2012 R2'] }

it { is_expected.to be_a(Hash) }
it { is_expected.to have_attributes(:size => 1) }
it { is_expected.to include('windows-2012 R2-x86_64' => an_instance_of(Hash)) }
it { is_expected.to match('windows-2012 R2-x86_64' => an_instance_of(Hash)) }
end

context 'with a Server prefixed release' do
let(:release) { ['Server 2012'] }

it { is_expected.to be_a(Hash) }
it { is_expected.to have_attributes(:size => 1) }
it { is_expected.to include('windows-2012-x86_64' => an_instance_of(Hash)) }
it { is_expected.to match('windows-2012-x86_64' => an_instance_of(Hash)) }
end

context 'with a 2016 release' do
let(:release) { ['2016'] }

it { is_expected.to be_a(Hash) }
it { is_expected.to have_attributes(:size => 1) }
it { is_expected.to include('windows-2016-x86_64' => an_instance_of(Hash)) }
it { is_expected.to match('windows-2016-x86_64' => an_instance_of(Hash)) }
end
end

Expand All @@ -568,14 +532,8 @@
expect(subject).to be_a Hash
end

it 'has 1 elements' do
expect(subject.size).to eq 1
end

it 'returns supported OS' do
expect(subject.keys.sort).to eq [
'sles-11-x86_64',
]
expect(subject.keys).to contain_exactly('sles-11-x86_64')
end
end

Expand Down Expand Up @@ -625,12 +583,8 @@
expect(subject).to be_a Hash
end

it 'has 2 elements' do
expect(subject.size).to eq 2
end

it 'returns supported OS' do
expect(subject.keys.sort).to include(a_string_matching(/\Aarchlinux-\d+-x86_64/), 'debian-8-x86_64')
expect(subject.keys).to contain_exactly(a_string_matching(/\Aarchlinux-\d+-x86_64/), 'debian-8-x86_64')
end
end

Expand Down

0 comments on commit cdeac2d

Please sign in to comment.