Skip to content

Commit ad55367

Browse files
committed
(maint) avoid clashing test with actual fixture, pt2
This might have been uncovered by the autoloader reset and random order testing. To make sure it does not recur, this change moves the autoloader reset to the top and runs it after each example.
1 parent 390e6bf commit ad55367

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

spec/integration/resource_api/transport_spec.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
require 'spec_helper'
22

33
RSpec.describe 'Resource API Transport integration tests:' do
4-
after(:each) do
5-
# reset registered transports between tests to reduce cross-test poisoning
6-
Puppet::ResourceApi::Transport.instance_variable_set(:@transports, nil)
7-
autoloader = Puppet::ResourceApi::Transport.instance_variable_get(:@autoloader)
8-
autoloader.class.loaded.clear
9-
end
10-
114
describe '#list_all_transports' do
125
subject(:transports) { Puppet::ResourceApi::Transport.list_all_transports('rp_env') }
136

spec/puppet/resource_api/transport_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ def change_environment(name = nil)
2929
Puppet.debug = true
3030
end
3131

32-
after(:each) do
33-
# reset registered transports between tests to reduce cross-test poisoning
34-
described_class.instance_variable_set(:@transports, nil)
35-
end
36-
3732
describe '#register(schema)' do
3833
context 'when registering a schema with missing keys' do
3934
it { expect { described_class.register([]) }.to raise_error(Puppet::DevError, %r{requires a hash as schema}) }

spec/puppet/resource_api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ def set(_context, changes) end
18471847
context 'when loading a type with unknown features' do
18481848
let(:definition) do
18491849
{
1850-
name: 'test_noop_support',
1850+
name: 'test_noop_support_2',
18511851
desc: 'a test resource',
18521852
features: ['no such feature'],
18531853
attributes: {},

spec/spec_helper.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@
3030

3131
# exclude the `version.rb` which already gets loaded by bundler via the gemspec, and doesn't need coverage testing anyways.
3232
SimpleCov.add_filter 'lib/puppet/resource_api/version.rb' if ENV['SIMPLECOV'] == 'yes'
33+
34+
# configure this hook after Resource API is loaded to get access to Puppet::ResourceApi::Transport
35+
RSpec.configure do |config|
36+
config.after(:each) do
37+
# reset registered transports between tests to reduce cross-test poisoning
38+
Puppet::ResourceApi::Transport.instance_variable_set(:@transports, nil)
39+
if (autoloader = Puppet::ResourceApi::Transport.instance_variable_get(:@autoloader))
40+
autoloader.class.loaded.clear
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)