diff options
author | John Keiser <john@johnkeiser.com> | 2015-05-07 14:55:28 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-05-13 13:43:15 -0700 |
commit | 3f04e9ea39d7ca332de9349d423db30863fc7dfa (patch) | |
tree | f7da7453452b329e5292996c9541a816e4724e0c /spec | |
parent | 27c57238f1f2fddc7d03dad818a6b7ee78cbff96 (diff) | |
download | chef-3f04e9ea39d7ca332de9349d423db30863fc7dfa.tar.gz |
Convert "override LWRP" spec to one explicit check, be absolutely
sure it didn't load by creating a global module inside the LWRP
and checking it outside
Diffstat (limited to 'spec')
-rw-r--r-- | spec/data/lwrp_override/resources/foo.rb | 5 | ||||
-rw-r--r-- | spec/unit/lwrp_spec.rb | 45 |
2 files changed, 38 insertions, 12 deletions
diff --git a/spec/data/lwrp_override/resources/foo.rb b/spec/data/lwrp_override/resources/foo.rb index 14decb9634..2fc13d32fd 100644 --- a/spec/data/lwrp_override/resources/foo.rb +++ b/spec/data/lwrp_override/resources/foo.rb @@ -3,3 +3,8 @@ actions :never_execute attribute :ever, :kind_of => String + +class ::Chef + def method_created_by_override_lwrp_foo + end +end diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index 245074f0ab..07b2c9d88c 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -17,6 +17,8 @@ # require 'spec_helper' +require 'tmpdir' +require 'fileutils' module LwrpConstScopingConflict end @@ -25,6 +27,7 @@ describe "LWRP" do before do @original_VERBOSE = $VERBOSE $VERBOSE = nil + Chef::Resource::LWRPBase.class_eval { @loaded_lwrps = {} } end after do @@ -69,9 +72,6 @@ describe "LWRP" do Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file| expect(Chef::Log).to receive(:info).with(/Skipping/) - expect(Chef::Log).to receive(:debug).with(/enabled on node/) - expect(Chef::Log).to receive(:debug).with(/survived replacement/) - expect(Chef::Log).to receive(:debug).with(/anymore/) Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil) end end @@ -83,7 +83,6 @@ describe "LWRP" do Dir[File.expand_path( "lwrp/providers/*", CHEF_SPEC_DATA)].each do |file| expect(Chef::Log).to receive(:info).with(/Skipping/) - expect(Chef::Log).to receive(:debug).with(/anymore/) Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil) end end @@ -110,16 +109,42 @@ describe "LWRP" do end + context "When an LWRP resource lwrp_foo is loaded" do + before do + @tmpdir = Dir.mktmpdir("lwrp_test") + @lwrp_path = File.join(@tmpdir, "foo.rb") + content = IO.read(File.expand_path("../../data/lwrp/resources/foo.rb", __FILE__)) + IO.write(@lwrp_path, content) + Chef::Resource::LWRPBase.build_from_file("lwrp", @lwrp_path, nil) + @original_resource = Chef::Resource.resource_for_node(:lwrp_foo, Chef::Node.new) + end + + after do + FileUtils.remove_entry @tmpdir + end + + context "And the LWRP is asked to load again, this time with different code" do + before do + content = IO.read(File.expand_path("../../data/lwrp_override/resources/foo.rb", __FILE__)) + IO.write(@lwrp_path, content) + Chef::Resource::LWRPBase.build_from_file("lwrp", @lwrp_path, nil) + end + + it "Should load the old content, and not the new" do + resource = Chef::Resource.resource_for_node(:lwrp_foo, Chef::Node.new) + expect(resource).to eq @original_resource + expect(resource.default_action).to eq :pass_buck + expect(Chef.method_defined?(:method_created_by_override_lwrp_foo)).to be_falsey + end + end + end + describe "Lightweight Chef::Resource" do before do Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "resources", "*"))].each do |file| Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil) end - - Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "resources", "*"))].each do |file| - Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil) - end end it "should load the resource into a properly-named class and emit a warning about deprecation when accessing it" do @@ -299,10 +324,6 @@ describe "LWRP" do Chef::Resource::LWRPBase.build_from_file("lwrp", file, @run_context) end - Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "resources", "*"))].each do |file| - Chef::Resource::LWRPBase.build_from_file("lwrp", file, @run_context) - end - Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "providers", "*"))].each do |file| Chef::Provider::LWRPBase.build_from_file("lwrp", file, @run_context) end |