From a0827ee2e2199e2364add0ebb93c59693f2bf165 Mon Sep 17 00:00:00 2001 From: Iristyle Date: Thu, 6 Sep 2018 14:16:48 -0700 Subject: [PATCH 1/2] (maint) Only set Puppet[:strict] where supported --- spec/spec_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e69d11d8..ba2ee5e6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,7 +31,8 @@ c.before :each do # set to strictest setting for testing # by default Puppet runs at warning level - Puppet.settings[:strict] = :warning + # newer versions of Puppet remove :strict + Puppet.settings[:strict] = :warning if Puppet.settings.include?(:strict) end end From 6a5c39f6222bae63567e7946294de0a415cec1fa Mon Sep 17 00:00:00 2001 From: Iristyle Date: Thu, 6 Sep 2018 14:55:55 -0700 Subject: [PATCH 2/2] (maint) Mock APIs correctly - Prior code from 9b8a0fe9bbbe0699b6626f92ac6f9dc4ddad9584 used a non-obvious behavior in the mocking framework to return the Description value from an error instance. If the count of errors was returned was increased by 1, the code would be subtly wrong as mocks are generating to each call of .Errors(x) with the supplied values. - Instead, more clearly mock the actual code path, and additionally provide two separate messages, demonstrating they are iterated and joined properly --- spec/unit/puppet_x/sql_connection_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/unit/puppet_x/sql_connection_spec.rb b/spec/unit/puppet_x/sql_connection_spec.rb index cefce388..efffdfa8 100644 --- a/spec/unit/puppet_x/sql_connection_spec.rb +++ b/spec/unit/puppet_x/sql_connection_spec.rb @@ -24,12 +24,13 @@ def stub_connection @connection.stubs(:Open).with('Provider=SQLNCLI11;Initial Catalog=master;Application Name=Puppet;Data Source=.;DataTypeComptibility=80;User ID=sa;Password=Pupp3t1@') end it 'should not raise an error but populate has_errors with message' do - @connection.Errors.stubs(:count).returns(1) - @connection.Errors.stubs(:Description).returns("SQL Error in Connection") + @connection.Errors.stubs(:count).returns(2) + @connection.expects(:Errors).with(0).returns(stub( { :Description => "SQL Error in Connection" })) + @connection.expects(:Errors).with(1).returns(stub( { :Description => "Rowdy Roddy Piper" })) expect { result = subject.open_and_run_command('whacka whacka whacka', config) expect(result.exitstatus).to eq(1) - expect(result.error_message).to eq('SQL Error in Connection') + expect(result.error_message).to eq("SQL Error in Connection\nRowdy Roddy Piper") }.to_not raise_error(Exception) end