Skip to content

Commit 6a5c39f

Browse files
committed
(maint) Mock APIs correctly
- Prior code from 9b8a0fe 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
1 parent a0827ee commit 6a5c39f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

spec/unit/puppet_x/sql_connection_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ def stub_connection
2424
@connection.stubs(:Open).with('Provider=SQLNCLI11;Initial Catalog=master;Application Name=Puppet;Data Source=.;DataTypeComptibility=80;User ID=sa;Password=Pupp3t1@')
2525
end
2626
it 'should not raise an error but populate has_errors with message' do
27-
@connection.Errors.stubs(:count).returns(1)
28-
@connection.Errors.stubs(:Description).returns("SQL Error in Connection")
27+
@connection.Errors.stubs(:count).returns(2)
28+
@connection.expects(:Errors).with(0).returns(stub( { :Description => "SQL Error in Connection" }))
29+
@connection.expects(:Errors).with(1).returns(stub( { :Description => "Rowdy Roddy Piper" }))
2930
expect {
3031
result = subject.open_and_run_command('whacka whacka whacka', config)
3132
expect(result.exitstatus).to eq(1)
32-
expect(result.error_message).to eq('SQL Error in Connection')
33+
expect(result.error_message).to eq("SQL Error in Connection\nRowdy Roddy Piper")
3334
}.to_not raise_error(Exception)
3435

3536
end

0 commit comments

Comments
 (0)