summaryrefslogtreecommitdiff
path: root/spec/unit/recipe_spec.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-01-20 10:16:17 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-01-20 10:21:10 -0800
commit35276fd91c5aec8986723504b8a490e5823b770e (patch)
tree5ea6d3a89ebc905d816753160d290e8a76199e0b /spec/unit/recipe_spec.rb
parentb622710cd1ee8af39bc3ff255e2394c0115abaac (diff)
downloadchef-35276fd91c5aec8986723504b8a490e5823b770e.tar.gz
make include_recipe "::foo" use current cookbook
The following code is brittle if you want to fork the cookbook and rename it (which is a best practice when forking cookbooks for internal use): ```ruby if node[:platform_family] == "rhel" include_recipe "mycookbook::_rhel" end ``` In order for cookbooks to be easily renamable they can currently use the syntax `include_recipe "#{cookbook_name}::_rhel"` which is unwieldy. This patch adds `include_recipe "::_rhel"` as syntax sugar to make this easier.
Diffstat (limited to 'spec/unit/recipe_spec.rb')
-rw-r--r--spec/unit/recipe_spec.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb
index 22389a1a82..5ade7c86e2 100644
--- a/spec/unit/recipe_spec.rb
+++ b/spec/unit/recipe_spec.rb
@@ -501,6 +501,34 @@ describe Chef::Recipe do
expect(cookbook_collection[:openldap]).not_to receive(:load_recipe).with("default", run_context)
recipe.include_recipe "openldap"
end
+
+ it "will load a recipe out of the current cookbook when include_recipe is called with a leading ::" do
+ openldap_recipe = Chef::Recipe.new("openldap", "test", run_context)
+ expect(node).to receive(:loaded_recipe).with(:openldap, "default").exactly(:once)
+ allow(run_context).to receive(:unreachable_cookbook?).with(:openldap).and_return(false)
+ expect(cookbook_collection[:openldap]).to receive(:load_recipe).with("default", run_context)
+ openldap_recipe.include_recipe "::default"
+ end
+
+ it "will not include the same recipe twice when using leading :: syntax" do
+ openldap_recipe = Chef::Recipe.new("openldap", "test", run_context)
+ expect(node).to receive(:loaded_recipe).with(:openldap, "default").exactly(:once)
+ allow(run_context).to receive(:unreachable_cookbook?).with(:openldap).and_return(false)
+ expect(cookbook_collection[:openldap]).to receive(:load_recipe).with("default", run_context)
+ openldap_recipe.include_recipe "::default"
+ expect(cookbook_collection[:openldap]).not_to receive(:load_recipe).with("default", run_context)
+ openldap_recipe.include_recipe "openldap::default"
+ end
+
+ it "will not include the same recipe twice when using leading :: syntax (reversed order)" do
+ openldap_recipe = Chef::Recipe.new("openldap", "test", run_context)
+ expect(node).to receive(:loaded_recipe).with(:openldap, "default").exactly(:once)
+ allow(run_context).to receive(:unreachable_cookbook?).with(:openldap).and_return(false)
+ expect(cookbook_collection[:openldap]).to receive(:load_recipe).with("default", run_context)
+ openldap_recipe.include_recipe "openldap::default"
+ expect(cookbook_collection[:openldap]).not_to receive(:load_recipe).with("default", run_context)
+ openldap_recipe.include_recipe "::default"
+ end
end
describe "tags" do