summaryrefslogtreecommitdiff
path: root/spec/unit/recipe_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/recipe_spec.rb')
-rw-r--r--spec/unit/recipe_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb
index b370e12732..7442f4477e 100644
--- a/spec/unit/recipe_spec.rb
+++ b/spec/unit/recipe_spec.rb
@@ -20,6 +20,7 @@
#
require 'spec_helper'
+require 'chef/platform/resource_priority_map'
describe Chef::Recipe do
@@ -136,6 +137,44 @@ describe Chef::Recipe do
res.kind_of?(YourMom)
end
+ describe "when there is more than one resource that resolves on a node" do
+ before do
+ node.automatic[:platform] = "nbc_sports"
+ Sounders = Class.new(Chef::Resource)
+ Sounders.provides :football, platform: "nbc_sports"
+ TottenhamHotspur = Class.new(Chef::Resource)
+ TottenhamHotspur.provides :football, platform: "nbc_sports"
+ end
+
+ after do
+ Object.send(:remove_const, :Sounders)
+ Object.send(:remove_const, :TottenhamHotspur)
+ end
+
+ it "warns if resolution of the two resources is ambiguous" do
+ expect(Chef::Log).to receive(:warn).at_least(:once).with(/Ambiguous resource precedence/)
+ res1 = recipe.football "club world cup"
+ expect(res1.name).to eql("club world cup")
+ # the class of res1 is not defined.
+ end
+
+ it "selects one if it is given priority" do
+ expect(Chef::Log).not_to receive(:warn)
+ Chef::Platform::ResourcePriorityMap.instance.send(:priority, :football, TottenhamHotspur, platform: "nbc_sports")
+ res1 = recipe.football "club world cup"
+ expect(res1.name).to eql("club world cup")
+ expect(res1).to be_a_kind_of(TottenhamHotspur)
+ end
+
+ it "selects the other one if it is given priority" do
+ expect(Chef::Log).not_to receive(:warn)
+ Chef::Platform::ResourcePriorityMap.instance.send(:priority, :football, Sounders, platform: "nbc_sports")
+ res1 = recipe.football "club world cup"
+ expect(res1.name).to eql("club world cup")
+ expect(res1).to be_a_kind_of(Sounders)
+ end
+ end
+
end
end