Sha256: 6ad7fb04f818f116caac3a4787be7724c140fb2f103b3e881e455683a477cd88

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

require File.expand_path('../../spec_helper', __FILE__)

describe MiniTest::Chef::Resources do

  let(:resources) { Class.new{ include MiniTest::Chef::Resources }.new }

  it "provides convenient access to current resource state" do
    [:cron, :directory, :file, :group, :ifconfig, :link, :mount, :package,
     :service, :user].each do |type|
      resources.must_respond_to(type)
    end
  end

  it "doesn't make available resources that are not idempotent" do
    [:bash, :erl_call, :execute, :ruby].each do |type|
      resources.wont_respond_to(type)
    end
  end

  it "doesn't make available file resources other than file itself" do
    [:cookbook_file, :remote_file, :template].each do |type|
      resources.wont_respond_to(type)
    end
  end

  describe "asserting with 'with' syntax" do
    let(:file) { ::Chef::Resource::File.new('/etc/foo') }
    it "can take an attribute name and value to assert against" do
      file.must_have(:name, '/etc/foo').must_equal file
    end
    it "allows assertions on resources to be chained together with 'with'" do
      file.must_have(:name, '/etc/foo').with(:action, 'create').must_equal(file)
    end
    it "allows assertions on resources to be chained together with 'and'" do
      file.must_have(:name, '/etc/foo').with(:action, 'create').
        and(:backup, 5).must_equal(file)
    end
    it "fails if the assertion is not met" do
      assert_triggered(/The file does not have the expected name/) do
        file.must_have(:name, '/etc/bar')
      end
      assert_triggered(/The file does not have the expected action/) do
        file.must_have(:name, '/etc/foo').with(:action, 'delete')
      end
      assert_triggered(/The file does not have the expected action/) do
        file.must_have(:name, '/etc/foo').and(:action, 'delete')
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
minitest-chef-handler-0.5.1 spec/minitest-chef-handler/resources_spec.rb
minitest-chef-handler-0.5.0 spec/minitest-chef-handler/resources_spec.rb
minitest-chef-handler-0.4.0 spec/minitest-chef-handler/resources_spec.rb