diff options
author | Serdar Sutay <serdar@opscode.com> | 2015-05-21 14:03:31 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2015-05-29 08:41:12 -0700 |
commit | 3e1cbd6856eda733a1ed800184d8545e5d070e8e (patch) | |
tree | ae3acb56976aaee7963ba20851a9684702d23370 /spec/functional/audit | |
parent | c58162b9ce165bde444ff396a95668666884c052 (diff) | |
download | chef-3e1cbd6856eda733a1ed800184d8545e5d070e8e.tar.gz |
Make sure the audit mode output is reflected both in the logs and in the formatter output.
Diffstat (limited to 'spec/functional/audit')
-rw-r--r-- | spec/functional/audit/runner_spec.rb | 64 |
1 files changed, 22 insertions, 42 deletions
diff --git a/spec/functional/audit/runner_spec.rb b/spec/functional/audit/runner_spec.rb index 494942889a..aae8fcf582 100644 --- a/spec/functional/audit/runner_spec.rb +++ b/spec/functional/audit/runner_spec.rb @@ -46,22 +46,12 @@ describe Chef::Audit::Runner do RSpec::Core::Sandbox.sandboxed { ex.run } end - before do - Chef::Config[:log_location] = stdout - end - describe "#run" do let(:audits) { {} } let(:run_context) { instance_double(Chef::RunContext, :events => events, :audits => audits) } let(:control_group_name) { "control_group_name" } - it "Correctly runs an empty controls block" do - in_sub_process do - runner.run - end - end - shared_context "passing audit" do let(:audits) do should_pass = lambda do @@ -84,50 +74,40 @@ describe Chef::Audit::Runner do end end - context "there is a single successful control" do - include_context "passing audit" - it "correctly runs" do - in_sub_process do - runner.run - - expect(stdout.string).to match(/1 example, 0 failures/) + describe "log location is stdout" do + before do + allow(Chef::Log).to receive(:info) do |msg| + stdout.puts(msg) end end - end - context "there is a single failing control" do - include_context "failing audit" - it "correctly runs" do + it "Correctly runs an empty controls block" do in_sub_process do runner.run - - expect(stdout.string).to match(/Failure\/Error: expect\(2 - 1\)\.to eq\(0\)/) - expect(stdout.string).to match(/1 example, 1 failure/) - expect(stdout.string).to match(/# control_group_name should fail/) end end - end - describe "log location is a file" do - let(:tmpfile) { Tempfile.new("audit") } - before do - Chef::Config[:log_location] = tmpfile.path - end + context "there is a single successful control" do + include_context "passing audit" + it "correctly runs" do + in_sub_process do + runner.run - after do - tmpfile.close - tmpfile.unlink + expect(stdout.string).to match(/1 example, 0 failures/) + end + end end - include_context "failing audit" - it "correctly runs" do - in_sub_process do - runner.run + context "there is a single failing control" do + include_context "failing audit" + it "correctly runs" do + in_sub_process do + runner.run - contents = tmpfile.read - expect(contents).to match(/Failure\/Error: expect\(2 - 1\)\.to eq\(0\)/) - expect(contents).to match(/1 example, 1 failure/) - expect(contents).to match(/# control_group_name should fail/) + expect(stdout.string).to match(/Failure\/Error: expect\(2 - 1\)\.to eq\(0\)/) + expect(stdout.string).to match(/1 example, 1 failure/) + expect(stdout.string).to match(/# control_group_name should fail/) + end end end end |