diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-12-15 14:44:36 -0800 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-12-17 18:52:24 -0800 |
commit | 0587f48b65a0a5f6ed8803cf1bd0d4b78e68c8a8 (patch) | |
tree | 037b99cfc2ccc2634af50514a113a05cc96ac7aa /spec/functional | |
parent | 44fc2faadb2d63c77fb1bfacb973be615a842c42 (diff) | |
download | chef-0587f48b65a0a5f6ed8803cf1bd0d4b78e68c8a8.tar.gz |
Fixing unit test adding Serverspec DSL
Diffstat (limited to 'spec/functional')
-rw-r--r-- | spec/functional/audit/runner_spec.rb | 100 |
1 files changed, 49 insertions, 51 deletions
diff --git a/spec/functional/audit/runner_spec.rb b/spec/functional/audit/runner_spec.rb index 8fab332167..89c62ae2e8 100644 --- a/spec/functional/audit/runner_spec.rb +++ b/spec/functional/audit/runner_spec.rb @@ -36,72 +36,70 @@ describe Chef::Audit::Runner do # Running in a sub_process means the serverspec libraries will only be included in a forked process, not the main one. include RSpec::Support::InSubProcess - let(:events) { double("events").as_null_object } - let(:runner) { Chef::Audit::Runner.new(run_context) } - let(:stdout) { StringIO.new } - - around(:each) do |ex| - Sandboxing.sandboxed { ex.run } - end - - before do - Chef::Config[:log_location] = stdout - end - - # When running these, because we are not mocking out any of the formatters we expect to get dual output on the - # command line - describe "#run" do - - let(:audits) { {} } - let(:run_context) { instance_double(Chef::RunContext, :events => events, :audits => audits) } - let(:controls_name) { "controls_name" } - - it "Correctly runs an empty controls block" do - in_sub_process do - runner.run - end + let(:events) { double("events").as_null_object } + let(:runner) { Chef::Audit::Runner.new(run_context) } + let(:stdout) { StringIO.new } + + around(:each) do |ex| + Sandboxing.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(:controls_name) { "controls_name" } + + it "Correctly runs an empty controls block" do + in_sub_process do + runner.run end + end - context "there is a single successful control" do - let(:audits) do - should_pass = lambda do - it "should pass" do - expect(2 - 2).to eq(0) - end + context "there is a single successful control" do + let(:audits) do + should_pass = lambda do + it "should pass" do + expect(2 - 2).to eq(0) end - { controls_name => Struct.new(:args, :block).new([controls_name], should_pass)} end + { controls_name => Struct.new(:args, :block).new([controls_name], should_pass)} + end - it "correctly runs" do - in_sub_process do - runner.run + it "correctly runs" do + in_sub_process do + runner.run - expect(stdout.string).to match(/1 example, 0 failures/) - end + expect(stdout.string).to match(/1 example, 0 failures/) end end + end - context "there is a single failing control" do - let(:audits) do - should_fail = lambda do - it "should fail" do - expect(2 - 1).to eq(0) - end + context "there is a single failing control" do + let(:audits) do + should_fail = lambda do + it "should fail" do + expect(2 - 1).to eq(0) end - { controls_name => Struct.new(:args, :block).new([controls_name], should_fail)} end + { controls_name => Struct.new(:args, :block).new([controls_name], should_fail)} + end - it "correctly runs" do - in_sub_process do - runner.run + it "correctly runs" 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(/# controls_name should fail/) - end + 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(/# controls_name should fail/) end end - end + end + end |