diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-10-31 10:58:35 -0700 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-10-31 10:58:35 -0700 |
commit | 0ff3d5010df97af2c8c02a30fe300830be593c39 (patch) | |
tree | 0d6135442eea0c014da3fd3a7d314ccd27f8041f | |
parent | 94947461dc3b28494053a86fee5d5004bdbd9692 (diff) | |
download | chef-tball/audit-mode.tar.gz |
Updating for github commentstball/audit-mode
-rw-r--r-- | lib/chef/dsl/audit.rb | 2 | ||||
-rw-r--r-- | lib/chef/exceptions.rb | 11 | ||||
-rw-r--r-- | spec/unit/exceptions_spec.rb | 46 |
3 files changed, 55 insertions, 4 deletions
diff --git a/lib/chef/dsl/audit.rb b/lib/chef/dsl/audit.rb index fee89c02ca..7adcecbf14 100644 --- a/lib/chef/dsl/audit.rb +++ b/lib/chef/dsl/audit.rb @@ -24,7 +24,7 @@ class Chef # Adds the controls group and block (containing controls to execute) to the runner's list of pending examples def controls(group_name, &group_block) - raise ::Chef::Exceptions::NoAuditsProvided("You must provide a block with audits") unless group_block + raise ::Chef::Exceptions::NoAuditsProvided unless group_block # TODO add the @example_groups list to the runner for later execution # run_context.audit_runner.register diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index eb7c27b2a8..ddfa574973 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -367,7 +367,11 @@ class Chef end end - class NoAuditsProvided < RuntimeError; end + class NoAuditsProvided < RuntimeError + def initialize + super "You must provide a block with audits" + end + end # If a converge or audit fails, we want to wrap the output from those errors into 1 error so we can # see both issues in the output. It is possible that nil will be provided. You must call `fill_backtrace` @@ -384,10 +388,11 @@ class Chef def fill_backtrace backtrace = [] wrapped_errors.each_with_index do |e,i| - backtrace << "#{i+1}) #{e.message}" - backtrace += e.backtrace + backtrace << "#{i+1}) #{e.class} - #{e.message}" + backtrace += e.backtrace if e.backtrace backtrace << "" end + set_backtrace(backtrace) end end end diff --git a/spec/unit/exceptions_spec.rb b/spec/unit/exceptions_spec.rb index 21b0abb9bf..59e507f7a8 100644 --- a/spec/unit/exceptions_spec.rb +++ b/spec/unit/exceptions_spec.rb @@ -81,4 +81,50 @@ describe Chef::Exceptions do end end end + + describe Chef::Exceptions::RunFailedWrappingError do + shared_examples "RunFailedWrappingError expectations" do + it "should initialize with a default message" do + expect(e.message).to eq("Found #{num_errors} errors, they are stored in the backtrace\n") + end + + it "should provide a modified backtrace when requested" do + e.fill_backtrace + expect(e.backtrace).to eq(backtrace) + end + end + + context "initialized with nothing" do + let(:e) { Chef::Exceptions::RunFailedWrappingError.new } + let(:num_errors) { 0 } + let(:backtrace) { [] } + + include_examples "RunFailedWrappingError expectations" + end + + context "initialized with nil" do + let(:e) { Chef::Exceptions::RunFailedWrappingError.new(nil, nil) } + let(:num_errors) { 0 } + let(:backtrace) { [] } + + include_examples "RunFailedWrappingError expectations" + end + + context "initialized with 1 error and nil" do + let(:e) { Chef::Exceptions::RunFailedWrappingError.new(RuntimeError.new("foo"), nil) } + let(:num_errors) { 1 } + let(:backtrace) { ["1) RuntimeError - foo", ""] } + + include_examples "RunFailedWrappingError expectations" + end + + context "initialized with 2 errors" do + let(:e) { Chef::Exceptions::RunFailedWrappingError.new(RuntimeError.new("foo"), RuntimeError.new("bar")) } + let(:num_errors) { 2 } + let(:backtrace) { ["1) RuntimeError - foo", "", "2) RuntimeError - bar", ""] } + + include_examples "RunFailedWrappingError expectations" + end + + end end |