From 7554c2f7e1e96f2170cc7f669bebbaa07464eaba Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Tue, 21 May 2019 14:28:17 +0100 Subject: [PATCH 1/3] (maint) make test order really random The test leakage fixed in the previous commit was only detected by changing the test order. Removing the seed will ensure that different test orderings are tested, leading to a more robust test suite as new issues are discovered and fixed. --- .rspec | 2 +- spec/puppet/resource_api_spec.rb | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.rspec b/.rspec index c895322c..333d91ee 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,3 @@ --format documentation --color ---order rand:123 \ No newline at end of file +--order rand diff --git a/spec/puppet/resource_api_spec.rb b/spec/puppet/resource_api_spec.rb index 29446642..17119e9e 100644 --- a/spec/puppet/resource_api_spec.rb +++ b/spec/puppet/resource_api_spec.rb @@ -1816,20 +1816,22 @@ def set(_context, changes) end it { expect { described_class.register_type(definition) }.not_to raise_error } - it 'is seen as a supported feature' do - expect(Puppet).not_to receive(:warning).with(%r{Unknown feature detected:.*simple_test_filter}) - expect { described_class.register_type(definition) }.not_to raise_error - end + context 'with the type registered' do + it 'is seen as a supported feature' do + expect(Puppet).not_to receive(:warning).with(%r{Unknown feature detected:.*simple_test_filter}) + expect { described_class.register_type(definition) }.not_to raise_error + end - it 'passes through the an empty array to `get`' do - expect(provider).to receive(:get).with(anything, []).and_return([]) - type.instances - end + it 'passes through the an empty array to `get`' do + expect(provider).to receive(:get).with(anything, []).and_return([]) + type.instances + end - it 'passes through the resource title to `get`' do - instance = type.new(name: 'bar', ensure: 'present') - expect(provider).to receive(:get).with(anything, ['bar']).and_return([]) - instance.retrieve + it 'passes through the resource title to `get`' do + instance = type.new(name: 'bar', ensure: 'present') + expect(provider).to receive(:get).with(anything, ['bar']).and_return([]) + instance.retrieve + end end end From 64484235feb58a2e669994f82fc863606abc4c01 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Tue, 21 May 2019 14:27:49 +0100 Subject: [PATCH 2/3] (maint) reset provider cache between tests Without this the `provider` mock would leak between tests. --- spec/puppet/resource_api_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/puppet/resource_api_spec.rb b/spec/puppet/resource_api_spec.rb index 17119e9e..36a1fa39 100644 --- a/spec/puppet/resource_api_spec.rb +++ b/spec/puppet/resource_api_spec.rb @@ -1814,6 +1814,11 @@ def set(_context, changes) end allow(provider_class).to receive(:new).and_return(provider) end + after(:each) do + # reset cached provider between tests + type.instance_variable_set(:@my_provider, nil) + end + it { expect { described_class.register_type(definition) }.not_to raise_error } context 'with the type registered' do From 74559e069dc83b585a95e6ffe517038d5618696a Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 13 Jun 2019 17:45:33 +0100 Subject: [PATCH 3/3] (maint) reset warning count after testing filtering After each of those test, the `warning_count` was 100 and other tests for warnings would fail as they would have been swallowed. --- spec/puppet/resource_api/type_definition_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/puppet/resource_api/type_definition_spec.rb b/spec/puppet/resource_api/type_definition_spec.rb index 592f02ea..adc4f9f1 100644 --- a/spec/puppet/resource_api/type_definition_spec.rb +++ b/spec/puppet/resource_api/type_definition_spec.rb @@ -119,6 +119,10 @@ Puppet.settings[:strict] = strict_level end + after(:each) do + Puppet::ResourceApi.warning_count = 0 + end + context 'when puppet strict is set to default (warning)' do it 'displays up to 100 warnings' do expect(Puppet).to receive(:warning).with(message).exactly(100).times @@ -156,6 +160,10 @@ Puppet.settings[:strict] = strict_level end + after(:each) do + Puppet::ResourceApi.warning_count = 0 + end + context 'when puppet strict is set to default (warning)' do it 'displays up to 100 warnings' do expect(Puppet).to receive(:warning).with(message).exactly(100).times