diff options
author | Tyler Ball <tyleraball@gmail.com> | 2014-12-09 14:08:43 -0800 |
---|---|---|
committer | Tyler Ball <tyleraball@gmail.com> | 2014-12-09 14:08:43 -0800 |
commit | 49e51d3d2b49897129201d8bc559351a8fdcb76b (patch) | |
tree | f9bc9a9d1eb707de450c74ec98f217f5e2220f70 | |
parent | ac93a406f34ae19af1377284b5cd3b5b05119558 (diff) | |
parent | f8ef27aa8e202934f5d2f9d09fa264fc4d54e7ea (diff) | |
download | chef-49e51d3d2b49897129201d8bc559351a8fdcb76b.tar.gz |
Merge pull request #2586 from opscode/tball/dsl-test
Adding audit DSL coverage
-rw-r--r-- | spec/unit/dsl/audit_spec.rb | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/spec/unit/dsl/audit_spec.rb b/spec/unit/dsl/audit_spec.rb index 7565a42d58..38707127f0 100644 --- a/spec/unit/dsl/audit_spec.rb +++ b/spec/unit/dsl/audit_spec.rb @@ -2,18 +2,19 @@ require 'spec_helper' require 'chef/dsl/audit' -class AuditDSLTester +class AuditDSLTester < Chef::Recipe include Chef::DSL::Audit end -describe Chef::DSL::Audit do - let(:auditor) { AuditDSLTester.new } - let(:run_context) { instance_double(Chef::RunContext, :audits => audits) } - let(:audits) { [] } +class BadAuditDSLTester + include Chef::DSL::Audit +end - before do - allow(auditor).to receive(:run_context).and_return(run_context) - end +describe Chef::DSL::Audit do + let(:auditor) { AuditDSLTester.new("cookbook_name", "recipe_name", run_context) } + let(:run_context) { instance_double(Chef::RunContext, :audits => audits, :cookbook_collection => cookbook_collection) } + let(:audits) { {} } + let(:cookbook_collection) { {} } it "raises an error when a block of audits is not provided" do expect{ auditor.controls "name" }.to raise_error(Chef::Exceptions::NoAuditsProvided) @@ -23,8 +24,20 @@ describe Chef::DSL::Audit do expect{ auditor.controls do end }.to raise_error(Chef::Exceptions::AuditNameMissing) end - it "raises an error if the audit name is a duplicate" do - expect(audits).to receive(:has_key?).with("unique").and_return(true) - expect { auditor.controls "unique" do end }.to raise_error(Chef::Exceptions::AuditControlGroupDuplicate) + context "audits already populated" do + let(:audits) { {"unique" => {} } } + + it "raises an error if the audit name is a duplicate" do + expect { auditor.controls "unique" do end }.to raise_error(Chef::Exceptions::AuditControlGroupDuplicate) + end end + + context "included in a class without recipe DSL" do + let(:auditor) { BadAuditDSLTester.new } + + it "fails because it relies on the recipe DSL existing" do + expect { auditor.controls "unique" do end }.to raise_error(NoMethodError, /undefined method `cookbook_name'/) + end + end + end |