Skip to content

Commit

Permalink
(maint) avoid clashing test with actual fixture, pt2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DavidS committed Jun 28, 2019
1 parent 390e6bf commit ad55367
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
7 changes: 0 additions & 7 deletions spec/integration/resource_api/transport_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
require 'spec_helper'

RSpec.describe 'Resource API Transport integration tests:' do
after(:each) do
# reset registered transports between tests to reduce cross-test poisoning
Puppet::ResourceApi::Transport.instance_variable_set(:@transports, nil)
autoloader = Puppet::ResourceApi::Transport.instance_variable_get(:@autoloader)
autoloader.class.loaded.clear
end

describe '#list_all_transports' do
subject(:transports) { Puppet::ResourceApi::Transport.list_all_transports('rp_env') }

Expand Down
5 changes: 0 additions & 5 deletions spec/puppet/resource_api/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ def change_environment(name = nil)
Puppet.debug = true
end

after(:each) do
# reset registered transports between tests to reduce cross-test poisoning
described_class.instance_variable_set(:@transports, nil)
end

describe '#register(schema)' do
context 'when registering a schema with missing keys' do
it { expect { described_class.register([]) }.to raise_error(Puppet::DevError, %r{requires a hash as schema}) }
Expand Down
2 changes: 1 addition & 1 deletion spec/puppet/resource_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ def set(_context, changes) end
context 'when loading a type with unknown features' do
let(:definition) do
{
name: 'test_noop_support',
name: 'test_noop_support_2',
desc: 'a test resource',
features: ['no such feature'],
attributes: {},
Expand Down
11 changes: 11 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@

# exclude the `version.rb` which already gets loaded by bundler via the gemspec, and doesn't need coverage testing anyways.
SimpleCov.add_filter 'lib/puppet/resource_api/version.rb' if ENV['SIMPLECOV'] == 'yes'

# configure this hook after Resource API is loaded to get access to Puppet::ResourceApi::Transport
RSpec.configure do |config|
config.after(:each) do
# reset registered transports between tests to reduce cross-test poisoning
Puppet::ResourceApi::Transport.instance_variable_set(:@transports, nil)
if (autoloader = Puppet::ResourceApi::Transport.instance_variable_get(:@autoloader))
autoloader.class.loaded.clear
end
end
end

0 comments on commit ad55367

Please sign in to comment.