Skip to content

Commit

Permalink
stelligent#394 Cleaning up rspec output by adding error types to `rai…
Browse files Browse the repository at this point in the history
…se_error` where needed and capturing stderr/stdout from cfn_nag_executor.
  • Loading branch information
Patrick Shelby committed Mar 3, 2020
1 parent b592ee3 commit 245e557
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/blacklist_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def rule_id

expect do
BlackListLoader.new(@rule_registry).load blacklist_definition: blacklist_definition
end.to raise_error # 'FAKEID is not a legal rule identifier'
end.to raise_error RuntimeError, /FAKEID1 is not a legal rule identifier/
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/cfn_nag_integration/cfn_nag_executor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
require 'cfn-nag/cfn_nag_executor'

describe CfnNagExecutor do
# Method of suppressing stderr and stdout was found on StackOverflow here:
# https://stackoverflow.com/a/22777806
original_stderr = nil
original_stdout = nil

before(:all) do
CfnNagLogging.configure_logging(debug: false)
Expand All @@ -17,6 +21,18 @@
output_format: 'json',
rule_repository: []
}

original_stderr = $stderr # capture previous value of $stderr
original_stdout = $stdout # capture previous value of $stdout
$stderr = StringIO.new # assign a string buffer to $stderr
$stdout = StringIO.new # assign a string buffer to $stdout
# $stderr.string # return the contents of the string buffer if needed
# $stdout.string # return the contents of the string buffer if needed
end

after(:all) do
$stderr = original_stderr # restore $stderr to its previous value
$stdout = original_stdout # restore $stdout to its previous value
end

context 'single file cfn_nag with fail on warnings' do
Expand Down
2 changes: 1 addition & 1 deletion spec/profile_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def rule_id
it 'should raise an error' do
expect do
ProfileLoader.new(@rule_registry).load profile_definition: 'FAKEID1'
end.to raise_error # 'FAKEID is not a legal rule identifier'
end.to raise_error RuntimeError, /FAKEID1 is not a legal rule identifier/
end
end

Expand Down

0 comments on commit 245e557

Please sign in to comment.