diff options
author | John Keiser <john@johnkeiser.com> | 2015-12-11 15:51:45 -0800 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-12-11 15:51:45 -0800 |
commit | 50b463e33a2ea6645f3d6fcee836b6f88842bd32 (patch) | |
tree | de01dc2a2cf8cbb04a64b0d22fd4735a98bcb96e /spec/integration | |
parent | 83a1df9786ab19967925b7e4b35a414ec6ff9d57 (diff) | |
download | chef-50b463e33a2ea6645f3d6fcee836b6f88842bd32.tar.gz |
Add inheritance and repeat tests for action_class dojk/action-class-do
Diffstat (limited to 'spec/integration')
-rw-r--r-- | spec/integration/recipes/resource_action_spec.rb | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb index a55ea72b3f..0ea67ea5f2 100644 --- a/spec/integration/recipes/resource_action_spec.rb +++ b/spec/integration/recipes/resource_action_spec.rb @@ -430,22 +430,36 @@ describe "Resource.action" do class DeclaresActionClassMethods < Chef::Resource use_automatic_resource_name property :x - action :hi do - new_resource.x = a + b + action :create do + new_resource.x = a + b + c + d end action_class do def a 1 end + end + declare_action_class do def b 2 end end + action_class do + def c + 3 + end + end + declare_action_class do + def d + 4 + end + end end it "the methods are not available on the resource" do expect { DeclaresActionClassMethods.new('hi').a }.to raise_error(NameError) expect { DeclaresActionClassMethods.new('hi').b }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new('hi').c }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new('hi').d }.to raise_error(NameError) end it "the methods are available to the action" do @@ -453,7 +467,37 @@ describe "Resource.action" do expect_recipe { r = declares_action_class_methods 'hi' }.to emit_no_warnings_or_errors - expect(r.x).to eq(3) + expect(r.x).to eq(10) + end + + context "And a subclass also creates a method" do + class DeclaresActionClassMethodsToo < DeclaresActionClassMethods + use_automatic_resource_name + action :create do + new_resource.x a+b+c+d+e + end + action_class do + def e + 5 + end + end + end + + it "the methods are not available on the resource" do + expect { DeclaresActionClassMethods.new('hi').a }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new('hi').b }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new('hi').c }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new('hi').d }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new('hi').e }.to raise_error(NameError) + end + + it "the methods are available to the action" do + r = nil + expect_recipe { + r = declares_action_class_methods_too 'hi' + }.to emit_no_warnings_or_errors + expect(r.x).to eq(15) + end end end end |