Sha256: 3dabda27e151e3a5987e96013e388fd96b058eb989788678be31982ed1938ca0

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'
require 'chef/rewind'

describe Chef::Recipe do

  before(:each) do
    @cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks"))
    cl = Chef::CookbookLoader.new(@cookbook_repo)
    cl.load_cookbooks
    @cookbook_collection = Chef::CookbookCollection.new(cl)
    @node = Chef::Node.new
    @node.normal[:tags] = Array.new
    @events = Chef::EventDispatch::Dispatcher.new
    @run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
    @recipe = Chef::Recipe.new("hjk", "test", @run_context)

    # Shell/ext.rb is on the run path, and it defines
    # Chef::Recipe#resources to call pp, which we don't want when
    # we're running tests.
    allow(@recipe).to receive(:pp)
  end


  describe "rewind" do
    it "rewind an existing resource rather than create a new one" do

      @recipe.zen_master "foobar" do
        peace false
      end

      @recipe.rewind "zen_master[foobar]" do
        peace true
      end
      resources = @run_context.resource_collection.all_resources
      expect(resources.length).to eq 1
    end

    it "change the value of an existing resource" do
      @recipe.zen_master "foobar" do
        peace false
      end

      @recipe.rewind "zen_master[foobar]" do
        peace true
      end

      zen_master = @run_context.resource_collection.find("zen_master[foobar]")
      peace_status = zen_master.instance_exec { @peace }
      expect(peace_status).to be true 
    end

    it "throw an error when rewinding a nonexistent resource" do
      expect {
        @recipe.rewind "zen_master[foobar]" do
          peace true
        end
      }.to raise_error(Chef::Exceptions::ResourceNotFound)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chef-rewind-0.0.9 spec/rewind_recipe_spec.rb