Skip to content

Commit bd4c6e8

Browse files
committed
(maint) - Fix failing tests exiting 0
Prior to this commit, the spec tests would falsely exit 0, meaning that the CI pipelines would pass and that failures would slip through the cracks. This was because we invoke rake tasks in some of our unit testing, which explicity exit with 0 (in the cause the offending tasks was litmus:check_connectivity). This exit code would interfere with the exit code 1 of the failing rspec tests, leading to a false passing CI pipeline. This now stubs the exit method, which is called during these rake tasks, and ensures that it is not actually invoked and interferes with the rspec exit code.
1 parent 55f7d1f commit bd4c6e8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

spec/lib/puppet_litmus/rake_tasks_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
expect($stdout).to receive(:puts).with('redhat-5-x86_64')
2323
expect($stdout).to receive(:puts).with('ubuntu-1404-x86_64')
2424
expect($stdout).to receive(:puts).with('ubuntu-1804-x86_64')
25+
allow_any_instance_of(Object).to receive(:exit)
2526
Rake::Task['litmus:metadata'].invoke
2627
end
2728
end
@@ -44,7 +45,7 @@
4445

4546
expect_any_instance_of(Object).to receive(:install_module).with(inventory_hash, target_nodes, dummy_tar, args[:module_repository])
4647
expect($stdout).to receive(:puts).with("Installed '#{dummy_tar}' on #{target_nodes.join(', ')}")
47-
48+
allow_any_instance_of(Object).to receive(:exit)
4849
Rake::Task['litmus:install_module'].invoke(*args.values)
4950
end
5051

@@ -93,6 +94,7 @@
9394
expect($stdout).to receive(:puts).with(start_with('Installing \'spec/data/doot.tar.gz\''))
9495
expect_any_instance_of(Object).to receive(:run_command).twice.and_return([])
9596
expect($stdout).to receive(:puts).with(start_with('Installed \'spec/data/doot.tar.gz\''))
97+
allow_any_instance_of(Object).to receive(:exit)
9698
Rake::Task['litmus:install_modules_from_directory'].invoke('./spec/fixtures/modules')
9799
end
98100
end
@@ -103,6 +105,7 @@
103105
expect(Rake::Task['litmus:provision_list']).to receive(:invoke).with('default')
104106
expect(Rake::Task['litmus:install_agent']).to receive(:invoke).with('puppet6')
105107
expect(Rake::Task['litmus:install_module']).to receive(:invoke)
108+
allow_any_instance_of(Object).to receive(:exit)
106109
Rake::Task['litmus:provision_install'].invoke('default', 'puppet6')
107110
end
108111
end
@@ -126,7 +129,7 @@
126129
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with(any_args).and_return(results)
127130
allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).with(any_args).and_return({})
128131
allow_any_instance_of(PuppetLitmus::RakeHelper).to receive(:check_connectivity?).with(any_args).and_return(true)
129-
132+
allow_any_instance_of(Object).to receive(:exit)
130133
expect { Rake::Task['litmus:provision'].invoke('docker', 'centos:7') }.to output(/#{expected_output}/).to_stdout
131134
end
132135
end
@@ -138,6 +141,7 @@
138141
it 'no key in provision file' do
139142
allow(File).to receive(:file?).with(any_args).and_return(true)
140143
expect(YAML).to receive(:load_file).with(provision_file).and_return(provision_hash)
144+
allow_any_instance_of(Object).to receive(:exit)
141145
expect { Rake::Task['litmus:provision_list'].invoke('deet') }.to raise_error(/deet/)
142146
end
143147
end
@@ -149,6 +153,7 @@
149153
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
150154
expect_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
151155
expect_any_instance_of(PuppetLitmus::RakeHelper).to receive(:check_connectivity?).with(inventory_hash, nil).and_return(true)
156+
allow_any_instance_of(Object).to receive(:exit)
152157
Rake::Task['litmus:check_connectivity'].invoke
153158
end
154159
end
@@ -157,6 +162,7 @@
157162
it 'calls spec_prep' do
158163
expect(Rake::Task['spec_prep']).to receive(:invoke).and_return('')
159164
expect_any_instance_of(RSpec::Core::RakeTask).to receive(:run_task)
165+
allow_any_instance_of(Object).to receive(:exit)
160166
Rake::Task['litmus:acceptance:localhost'].invoke
161167
end
162168
end

0 commit comments

Comments
 (0)