diff options
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/provider_spec.rb | 23 | ||||
-rw-r--r-- | spec/unit/resource_spec.rb | 27 |
2 files changed, 42 insertions, 8 deletions
diff --git a/spec/unit/provider_spec.rb b/spec/unit/provider_spec.rb index 28874bc0f3..88262dd33a 100644 --- a/spec/unit/provider_spec.rb +++ b/spec/unit/provider_spec.rb @@ -32,6 +32,21 @@ class NoWhyrunDemonstrator < Chef::Provider end end +class ActionDescriptionDemonstrator < Chef::Provider + def load_current_resource; end + + action :foo, description: "foo described" do + true + end + + action :foo2 do + true + end + +end + +context "blah" do +end class ConvergeActionDemonstrator < Chef::Provider attr_reader :system_state_altered @@ -98,6 +113,14 @@ describe Chef::Provider do expect(@provider.action_nothing).to eql(true) end + it "should return an action description for action_description when one is available" do + expect(ActionDescriptionDemonstrator.action_description(:foo)).to eq "foo described" + end + + it "should return nil for action_description when no description is available" do + expect(ActionDescriptionDemonstrator.action_description(:none)).to eq nil + end + it "evals embedded recipes with a pristine resource collection" do @provider.run_context.instance_variable_set(:@resource_collection, "doesn't matter what this is") temporary_collection = nil diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index f7109cc680..5f662dea60 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -1172,21 +1172,23 @@ describe Chef::Resource do action :base_action3, description: "unmodified base action 3 desc" do; end end + let(:resource_inst) { TestResource.new("TestResource", nil) } + it "returns nil when no description was provided for the action" do - expect(TestResource.action_description(:base_action0)).to eql(nil) + expect(resource_inst.action_description(:base_action0)).to eql(nil) end context "when action definition is a string" do it "returns the description whether a symbol or string is used to look it up" do - expect(TestResource.action_description("string_action")).to eql("a string test") - expect(TestResource.action_description(:string_action)).to eql("a string test") + expect(resource_inst.action_description("string_action")).to eql("a string test") + expect(resource_inst.action_description(:string_action)).to eql("a string test") end end context "when action definition is a symbol" do it "returns the description whether a symbol or string is used to look up" do - expect(TestResource.action_description("symbol_action")).to eql("a symbol test") - expect(TestResource.action_description(:symbol_action)).to eql("a symbol test") + expect(resource_inst.action_description("symbol_action")).to eql("a symbol test") + expect(resource_inst.action_description(:symbol_action)).to eql("a symbol test") end end @@ -1196,14 +1198,23 @@ describe Chef::Resource do action :base_action3 do; end end + class TestResourceChild2 < TestResource + # We should never see this description + action :base_action2, description: "if you see this in an error, TestResourceChild was polluted with this description" do; end + end + let(:resource_inst) { TestResourceChild.new("TestResource", nil) } + it "returns original description when a described action is not overridden in child resource" do - expect(TestResourceChild.action_description(:base_action1)).to eq "unmodified base action 1 desc" + expect(resource_inst.action_description(:base_action1)).to eq "unmodified base action 1 desc" end it "returns original description when the child resource overrides an inherited action but NOT its description" do - expect(TestResourceChild.action_description(:base_action3)).to eq "unmodified base action 3 desc" + expect(resource_inst.action_description(:base_action3)).to eq "unmodified base action 3 desc" + end + it "returns new description when the child resource overrides an inherited action and its description" do + expect(resource_inst.action_description(:base_action2)).to eq "modified base action 2 desc" end it "returns new description when the child resource overrides an inherited action and its description" do - expect(TestResourceChild.action_description(:base_action2)).to eq "modified base action 2 desc" + expect(resource_inst.action_description(:base_action2)).to eq "modified base action 2 desc" end end end |