Sha256: 0417637eb5ee69b50edf338125c67231617f5117fa36990fd486eb3c585c76f9

Contents?: true

Size: 1.32 KB

Versions: 23

Compression:

Stored size: 1.32 KB

Contents

require "spec_helper"
require "chef/dsl/audit"

class AuditDSLTester < Chef::Recipe
  include Chef::DSL::Audit
end

class BadAuditDSLTester
  include Chef::DSL::Audit
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.control_group "name" }.to raise_error(Chef::Exceptions::NoAuditsProvided)
  end

  it "raises an error when no audit name is given" do
    expect { auditor.control_group {} }.to raise_error(Chef::Exceptions::AuditNameMissing)
  end

  context "audits already populated" do
    let(:audits) { { "unique" => {} } }

    it "raises an error if the audit name is a duplicate" do
      expect { auditor.control_group("unique") {} }.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.control_group("unique") {} }.to raise_error(NoMethodError, /undefined method `cookbook_name'/)
    end
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
chef-14.15.6 spec/unit/dsl/audit_spec.rb
chef-14.15.6-universal-mingw32 spec/unit/dsl/audit_spec.rb
chef-14.14.29 spec/unit/dsl/audit_spec.rb
chef-14.14.29-universal-mingw32 spec/unit/dsl/audit_spec.rb
chef-14.14.25-universal-mingw32 spec/unit/dsl/audit_spec.rb
chef-14.14.25 spec/unit/dsl/audit_spec.rb
chef-14.14.14-universal-mingw32 spec/unit/dsl/audit_spec.rb
chef-14.14.14 spec/unit/dsl/audit_spec.rb
chef-14.13.11 spec/unit/dsl/audit_spec.rb
chef-14.12.9 spec/unit/dsl/audit_spec.rb
chef-14.12.3 spec/unit/dsl/audit_spec.rb
chef-14.11.21 spec/unit/dsl/audit_spec.rb
chef-14.10.9 spec/unit/dsl/audit_spec.rb
chef-14.9.13 spec/unit/dsl/audit_spec.rb
chef-14.8.12 spec/unit/dsl/audit_spec.rb
chef-14.7.17 spec/unit/dsl/audit_spec.rb
chef-14.6.47 spec/unit/dsl/audit_spec.rb
chef-14.5.33 spec/unit/dsl/audit_spec.rb
chef-14.5.27 spec/unit/dsl/audit_spec.rb
chef-14.5.27-universal-mingw32 spec/unit/dsl/audit_spec.rb