summaryrefslogtreecommitdiff
path: root/spec/integration
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-05 14:47:18 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-08 09:01:55 -0700
commit3dcaddb86dc85a4cf730e675232ce83f97d5726b (patch)
tree950b87bae166f85b45edf7552dee6891153e8125 /spec/integration
parentc65de79dbd662d895c8a10ef496d7eb9c69376c2 (diff)
downloadchef-3dcaddb86dc85a4cf730e675232ce83f97d5726b.tar.gz
Make sure resource_name :x only removes automatic provides from that class
Diffstat (limited to 'spec/integration')
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb108
-rw-r--r--spec/integration/recipes/resource_definition_spec.rb18
2 files changed, 108 insertions, 18 deletions
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index 403c879e74..9595653ad8 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -3,6 +3,14 @@ require 'support/shared/integration/integration_helper'
describe "Recipe DSL methods" do
include IntegrationSupport
+ module Namer
+ extend self
+ attr_accessor :current_index
+ end
+
+ before(:all) { Namer.current_index = 1 }
+ before { Namer.current_index += 1 }
+
context "With resource 'base_thingy' declared as BaseThingy" do
before(:context) {
@@ -403,6 +411,106 @@ describe "Recipe DSL methods" do
}.to raise_error(NoMethodError)
end
end
+
+ context "With a resource TwoClassesOneDsl" do
+ let(:class_name) { "TwoClassesOneDsl#{Namer.current_index}" }
+ let(:dsl_method) { "two_classes_one_dsl#{Namer.current_index}" }
+
+ before {
+ eval <<-EOM, nil, __FILE__, __LINE__+1
+ class #{class_name} < BaseThingy
+ end
+ EOM
+ }
+ context "And resource BlahModule::TwoClassesOneDsl" do
+ before {
+ eval <<-EOM, nil, __FILE__, __LINE__+1
+ module BlahModule
+ class #{class_name} < BaseThingy
+ end
+ end
+ EOM
+ }
+ it "two_classes_one_dsl resolves to BlahModule::TwoClassesOneDsl (last declared)" do
+ dsl_method = self.dsl_method
+ recipe = converge {
+ instance_eval("#{dsl_method} 'blah' do; end")
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq eval("BlahModule::#{class_name}")
+ end
+ end
+ context "And resource BlahModule::TwoClassesOneDsl with resource_name nil" do
+ before {
+ eval <<-EOM, nil, __FILE__, __LINE__+1
+ module BlahModule
+ class BlahModule::#{class_name} < BaseThingy
+ resource_name nil
+ end
+ end
+ EOM
+ }
+ it "two_classes_one_dsl resolves to ::TwoClassesOneDsl" do
+ dsl_method = self.dsl_method
+ recipe = converge {
+ instance_eval("#{dsl_method} 'blah' do; end")
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq eval("::#{class_name}")
+ end
+ end
+ context "And resource BlahModule::TwoClassesOneDsl with resource_name :argh" do
+ before {
+ eval <<-EOM, nil, __FILE__, __LINE__+1
+ module BlahModule
+ class BlahModule::#{class_name} < BaseThingy
+ resource_name :argh
+ end
+ end
+ EOM
+ }
+ it "two_classes_one_dsl resolves to ::TwoClassesOneDsl" do
+ dsl_method = self.dsl_method
+ recipe = converge {
+ instance_eval("#{dsl_method} 'blah' do; end")
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq eval("::#{class_name}")
+ end
+ end
+ context "And resource BlahModule::TwoClassesOneDsl with provides :two_classes_one_dsl, os: 'blarghle'" do
+ before {
+ eval <<-EOM, nil, __FILE__, __LINE__+1
+ module BlahModule
+ class BlahModule::#{class_name} < BaseThingy
+ provides #{dsl_method.inspect}, os: 'blarghle'
+ end
+ end
+ EOM
+ }
+ it "and os = blarghle, two_classes_one_dsl resolves to BlahModule::TwoClassesOneDsl" do
+ dsl_method = self.dsl_method
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ instance_eval("#{dsl_method} 'blah' do; end")
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq eval("BlahModule::#{class_name}")
+ end
+
+ it "and os = linux, two_classes_one_dsl resolves to BlahModule::TwoClassesOneDsl" do
+ dsl_method = self.dsl_method
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ instance_eval("#{dsl_method} 'blah' do; end")
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq eval("::#{class_name}")
+ end
+ end
+ end
end
end
diff --git a/spec/integration/recipes/resource_definition_spec.rb b/spec/integration/recipes/resource_definition_spec.rb
deleted file mode 100644
index 4e5bc53428..0000000000
--- a/spec/integration/recipes/resource_definition_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require 'support/shared/integration/integration_helper'
-
-describe "Resource definition" do
- include IntegrationSupport
-
- context "With a resource with only provides lines and no resource_name" do
- before(:context) {
- class ResourceDefinitionNoNameTest < Chef::Resource
- provides :resource_definition_no_name_test
- end
- }
- it "Creating said resource with the resource builder fails with an exception" do
- expect_converge {
- resource_definition_no_name_test 'blah'
- }.to raise_error(Chef::Exceptions::InvalidResourceSpecification)
- end
- end
-end