diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-05 15:00:00 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-05 15:00:00 -0800 |
commit | 686113531d23f30e9973d659c456ae33eb9cff1f (patch) | |
tree | f225de7251a8b49b8d183dd168bab0a0addbe23f /spec/integration | |
parent | d1cf34b059a16a81e0fc48de52ba29863bb41fe6 (diff) | |
download | chef-686113531d23f30e9973d659c456ae33eb9cff1f.tar.gz |
autofixing whitespace cops
4174 Style/SpaceInsideHashLiteralBraces
1860 Style/SpaceAroundOperators
1336 Style/SpaceInsideBlockBraces
1292 Style/AlignHash
997 Style/SpaceAfterComma
860 Style/SpaceAroundEqualsInParameterDefault
310 Style/EmptyLines
294 Style/IndentationConsistency
267 Style/TrailingWhitespace
238 Style/ExtraSpacing
212 Style/SpaceBeforeBlockBraces
166 Style/MultilineOperationIndentation
144 Style/TrailingBlankLines
120 Style/EmptyLineBetweenDefs
101 Style/IndentationWidth
82 Style/SpaceAroundBlockParameters
40 Style/EmptyLinesAroundMethodBody
29 Style/EmptyLinesAroundAccessModifier
1 Style/RescueEnsureAlignment
Diffstat (limited to 'spec/integration')
-rw-r--r-- | spec/integration/client/client_spec.rb | 7 | ||||
-rw-r--r-- | spec/integration/client/ipv6_spec.rb | 11 | ||||
-rw-r--r-- | spec/integration/knife/chef_fs_data_store_spec.rb | 8 | ||||
-rw-r--r-- | spec/integration/knife/cookbook_api_ipv6_spec.rb | 4 | ||||
-rw-r--r-- | spec/integration/knife/delete_spec.rb | 2 | ||||
-rw-r--r-- | spec/integration/knife/diff_spec.rb | 4 | ||||
-rw-r--r-- | spec/integration/knife/download_spec.rb | 8 | ||||
-rw-r--r-- | spec/integration/knife/raw_spec.rb | 4 | ||||
-rw-r--r-- | spec/integration/knife/redirection_spec.rb | 2 | ||||
-rw-r--r-- | spec/integration/knife/show_spec.rb | 2 | ||||
-rw-r--r-- | spec/integration/knife/upload_spec.rb | 19 | ||||
-rw-r--r-- | spec/integration/recipes/lwrp_inline_resources_spec.rb | 4 | ||||
-rw-r--r-- | spec/integration/recipes/provider_choice.rb | 1 | ||||
-rw-r--r-- | spec/integration/recipes/recipe_dsl_spec.rb | 31 | ||||
-rw-r--r-- | spec/integration/recipes/resource_action_spec.rb | 790 | ||||
-rw-r--r-- | spec/integration/recipes/resource_converge_if_changed_spec.rb | 1 | ||||
-rw-r--r-- | spec/integration/recipes/resource_load_spec.rb | 20 | ||||
-rw-r--r-- | spec/integration/solo/solo_spec.rb | 9 |
18 files changed, 481 insertions, 446 deletions
diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb index 24ce69ac03..bfc88659e0 100644 --- a/spec/integration/client/client_spec.rb +++ b/spec/integration/client/client_spec.rb @@ -3,17 +3,16 @@ require "chef/mixin/shell_out" require "tiny_server" require "tmpdir" - describe "chef-client" do def recipes_filename File.join(CHEF_SPEC_DATA, "recipes.tgz") end - def start_tiny_server(server_opts={}) + def start_tiny_server(server_opts = {}) @server = TinyServer::Manager.new(server_opts) @server.start - @api = TinyServer::API.instance + @api = TinyServer::API.instance @api.clear # # trivial endpoints @@ -48,7 +47,7 @@ describe "chef-client" do # cf. CHEF-4914 let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" } - let(:critical_env_vars) { %w{PATH RUBYOPT BUNDLE_GEMFILE GEM_PATH}.map {|o| "#{o}=#{ENV[o]}"} .join(" ") } + let(:critical_env_vars) { %w{PATH RUBYOPT BUNDLE_GEMFILE GEM_PATH}.map { |o| "#{o}=#{ENV[o]}" } .join(" ") } when_the_repository "has a cookbook with a no-op recipe" do before { file "cookbooks/x/recipes/default.rb", "" } diff --git a/spec/integration/client/ipv6_spec.rb b/spec/integration/client/ipv6_spec.rb index 45086611bc..68c58bb8ea 100644 --- a/spec/integration/client/ipv6_spec.rb +++ b/spec/integration/client/ipv6_spec.rb @@ -22,7 +22,7 @@ describe "chef-client" do include IntegrationSupport include Chef::Mixin::ShellOut - let(:chef_zero_opts) { {:host => "::1"} } + let(:chef_zero_opts) { { :host => "::1" } } let(:validation_pem) do <<-END_VALIDATION_PEM @@ -73,7 +73,6 @@ END_CLIENT_RB basic_config_file end - let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") } let(:chef_client_cmd) { %Q{ruby '#{chef_dir}/chef-client' --minimal-ohai -c "#{path_to('config/client.rb')}" -lwarn} } @@ -88,7 +87,7 @@ END_CLIENT_RB when_the_repository "has a cookbook with a no-op recipe" do before do - cookbook "noop", "1.0.0", { }, "recipes" => {"default.rb" => "#raise 'foo'"} + cookbook "noop", "1.0.0", {}, "recipes" => { "default.rb" => "#raise 'foo'" } file "config/client.rb", client_rb_content file "config/validator.pem", validation_pem end @@ -103,7 +102,7 @@ END_CLIENT_RB when_the_repository "has a cookbook that hits server APIs" do before do - recipe=<<-END_RECIPE + recipe = <<-END_RECIPE actual_item = data_bag_item("expect_bag", "expect_item") if actual_item.key?("expect_key") and actual_item["expect_key"] == "expect_value" Chef::Log.info "lookin good" @@ -115,9 +114,9 @@ END_CLIENT_RB END_RECIPE - data_bag("expect_bag", { "expect_item" => {"expect_key" => "expect_value"} }) + data_bag("expect_bag", { "expect_item" => { "expect_key" => "expect_value" } }) - cookbook "api-smoke-test", "1.0.0", { }, "recipes" => {"default.rb" => recipe} + cookbook "api-smoke-test", "1.0.0", {}, "recipes" => { "default.rb" => recipe } end before do diff --git a/spec/integration/knife/chef_fs_data_store_spec.rb b/spec/integration/knife/chef_fs_data_store_spec.rb index e9a2ea4824..02508b799d 100644 --- a/spec/integration/knife/chef_fs_data_store_spec.rb +++ b/spec/integration/knife/chef_fs_data_store_spec.rb @@ -179,7 +179,7 @@ EOM context "PUT /TYPE/NAME" do before do file "empty.json", {} - file "dummynode.json", { "name" => "x", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => {"foo" => "bar"}} + file "dummynode.json", { "name" => "x", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } file "rolestuff.json", '{"description":"hi there","name":"x"}' file "cookbooks_to_upload/x/metadata.rb", cookbook_x_100_metadata_rb end @@ -234,7 +234,7 @@ EOM context "POST /TYPE/NAME" do before do file "empty.json", { "name" => "z" } - file "dummynode.json", { "name" => "z", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => {"foo" => "bar"}} + file "dummynode.json", { "name" => "z", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } file "empty_x.json", { "name" => "x" } file "empty_id.json", { "id" => "z" } file "rolestuff.json", '{"description":"hi there","name":"x"}' @@ -479,7 +479,7 @@ EOM context "PUT /TYPE/NAME" do before do file "empty.json", {} - file "dummynode.json", { "name" => "x", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => {"foo" => "bar"}} + file "dummynode.json", { "name" => "x", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } file "rolestuff.json", '{"description":"hi there","name":"x"}' file "cookbooks_to_upload/x/metadata.rb", cookbook_x_100_metadata_rb end @@ -505,7 +505,7 @@ EOM context "POST /TYPE/NAME" do before do file "empty.json", { "name" => "z" } - file "dummynode.json", { "name" => "z", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => {"foo" => "bar"}} + file "dummynode.json", { "name" => "z", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } file "empty_x.json", { "name" => "x" } file "empty_id.json", { "id" => "z" } file "rolestuff.json", '{"description":"hi there","name":"x"}' diff --git a/spec/integration/knife/cookbook_api_ipv6_spec.rb b/spec/integration/knife/cookbook_api_ipv6_spec.rb index 3126c93a1c..0a4a6a6e94 100644 --- a/spec/integration/knife/cookbook_api_ipv6_spec.rb +++ b/spec/integration/knife/cookbook_api_ipv6_spec.rb @@ -23,7 +23,7 @@ describe "Knife cookbook API integration with IPv6", :workstation, :not_supporte include Chef::Mixin::ShellOut when_the_chef_server "is bound to IPv6" do - let(:chef_zero_opts) { {:host => "::1"} } + let(:chef_zero_opts) { { :host => "::1" } } let(:client_key) do <<-END_VALIDATION_PEM @@ -102,7 +102,7 @@ END_CLIENT_RB it "downloads the cookbook" do shell_out!("knife cookbook download apache2 #{knife_config_flag} -d #{cache_path}", :cwd => chef_dir) - expect(Dir["#{cache_path}/*"].map {|entry| File.basename(entry)}).to include("apache2-0.0.1") + expect(Dir["#{cache_path}/*"].map { |entry| File.basename(entry) }).to include("apache2-0.0.1") end end diff --git a/spec/integration/knife/delete_spec.rb b/spec/integration/knife/delete_spec.rb index 9f2accdbfa..d8cb8d950f 100644 --- a/spec/integration/knife/delete_spec.rb +++ b/spec/integration/knife/delete_spec.rb @@ -916,7 +916,7 @@ EOM when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => ""} + cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } end diff --git a/spec/integration/knife/diff_spec.rb b/spec/integration/knife/diff_spec.rb index 3cc2518915..b7d2f4d1c3 100644 --- a/spec/integration/knife/diff_spec.rb +++ b/spec/integration/knife/diff_spec.rb @@ -174,7 +174,7 @@ EOM when_the_chef_server "has a later version for the cookbook" do before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => ""} + cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "" } end @@ -470,7 +470,7 @@ EOM when_the_chef_server "has a later version for the cookbook" do before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => ""} + cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "" } end diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb index ec322ca01c..2c9f64b61a 100644 --- a/spec/integration/knife/download_spec.rb +++ b/spec/integration/knife/download_spec.rb @@ -489,7 +489,7 @@ EOM when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => ""} + cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } end @@ -986,7 +986,7 @@ EOM when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => ""} + cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } end @@ -1254,8 +1254,8 @@ EOM file "members.json", [ "bar" ] file "nodes/x.json", {} file "org.json", { "full_name" => "Something" } - file "policies/x-1.0.0.json", { } - file "policies/blah-1.0.0.json", { } + file "policies/x-1.0.0.json", {} + file "policies/blah-1.0.0.json", {} file "policy_groups/x.json", { "policies" => { "x" => { "revision_id" => "1.0.0" }, "blah" => { "revision_id" => "1.0.0" } } } file "roles/x.json", {} end diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb index 8d3499617c..9078bf09a1 100644 --- a/spec/integration/knife/raw_spec.rb +++ b/spec/integration/knife/raw_spec.rb @@ -186,7 +186,7 @@ EOM before :each do Chef::Config.chef_server_url = "http://localhost:9018" app = lambda do |env| - [200, {"Content-Type" => "application/json" }, ['{ "x": "y", "a": "b" }'] ] + [200, { "Content-Type" => "application/json" }, ['{ "x": "y", "a": "b" }'] ] end @raw_server, @raw_server_thread = start_app_server(app, 9018) end @@ -216,7 +216,7 @@ EOM before :each do Chef::Config.chef_server_url = "http://localhost:9018" app = lambda do |env| - [200, {"Content-Type" => "text" }, ['{ "x": "y", "a": "b" }'] ] + [200, { "Content-Type" => "text" }, ['{ "x": "y", "a": "b" }'] ] end @raw_server, @raw_server_thread = start_app_server(app, 9018) end diff --git a/spec/integration/knife/redirection_spec.rb b/spec/integration/knife/redirection_spec.rb index 9febfc0ce5..29c1ee6ffb 100644 --- a/spec/integration/knife/redirection_spec.rb +++ b/spec/integration/knife/redirection_spec.rb @@ -34,7 +34,7 @@ describe "redirection", :workstation do real_chef_server_url = Chef::Config.chef_server_url Chef::Config.chef_server_url = "http://localhost:9018" app = lambda do |env| - [302, {"Content-Type" => "text","Location" => "#{real_chef_server_url}#{env['PATH_INFO']}" }, ["302 found"] ] + [302, { "Content-Type" => "text", "Location" => "#{real_chef_server_url}#{env['PATH_INFO']}" }, ["302 found"] ] end @redirector_server, @redirector_server_thread = start_app_server(app, 9018) end diff --git a/spec/integration/knife/show_spec.rb b/spec/integration/knife/show_spec.rb index a1de48e121..ed4802fef9 100644 --- a/spec/integration/knife/show_spec.rb +++ b/spec/integration/knife/show_spec.rb @@ -129,7 +129,7 @@ EOM before do environment "x", { "default_attributes" => { "foo" => "bar" }, - "cookbook_versions" => { "blah" => "= 1.0.0"}, + "cookbook_versions" => { "blah" => "= 1.0.0" }, "override_attributes" => { "x" => "y" }, "description" => "woo", "name" => "x", diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb index 2ecbd4e64a..6f8dce5ae7 100644 --- a/spec/integration/knife/upload_spec.rb +++ b/spec/integration/knife/upload_spec.rb @@ -80,7 +80,7 @@ Deleted extra entry /roles/x.json (purge is on) Deleted extra entry /users/admin.json (purge is on) Deleted extra entry /users/x.json (purge is on) EOM - knife("diff --name-status /").should_succeed <<EOM + knife("diff --name-status /").should_succeed <<EOM D\t/environments/_default.json EOM end @@ -565,7 +565,7 @@ EOM when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => ""} + cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } end @@ -1129,7 +1129,7 @@ EOM when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => ""} + cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } end it "knife upload /cookbooks uploads the local version" do @@ -1248,7 +1248,6 @@ EOM end end # with versioned cookbooks - when_the_chef_server "has a user" do before do user "x", {} @@ -1296,8 +1295,8 @@ EOM file "members.json", [ "bar" ] file "org.json", { "full_name" => "wootles" } file "nodes/x.json", {} - file "policies/x-1.0.0.json", { } - file "policies/blah-1.0.0.json", { } + file "policies/x-1.0.0.json", {} + file "policies/blah-1.0.0.json", {} file "policy_groups/x.json", { "policies" => { "x" => { "revision_id" => "1.0.0" }, "blah" => { "revision_id" => "1.0.0" } } } file "roles/x.json", {} end @@ -1397,9 +1396,9 @@ EOM environment "x", { "description" => "foo" } group "x", { "groups" => [ "admin" ] } node "x", { "run_list" => [ "blah" ] } - policy "x", "1.0.0", { } - policy "x", "1.0.1", { } - policy "y", "1.0.0", { } + policy "x", "1.0.0", {} + policy "x", "1.0.1", {} + policy "y", "1.0.0", {} policy_group "x", { "policies" => { "x" => { "revision_id" => "1.0.1" }, @@ -1443,7 +1442,7 @@ EOM when_the_repository "has an org.json that changes full_name" do before do - file "org.json", { "full_name" => "Something Else"} + file "org.json", { "full_name" => "Something Else" } end it "knife upload / emits a warning for bar and adds foo and foobar" do diff --git a/spec/integration/recipes/lwrp_inline_resources_spec.rb b/spec/integration/recipes/lwrp_inline_resources_spec.rb index dc7e19a3cb..0fc2c338fd 100644 --- a/spec/integration/recipes/lwrp_inline_resources_spec.rb +++ b/spec/integration/recipes/lwrp_inline_resources_spec.rb @@ -82,8 +82,8 @@ describe "LWRPs with inline resources" do action :b end }.to have_updated("lwrp_inline_resources_test2[hi]", :b). - and have_updated("ruby_block[run a]", :run). - and have_updated("ruby_block[run b]", :run) + and have_updated("ruby_block[run a]", :run). + and have_updated("ruby_block[run b]", :run) expect(r.ran_b).to eq "ran b: ran_a value was \"ran a\"" end end diff --git a/spec/integration/recipes/provider_choice.rb b/spec/integration/recipes/provider_choice.rb index d08090bbe8..a9fc06038a 100644 --- a/spec/integration/recipes/provider_choice.rb +++ b/spec/integration/recipes/provider_choice.rb @@ -18,6 +18,7 @@ describe "Recipe DSL methods" do class Chef::Provider::ProviderThingy < Chef::Provider def load_current_resource end + def action_create Chef::Log.warn("hello from #{self.class.name}") end diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb index db4d158eec..f96be7ea91 100644 --- a/spec/integration/recipes/recipe_dsl_spec.rb +++ b/spec/integration/recipes/recipe_dsl_spec.rb @@ -30,6 +30,7 @@ describe "Recipe DSL methods" do class Provider < Chef::Provider def load_current_resource end + def action_create BaseThingy.created_name = new_resource.name BaseThingy.created_resource = new_resource.class @@ -89,6 +90,7 @@ describe "Recipe DSL methods" do class Chef::Provider::BackcompatThingy < Chef::Provider def load_current_resource end + def action_create BaseThingy.created_resource = new_resource.class BaseThingy.created_provider = self.class @@ -832,7 +834,9 @@ describe "Recipe DSL methods" do def self.name "B" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result.resource_name two_classes_one_dsl @@ -846,7 +850,9 @@ describe "Recipe DSL methods" do def self.name "A" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result.resource_name two_classes_one_dsl @@ -874,7 +880,9 @@ describe "Recipe DSL methods" do def self.name "Z" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result.resource_name two_classes_one_dsl @@ -1009,7 +1017,9 @@ describe "Recipe DSL methods" do def self.name "B" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result.provides two_classes_one_dsl @@ -1023,7 +1033,9 @@ describe "Recipe DSL methods" do def self.name "A" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result @@ -1060,7 +1072,9 @@ describe "Recipe DSL methods" do def self.name "Z" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result @@ -1132,7 +1146,9 @@ describe "Recipe DSL methods" do def self.name "Blarghle" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result.resource_name two_classes_one_dsl @@ -1170,6 +1186,7 @@ describe "Recipe DSL methods" do def self.called_provides @called_provides end + def to_s "MyResource" end @@ -1237,8 +1254,11 @@ describe "Recipe DSL methods" do def self.name "MyProvider" end + def self.to_s; name; end + def self.inspect; name.inspect; end + def self.called_provides @called_provides end @@ -1256,7 +1276,7 @@ describe "Recipe DSL methods" do context "with supports? returning true" do before do - provider_class.define_singleton_method(:supports?) { |resource,action| true } + provider_class.define_singleton_method(:supports?) { |resource, action| true } end it "my_resource runs the provider and does not emit a warning" do @@ -1274,8 +1294,11 @@ describe "Recipe DSL methods" do def self.name "MyProvider2" end + def self.to_s; name; end + def self.inspect; name.inspect; end + def self.called_provides @called_provides end @@ -1299,7 +1322,7 @@ describe "Recipe DSL methods" do context "with supports? returning false" do before do - provider_class.define_singleton_method(:supports?) { |resource,action| false } + provider_class.define_singleton_method(:supports?) { |resource, action| false } end # TODO no warning? ick @@ -1319,8 +1342,11 @@ describe "Recipe DSL methods" do def self.name "MyProvider2" end + def self.to_s; name; end + def self.inspect; name.inspect; end + def self.called_provides @called_provides end @@ -1475,6 +1501,7 @@ describe "Recipe DSL methods" do class Chef::Provider::LwResourceWithHwProviderTestCase < Chef::Provider def load_current_resource end + def action_create new_resource.created_provider = self.class end diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb index 5778c467c5..8f6f4b7f46 100644 --- a/spec/integration/recipes/resource_action_spec.rb +++ b/spec/integration/recipes/resource_action_spec.rb @@ -3,89 +3,89 @@ require "support/shared/integration/integration_helper" # Houses any classes we declare module ResourceActionSpec -describe "Resource.action" do - include IntegrationSupport + describe "Resource.action" do + include IntegrationSupport - shared_context "ActionJackson" do - it "the default action is the first declared action" do - converge <<-EOM, __FILE__, __LINE__+1 + shared_context "ActionJackson" do + it "the default action is the first declared action" do + converge <<-EOM, __FILE__, __LINE__ + 1 #{resource_dsl} "hi" do foo "foo!" end EOM - expect(ActionJackson.ran_action).to eq :access_recipe_dsl - expect(ActionJackson.succeeded).to eq true - end + expect(ActionJackson.ran_action).to eq :access_recipe_dsl + expect(ActionJackson.succeeded).to eq true + end - it "the action can access recipe DSL" do - converge <<-EOM, __FILE__, __LINE__+1 + it "the action can access recipe DSL" do + converge <<-EOM, __FILE__, __LINE__ + 1 #{resource_dsl} "hi" do foo "foo!" action :access_recipe_dsl end EOM - expect(ActionJackson.ran_action).to eq :access_recipe_dsl - expect(ActionJackson.succeeded).to eq true - end + expect(ActionJackson.ran_action).to eq :access_recipe_dsl + expect(ActionJackson.succeeded).to eq true + end - it "the action can access attributes" do - converge <<-EOM, __FILE__, __LINE__+1 + it "the action can access attributes" do + converge <<-EOM, __FILE__, __LINE__ + 1 #{resource_dsl} "hi" do foo "foo!" action :access_attribute end EOM - expect(ActionJackson.ran_action).to eq :access_attribute - expect(ActionJackson.succeeded).to eq "foo!" - end + expect(ActionJackson.ran_action).to eq :access_attribute + expect(ActionJackson.succeeded).to eq "foo!" + end - it "the action can access public methods" do - converge <<-EOM, __FILE__, __LINE__+1 + it "the action can access public methods" do + converge <<-EOM, __FILE__, __LINE__ + 1 #{resource_dsl} "hi" do foo "foo!" action :access_method end EOM - expect(ActionJackson.ran_action).to eq :access_method - expect(ActionJackson.succeeded).to eq "foo_public!" - end + expect(ActionJackson.ran_action).to eq :access_method + expect(ActionJackson.succeeded).to eq "foo_public!" + end - it "the action can access protected methods" do - converge <<-EOM, __FILE__, __LINE__+1 + it "the action can access protected methods" do + converge <<-EOM, __FILE__, __LINE__ + 1 #{resource_dsl} "hi" do foo "foo!" action :access_protected_method end EOM - expect(ActionJackson.ran_action).to eq :access_protected_method - expect(ActionJackson.succeeded).to eq "foo_protected!" - end + expect(ActionJackson.ran_action).to eq :access_protected_method + expect(ActionJackson.succeeded).to eq "foo_protected!" + end - it "the action cannot access private methods" do - expect { - converge(<<-EOM, __FILE__, __LINE__+1) + it "the action cannot access private methods" do + expect { + converge(<<-EOM, __FILE__, __LINE__ + 1) #{resource_dsl} "hi" do foo "foo!" action :access_private_method end EOM - }.to raise_error(NameError) - expect(ActionJackson.ran_action).to eq :access_private_method - end + }.to raise_error(NameError) + expect(ActionJackson.ran_action).to eq :access_private_method + end - it "the action cannot access resource instance variables" do - converge <<-EOM, __FILE__, __LINE__+1 + it "the action cannot access resource instance variables" do + converge <<-EOM, __FILE__, __LINE__ + 1 #{resource_dsl} "hi" do foo "foo!" action :access_instance_variable end EOM - expect(ActionJackson.ran_action).to eq :access_instance_variable - expect(ActionJackson.succeeded).to be_nil - end + expect(ActionJackson.ran_action).to eq :access_instance_variable + expect(ActionJackson.succeeded).to be_nil + end - it "the action does not compile until the prior resource has converged" do - converge <<-EOM, __FILE__, __LINE__+1 + it "the action does not compile until the prior resource has converged" do + converge <<-EOM, __FILE__, __LINE__ + 1 ruby_block "wow" do block do ResourceActionSpec::ActionJackson.ruby_block_converged = "ruby_block_converged!" @@ -97,12 +97,12 @@ describe "Resource.action" do action :access_class_method end EOM - expect(ActionJackson.ran_action).to eq :access_class_method - expect(ActionJackson.succeeded).to eq "ruby_block_converged!" - end + expect(ActionJackson.ran_action).to eq :access_class_method + expect(ActionJackson.succeeded).to eq "ruby_block_converged!" + end - it "the action's resources converge before the next resource converges" do - converge <<-EOM, __FILE__, __LINE__+1 + it "the action's resources converge before the next resource converges" do + converge <<-EOM, __FILE__, __LINE__ + 1 #{resource_dsl} "hi" do foo "foo!" action :access_attribute @@ -114,427 +114,407 @@ describe "Resource.action" do end end EOM - expect(ActionJackson.ran_action).to eq :access_attribute - expect(ActionJackson.succeeded).to eq "foo!" - expect(ActionJackson.ruby_block_converged).to eq "foo!" - end - end - - context "With resource 'action_jackson'" do - class ActionJackson < Chef::Resource - use_automatic_resource_name - def foo(value=nil) - @foo = value if value - @foo - end - def blarghle(value=nil) - @blarghle = value if value - @blarghle + expect(ActionJackson.ran_action).to eq :access_attribute + expect(ActionJackson.succeeded).to eq "foo!" + expect(ActionJackson.ruby_block_converged).to eq "foo!" end + end - class <<self - attr_accessor :ran_action - attr_accessor :succeeded - attr_accessor :ruby_block_converged - end + context "With resource 'action_jackson'" do + class ActionJackson < Chef::Resource + use_automatic_resource_name + def foo(value = nil) + @foo = value if value + @foo + end - public - def foo_public - "foo_public!" - end - protected - def foo_protected - "foo_protected!" - end - private - def foo_private - "foo_private!" - end + def blarghle(value = nil) + @blarghle = value if value + @blarghle + end - public - action :access_recipe_dsl do - ActionJackson.ran_action = :access_recipe_dsl - ruby_block "hi there" do - block do - ActionJackson.succeeded = true - end + class <<self + attr_accessor :ran_action + attr_accessor :succeeded + attr_accessor :ruby_block_converged end - end - action :access_attribute do - ActionJackson.ran_action = :access_attribute - ActionJackson.succeeded = foo - ActionJackson.succeeded += " #{blarghle}" if blarghle - ActionJackson.succeeded += " #{bar}" if respond_to?(:bar) - end - action :access_attribute2 do - ActionJackson.ran_action = :access_attribute2 - ActionJackson.succeeded = foo - ActionJackson.succeeded += " #{blarghle}" if blarghle - ActionJackson.succeeded += " #{bar}" if respond_to?(:bar) - end - action :access_method do - ActionJackson.ran_action = :access_method - ActionJackson.succeeded = foo_public - end - action :access_protected_method do - ActionJackson.ran_action = :access_protected_method - ActionJackson.succeeded = foo_protected - end - action :access_private_method do - ActionJackson.ran_action = :access_private_method - ActionJackson.succeeded = foo_private - end - action :access_instance_variable do - ActionJackson.ran_action = :access_instance_variable - ActionJackson.succeeded = @foo - end - action :access_class_method do - ActionJackson.ran_action = :access_class_method - ActionJackson.succeeded = ActionJackson.ruby_block_converged - end - end - before(:each) { - ActionJackson.ran_action = :error - ActionJackson.succeeded = :error - ActionJackson.ruby_block_converged = :error - } + public - it_behaves_like "ActionJackson" do - let(:resource_dsl) { :action_jackson } - end + def foo_public + "foo_public!" + end - it "Can retrieve ancestors of action class without crashing" do - converge { action_jackson "hi" } - expect { ActionJackson.action_class.ancestors.join(",") }.not_to raise_error - end + protected - context "And 'action_jackgrandson' inheriting from ActionJackson and changing nothing" do - before(:context) { - class ActionJackgrandson < ActionJackson - use_automatic_resource_name + def foo_protected + "foo_protected!" end - } - it_behaves_like "ActionJackson" do - let(:resource_dsl) { :action_jackgrandson } - end - end + private - context "And 'action_jackalope' inheriting from ActionJackson with an extra attribute, action and custom method" do - class ActionJackalope < ActionJackson - use_automatic_resource_name + def foo_private + "foo_private!" + end - def foo(value=nil) - @foo = "#{value}alope" if value - @foo + public + + action :access_recipe_dsl do + ActionJackson.ran_action = :access_recipe_dsl + ruby_block "hi there" do + block do + ActionJackson.succeeded = true + end + end end - def bar(value=nil) - @bar = "#{value}alope" if value - @bar + action :access_attribute do + ActionJackson.ran_action = :access_attribute + ActionJackson.succeeded = foo + ActionJackson.succeeded += " #{blarghle}" if blarghle + ActionJackson.succeeded += " #{bar}" if respond_to?(:bar) end - class <<self - attr_accessor :load_current_resource_ran - attr_accessor :jackalope_ran + action :access_attribute2 do + ActionJackson.ran_action = :access_attribute2 + ActionJackson.succeeded = foo + ActionJackson.succeeded += " #{blarghle}" if blarghle + ActionJackson.succeeded += " #{bar}" if respond_to?(:bar) end - action :access_jackalope do - ActionJackalope.jackalope_ran = :access_jackalope - ActionJackalope.succeeded = "#{foo} #{blarghle} #{bar}" + action :access_method do + ActionJackson.ran_action = :access_method + ActionJackson.succeeded = foo_public end - action :access_attribute do - super() - ActionJackalope.jackalope_ran = :access_attribute - ActionJackalope.succeeded = ActionJackson.succeeded + action :access_protected_method do + ActionJackson.ran_action = :access_protected_method + ActionJackson.succeeded = foo_protected + end + action :access_private_method do + ActionJackson.ran_action = :access_private_method + ActionJackson.succeeded = foo_private + end + action :access_instance_variable do + ActionJackson.ran_action = :access_instance_variable + ActionJackson.succeeded = @foo + end + action :access_class_method do + ActionJackson.ran_action = :access_class_method + ActionJackson.succeeded = ActionJackson.ruby_block_converged end end - before do - ActionJackalope.jackalope_ran = nil - ActionJackalope.load_current_resource_ran = nil + + before(:each) { + ActionJackson.ran_action = :error + ActionJackson.succeeded = :error + ActionJackson.ruby_block_converged = :error + } + + it_behaves_like "ActionJackson" do + let(:resource_dsl) { :action_jackson } end - context "action_jackson still behaves the same" do - it_behaves_like "ActionJackson" do - let(:resource_dsl) { :action_jackson } - end + it "Can retrieve ancestors of action class without crashing" do + converge { action_jackson "hi" } + expect { ActionJackson.action_class.ancestors.join(",") }.not_to raise_error end - it "the default action remains the same even though new actions were specified first" do - converge { - action_jackalope "hi" do - foo "foo!" - bar "bar!" + context "And 'action_jackgrandson' inheriting from ActionJackson and changing nothing" do + before(:context) { + class ActionJackgrandson < ActionJackson + use_automatic_resource_name end } - expect(ActionJackson.ran_action).to eq :access_recipe_dsl - expect(ActionJackson.succeeded).to eq true + + it_behaves_like "ActionJackson" do + let(:resource_dsl) { :action_jackgrandson } + end end - it "new actions run, and can access overridden, new, and overridden attributes" do - converge { - action_jackalope "hi" do - foo "foo!" - bar "bar!" - blarghle "blarghle!" - action :access_jackalope + context "And 'action_jackalope' inheriting from ActionJackson with an extra attribute, action and custom method" do + class ActionJackalope < ActionJackson + use_automatic_resource_name + + def foo(value = nil) + @foo = "#{value}alope" if value + @foo end - } - expect(ActionJackalope.jackalope_ran).to eq :access_jackalope - expect(ActionJackalope.succeeded).to eq "foo!alope blarghle! bar!alope" - end - it "overridden actions run, call super, and can access overridden, new, and overridden attributes" do - converge { - action_jackalope "hi" do - foo "foo!" - bar "bar!" - blarghle "blarghle!" - action :access_attribute + def bar(value = nil) + @bar = "#{value}alope" if value + @bar end - } - expect(ActionJackson.ran_action).to eq :access_attribute - expect(ActionJackson.succeeded).to eq "foo!alope blarghle! bar!alope" - expect(ActionJackalope.jackalope_ran).to eq :access_attribute - expect(ActionJackalope.succeeded).to eq "foo!alope blarghle! bar!alope" - end + class <<self + attr_accessor :load_current_resource_ran + attr_accessor :jackalope_ran + end + action :access_jackalope do + ActionJackalope.jackalope_ran = :access_jackalope + ActionJackalope.succeeded = "#{foo} #{blarghle} #{bar}" + end + action :access_attribute do + super() + ActionJackalope.jackalope_ran = :access_attribute + ActionJackalope.succeeded = ActionJackson.succeeded + end + end + before do + ActionJackalope.jackalope_ran = nil + ActionJackalope.load_current_resource_ran = nil + end - it "non-overridden actions run and can access overridden and non-overridden variables (but not necessarily new ones)" do - converge { - action_jackalope "hi" do - foo "foo!" - bar "bar!" - blarghle "blarghle!" - action :access_attribute2 + context "action_jackson still behaves the same" do + it_behaves_like "ActionJackson" do + let(:resource_dsl) { :action_jackson } end - } - expect(ActionJackson.ran_action).to eq :access_attribute2 - expect(ActionJackson.succeeded).to eq("foo!alope blarghle! bar!alope").or(eq("foo!alope blarghle!")) + end + + it "the default action remains the same even though new actions were specified first" do + converge { + action_jackalope "hi" do + foo "foo!" + bar "bar!" + end + } + expect(ActionJackson.ran_action).to eq :access_recipe_dsl + expect(ActionJackson.succeeded).to eq true + end + + it "new actions run, and can access overridden, new, and overridden attributes" do + converge { + action_jackalope "hi" do + foo "foo!" + bar "bar!" + blarghle "blarghle!" + action :access_jackalope + end + } + expect(ActionJackalope.jackalope_ran).to eq :access_jackalope + expect(ActionJackalope.succeeded).to eq "foo!alope blarghle! bar!alope" + end + + it "overridden actions run, call super, and can access overridden, new, and overridden attributes" do + converge { + action_jackalope "hi" do + foo "foo!" + bar "bar!" + blarghle "blarghle!" + action :access_attribute + end + } + expect(ActionJackson.ran_action).to eq :access_attribute + expect(ActionJackson.succeeded).to eq "foo!alope blarghle! bar!alope" + expect(ActionJackalope.jackalope_ran).to eq :access_attribute + expect(ActionJackalope.succeeded).to eq "foo!alope blarghle! bar!alope" + end + + it "non-overridden actions run and can access overridden and non-overridden variables (but not necessarily new ones)" do + converge { + action_jackalope "hi" do + foo "foo!" + bar "bar!" + blarghle "blarghle!" + action :access_attribute2 + end + } + expect(ActionJackson.ran_action).to eq :access_attribute2 + expect(ActionJackson.succeeded).to eq("foo!alope blarghle! bar!alope").or(eq("foo!alope blarghle!")) + end end end - end - context "With a resource with no actions" do - class NoActionJackson < Chef::Resource - use_automatic_resource_name + context "With a resource with no actions" do + class NoActionJackson < Chef::Resource + use_automatic_resource_name - def foo(value=nil) - @foo = value if value - @foo - end + def foo(value = nil) + @foo = value if value + @foo + end - class <<self - attr_accessor :action_was + class <<self + attr_accessor :action_was + end end - end - it "the default action is :nothing" do - converge { - no_action_jackson "hi" do - foo "foo!" - NoActionJackson.action_was = action - end - } - expect(NoActionJackson.action_was).to eq [:nothing] + it "the default action is :nothing" do + converge { + no_action_jackson "hi" do + foo "foo!" + NoActionJackson.action_was = action + end + } + expect(NoActionJackson.action_was).to eq [:nothing] + end end - end - context "With a resource with action a-b-c d" do - class WeirdActionJackson < Chef::Resource - use_automatic_resource_name + context "With a resource with action a-b-c d" do + class WeirdActionJackson < Chef::Resource + use_automatic_resource_name - class <<self - attr_accessor :action_was - end + class <<self + attr_accessor :action_was + end - action "a-b-c d" do - WeirdActionJackson.action_was = action + action "a-b-c d" do + WeirdActionJackson.action_was = action + end end - end - - it "Running the action works" do - expect_recipe { - weird_action_jackson "hi" - }.to be_up_to_date - expect(WeirdActionJackson.action_was).to eq :"a-b-c d" - end - end - context "With a resource with property x" do - class ResourceActionSpecWithX < Chef::Resource - resource_name :resource_action_spec_with_x - property :x, default: 20 - action :set do - # Access x during converge to ensure that we emit no warnings there - x + it "Running the action works" do + expect_recipe { + weird_action_jackson "hi" + }.to be_up_to_date + expect(WeirdActionJackson.action_was).to eq :"a-b-c d" end end - context "And another resource with a property x and an action that sets property x to its value" do - class ResourceActionSpecAlsoWithX < Chef::Resource - resource_name :resource_action_spec_also_with_x - property :x - action :set_x_to_x do - resource_action_spec_with_x "hi" do - x x - end - end - def self.x_warning_line - __LINE__-4 - end - action :set_x_to_x_in_non_initializer do - r = resource_action_spec_with_x "hi" do - x 10 - end - x_times_2 = r.x*2 - end - action :set_x_to_10 do - resource_action_spec_with_x "hi" do - x 10 - end + context "With a resource with property x" do + class ResourceActionSpecWithX < Chef::Resource + resource_name :resource_action_spec_with_x + property :x, default: 20 + action :set do + # Access x during converge to ensure that we emit no warnings there + x end end - attr_reader :x_warning_line - - it "Using the enclosing resource to set x to x emits a warning that you're using the wrong x" do - recipe = converge { - resource_action_spec_also_with_x "hi" do - x 1 - action :set_x_to_x + context "And another resource with a property x and an action that sets property x to its value" do + class ResourceActionSpecAlsoWithX < Chef::Resource + resource_name :resource_action_spec_also_with_x + property :x + action :set_x_to_x do + resource_action_spec_with_x "hi" do + x x + end end - } - warnings = recipe.logs.lines.select { |l| l =~ /warn/i } - expect(warnings.size).to eq 1 - expect(warnings[0]).to match(/property x is declared in both resource_action_spec_with_x\[hi\] and resource_action_spec_also_with_x\[hi\] action :set_x_to_x. Use new_resource.x instead. At #{__FILE__}:#{ResourceActionSpecAlsoWithX.x_warning_line}/) - end - - it "Using the enclosing resource to set x to x outside the initializer emits no warning" do - expect_recipe { - resource_action_spec_also_with_x "hi" do - x 1 - action :set_x_to_x_in_non_initializer + def self.x_warning_line + __LINE__ - 4 end - }.to emit_no_warnings_or_errors - end - - it "Using the enclosing resource to set x to 10 emits no warning" do - expect_recipe { - resource_action_spec_also_with_x "hi" do - x 1 - action :set_x_to_10 + action :set_x_to_x_in_non_initializer do + r = resource_action_spec_with_x "hi" do + x 10 + end + x_times_2 = r.x * 2 end - }.to emit_no_warnings_or_errors - end - - it "Using the enclosing resource to set x to 10 emits no warning" do - expect_recipe { - r = resource_action_spec_also_with_x "hi" - r.x 1 - r.action :set_x_to_10 - }.to emit_no_warnings_or_errors - end - end + action :set_x_to_10 do + resource_action_spec_with_x "hi" do + x 10 + end + end + end - end + attr_reader :x_warning_line - context "With a resource with a set_or_return property named group (same name as a resource)" do - class ResourceActionSpecWithGroupAction < Chef::Resource - resource_name :resource_action_spec_set_group_to_nil - action :set_group_to_nil do - # Access x during converge to ensure that we emit no warnings there - resource_action_spec_with_group "hi" do - group nil - action :nothing + it "Using the enclosing resource to set x to x emits a warning that you're using the wrong x" do + recipe = converge { + resource_action_spec_also_with_x "hi" do + x 1 + action :set_x_to_x + end + } + warnings = recipe.logs.lines.select { |l| l =~ /warn/i } + expect(warnings.size).to eq 1 + expect(warnings[0]).to match(/property x is declared in both resource_action_spec_with_x\[hi\] and resource_action_spec_also_with_x\[hi\] action :set_x_to_x. Use new_resource.x instead. At #{__FILE__}:#{ResourceActionSpecAlsoWithX.x_warning_line}/) end - end - end - class ResourceActionSpecWithGroup < Chef::Resource - resource_name :resource_action_spec_with_group - def group(value=nil) - set_or_return(:group, value, {}) - end - end + it "Using the enclosing resource to set x to x outside the initializer emits no warning" do + expect_recipe { + resource_action_spec_also_with_x "hi" do + x 1 + action :set_x_to_x_in_non_initializer + end + }.to emit_no_warnings_or_errors + end - it "Setting group to nil in an action does not emit a warning about it being defined in two places" do - expect_recipe { - resource_action_spec_set_group_to_nil "hi" do - action :set_group_to_nil + it "Using the enclosing resource to set x to 10 emits no warning" do + expect_recipe { + resource_action_spec_also_with_x "hi" do + x 1 + action :set_x_to_10 + end + }.to emit_no_warnings_or_errors end - }.to emit_no_warnings_or_errors - end - end - context "When a resource has a property with the same name as another resource" do - class HasPropertyNamedTemplate < Chef::Resource - use_automatic_resource_name - property :template - action :create do - template "x" do - "blah" + it "Using the enclosing resource to set x to 10 emits no warning" do + expect_recipe { + r = resource_action_spec_also_with_x "hi" + r.x 1 + r.action :set_x_to_10 + }.to emit_no_warnings_or_errors end end - end - it "Raises an error when attempting to use a template in the action" do - expect_converge { - has_property_named_template "hi" - }.to raise_error(/Property template of has_property_named_template\[hi\] cannot be passed a block! If you meant to create a resource named template instead, you'll need to first rename the property./) end - end - context "When a resource declares methods in action_class and declare_action_class" do - class DeclaresActionClassMethods < Chef::Resource - use_automatic_resource_name - property :x - 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 + context "With a resource with a set_or_return property named group (same name as a resource)" do + class ResourceActionSpecWithGroupAction < Chef::Resource + resource_name :resource_action_spec_set_group_to_nil + action :set_group_to_nil do + # Access x during converge to ensure that we emit no warnings there + resource_action_spec_with_group "hi" do + group nil + action :nothing + end end end - action_class do - def c - 3 + + class ResourceActionSpecWithGroup < Chef::Resource + resource_name :resource_action_spec_with_group + def group(value = nil) + set_or_return(:group, value, {}) end end - declare_action_class do - def d - 4 - end + + it "Setting group to nil in an action does not emit a warning about it being defined in two places" do + expect_recipe { + resource_action_spec_set_group_to_nil "hi" do + action :set_group_to_nil + end + }.to emit_no_warnings_or_errors 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 + context "When a resource has a property with the same name as another resource" do + class HasPropertyNamedTemplate < Chef::Resource + use_automatic_resource_name + property :template + action :create do + template "x" do + "blah" + end + end + end - it "the methods are available to the action" do - r = nil - expect_recipe { - r = declares_action_class_methods "hi" - }.to emit_no_warnings_or_errors - expect(r.x).to eq(10) + it "Raises an error when attempting to use a template in the action" do + expect_converge { + has_property_named_template "hi" + }.to raise_error(/Property template of has_property_named_template\[hi\] cannot be passed a block! If you meant to create a resource named template instead, you'll need to first rename the property./) + end end - context "And a subclass also creates a method" do - class DeclaresActionClassMethodsToo < DeclaresActionClassMethods + context "When a resource declares methods in action_class and declare_action_class" do + class DeclaresActionClassMethods < Chef::Resource use_automatic_resource_name + property :x action :create do - new_resource.x a+b+c+d+e + new_resource.x = a + b + c + d end action_class do - def e - 5 + 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 @@ -544,18 +524,46 @@ describe "Resource.action" do 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" + r = declares_action_class_methods "hi" }.to emit_no_warnings_or_errors - expect(r.x).to eq(15) + 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 -end end diff --git a/spec/integration/recipes/resource_converge_if_changed_spec.rb b/spec/integration/recipes/resource_converge_if_changed_spec.rb index 2bcccd9831..f1ea79daf9 100644 --- a/spec/integration/recipes/resource_converge_if_changed_spec.rb +++ b/spec/integration/recipes/resource_converge_if_changed_spec.rb @@ -22,6 +22,7 @@ describe "Resource::ActionClass#converge_if_changed" do let(:resource_class) { result = Class.new(Chef::Resource) do def self.to_s; resource_name; end + def self.inspect; resource_name.inspect; end property :identity1, identity: true, default: "default_identity1" property :control1, desired_state: false, default: "default_control1" diff --git a/spec/integration/recipes/resource_load_spec.rb b/spec/integration/recipes/resource_load_spec.rb index 66a36b1431..b48eb2daa5 100644 --- a/spec/integration/recipes/resource_load_spec.rb +++ b/spec/integration/recipes/resource_load_spec.rb @@ -21,11 +21,13 @@ describe "Resource.load_current_value" do let(:resource_class) { result = Class.new(Chef::Resource) do def self.to_s; resource_name; end + def self.inspect; resource_name.inspect; end property :x, default: lazy { "default #{Namer.incrementing_value}" } def self.created_x=(value) @created = value end + def self.created_x @created end @@ -43,9 +45,9 @@ describe "Resource.load_current_value" do context "with a resource with load_current_value" do before :each do resource_class.load_current_value do - x "loaded #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name,p| name }. - select { |name,p| p.is_set?(self) }. - map { |name,p| "#{name}=#{p.get(self)}" }. + x "loaded #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }. + select { |name, p| p.is_set?(self) }. + map { |name, p| "#{name}=#{p.get(self)}" }. join(", ") })" end end @@ -170,9 +172,9 @@ describe "Resource.load_current_value" do context "And a child resource class with load_current_value" do before { subresource_class.load_current_value do - y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name,p| name }. - select { |name,p| p.is_set?(self) }. - map { |name,p| "#{name}=#{p.get(self)}" }. + y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }. + select { |name, p| p.is_set?(self) }. + map { |name, p| "#{name}=#{p.get(self)}" }. join(", ") })" end } @@ -188,9 +190,9 @@ describe "Resource.load_current_value" do before { subresource_class.load_current_value do super() - y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name,p| name }. - select { |name,p| p.is_set?(self) }. - map { |name,p| "#{name}=#{p.get(self)}" }. + y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }. + select { |name, p| p.is_set?(self) }. + map { |name, p| "#{name}=#{p.get(self)}" }. join(", ") })" end } diff --git a/spec/integration/solo/solo_spec.rb b/spec/integration/solo/solo_spec.rb index 4849cb4d40..567f1a2c6f 100644 --- a/spec/integration/solo/solo_spec.rb +++ b/spec/integration/solo/solo_spec.rb @@ -39,7 +39,7 @@ cookbook_path "#{path_to('cookbooks')}" file_cache_path "#{path_to('config/cache')}" EOM - file "config/node.json",<<-E + file "config/node.json", <<-E {"run_list":["x::default"]} E @@ -104,7 +104,6 @@ EOM end end - when_the_repository "has a cookbook with a recipe with sleep" do before do directory "logs" @@ -152,12 +151,12 @@ EOM run_log = File.read(path_to("logs/runs.log")) # both of the runs should succeed - expect(run_log.lines.reject {|l| !l.include? "INFO: Chef Run complete in"}.length).to eq(2) + expect(run_log.lines.reject { |l| !l.include? "INFO: Chef Run complete in" }.length).to eq(2) # second run should have a message which indicates it's waiting for the first run - pid_lines = run_log.lines.reject {|l| !l.include? "Chef-client pid:"} + pid_lines = run_log.lines.reject { |l| !l.include? "Chef-client pid:" } expect(pid_lines.length).to eq(2) - pids = pid_lines.map {|l| l.split(" ").last} + pids = pid_lines.map { |l| l.split(" ").last } expect(run_log).to include("Chef client #{pids[0]} is running, will wait for it to finish and then run.") # second run should start after first run ends |