summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-06-30 13:46:12 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-06-30 13:46:12 -0700
commitc01d3934fb914ddbcbdff2de337d0c697785607b (patch)
treed0b7bde9ed738d928449651a2142164d3b9c7af3
parentaed2d5eabd33a6f36df82da62b97e478596b88ab (diff)
downloadchef-jdm/simplify-lwrp1.tar.gz
Fix up specsjdm/simplify-lwrp1
Loading the lwrp multiple times causes problems when comparing classes due to the their dynamic nature. It worked fine when we were overriding the things that checked. I've left the tests mostly as is, other than the fact that the test lwrp is loaded only once. The tests should still hold true, even with the new implementation.
-rw-r--r--spec/unit/lwrp_spec.rb274
1 files changed, 138 insertions, 136 deletions
diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb
index 7e2ed998b8..545524eb10 100644
--- a/spec/unit/lwrp_spec.rb
+++ b/spec/unit/lwrp_spec.rb
@@ -177,20 +177,6 @@ describe "LWRP" do
end
end
- it "allows monkey patching of the lwrp through Chef::Resource" do
- monkey = Module.new do
- def issue_3607
- end
- end
- allow(Chef::Config).to receive(:[]).with(:treat_deprecation_warnings_as_errors).and_return(false)
- Chef::Resource::LwrpFoo.send(:include, monkey)
- expect { get_lwrp(:lwrp_foo).new("blah").issue_3607 }.not_to raise_error
- end
-
- it "should load the resource into a properly-named class and emit a warning when it is initialized" do
- expect { Chef::Resource::LwrpFoo.new('hi') }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
- end
-
it "should be resolvable with Chef::ResourceResolver.resolve(:lwrp_foo)" do
expect(Chef::ResourceResolver.resolve(:lwrp_foo, node: Chef::Node.new)).to eq(get_lwrp(:lwrp_foo))
end
@@ -238,127 +224,6 @@ describe "LWRP" do
expect(cls.node[:penguin_name]).to eql("jackass")
end
- context "resource class created" do
- before do
- @old_treat_deprecation_warnings_as_errors = Chef::Config[:treat_deprecation_warnings_as_errors]
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- end
- after do
- Chef::Config[:treat_deprecation_warnings_as_errors] = @old_treat_deprecation_warnings_as_errors
- end
-
- it "should load the resource into a properly-named class" do
- expect(Chef::Resource::LwrpFoo).to be_kind_of(Class)
- expect(Chef::Resource::LwrpFoo <= Chef::Resource::LWRPBase).to be_truthy
- end
-
- it "get_lwrp(:lwrp_foo).new is a Chef::Resource::LwrpFoo" do
- lwrp = get_lwrp(:lwrp_foo).new('hi')
- expect(lwrp.kind_of?(Chef::Resource::LwrpFoo)).to be_truthy
- expect(lwrp.is_a?(Chef::Resource::LwrpFoo)).to be_truthy
- expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
- expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
- end
-
- it "Chef::Resource::LwrpFoo.new is a get_lwrp(:lwrp_foo)" do
- lwrp = Chef::Resource::LwrpFoo.new('hi')
- expect(lwrp.kind_of?(get_lwrp(:lwrp_foo))).to be_truthy
- expect(lwrp.is_a?(get_lwrp(:lwrp_foo))).to be_truthy
- expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
- expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
- end
-
- it "works even if LwrpFoo exists in the top level" do
- module ::LwrpFoo
- end
- expect(Chef::Resource::LwrpFoo).not_to eq(::LwrpFoo)
- end
-
- context "with a subclass of get_lwrp(:lwrp_foo)" do
- let(:subclass) do
- Class.new(get_lwrp(:lwrp_foo))
- end
-
- it "subclass.new is a subclass" do
- lwrp = subclass.new('hi')
- expect(lwrp.kind_of?(subclass)).to be_truthy
- expect(lwrp.is_a?(subclass)).to be_truthy
- expect(subclass === lwrp).to be_truthy
- expect(lwrp.class === subclass)
- end
- it "subclass.new is a Chef::Resource::LwrpFoo" do
- lwrp = subclass.new('hi')
- expect(lwrp.kind_of?(Chef::Resource::LwrpFoo)).to be_truthy
- expect(lwrp.is_a?(Chef::Resource::LwrpFoo)).to be_truthy
- expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
- expect(lwrp.class === Chef::Resource::LwrpFoo)
- end
- it "subclass.new is a get_lwrp(:lwrp_foo)" do
- lwrp = subclass.new('hi')
- expect(lwrp.kind_of?(get_lwrp(:lwrp_foo))).to be_truthy
- expect(lwrp.is_a?(get_lwrp(:lwrp_foo))).to be_truthy
- expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
- expect(lwrp.class === get_lwrp(:lwrp_foo))
- end
- it "Chef::Resource::LwrpFoo.new is *not* a subclass" do
- lwrp = Chef::Resource::LwrpFoo.new('hi')
- expect(lwrp.kind_of?(subclass)).to be_falsey
- expect(lwrp.is_a?(subclass)).to be_falsey
- expect(subclass === lwrp.class).to be_falsey
- expect(subclass === Chef::Resource::LwrpFoo).to be_falsey
- end
- it "get_lwrp(:lwrp_foo).new is *not* a subclass" do
- lwrp = get_lwrp(:lwrp_foo).new('hi')
- expect(lwrp.kind_of?(subclass)).to be_falsey
- expect(lwrp.is_a?(subclass)).to be_falsey
- expect(subclass === lwrp.class).to be_falsey
- expect(subclass === get_lwrp(:lwrp_foo)).to be_falsey
- end
- end
-
- context "with a subclass of Chef::Resource::LwrpFoo" do
- let(:subclass) do
- Class.new(Chef::Resource::LwrpFoo)
- end
-
- it "subclass.new is a subclass" do
- lwrp = subclass.new('hi')
- expect(lwrp.kind_of?(subclass)).to be_truthy
- expect(lwrp.is_a?(subclass)).to be_truthy
- expect(subclass === lwrp).to be_truthy
- expect(lwrp.class === subclass)
- end
- it "subclass.new is a Chef::Resource::LwrpFoo" do
- lwrp = subclass.new('hi')
- expect(lwrp.kind_of?(Chef::Resource::LwrpFoo)).to be_truthy
- expect(lwrp.is_a?(Chef::Resource::LwrpFoo)).to be_truthy
- expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
- expect(lwrp.class === Chef::Resource::LwrpFoo)
- end
- it "subclass.new is a get_lwrp(:lwrp_foo)" do
- lwrp = subclass.new('hi')
- expect(lwrp.kind_of?(get_lwrp(:lwrp_foo))).to be_truthy
- expect(lwrp.is_a?(get_lwrp(:lwrp_foo))).to be_truthy
- expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
- expect(lwrp.class === get_lwrp(:lwrp_foo))
- end
- it "Chef::Resource::LwrpFoo.new is *not* a subclass" do
- lwrp = Chef::Resource::LwrpFoo.new('hi')
- expect(lwrp.kind_of?(subclass)).to be_falsey
- expect(lwrp.is_a?(subclass)).to be_falsey
- expect(subclass === lwrp.class).to be_falsey
- expect(subclass === Chef::Resource::LwrpFoo).to be_falsey
- end
- it "get_lwrp(:lwrp_foo).new is *not* a subclass" do
- lwrp = get_lwrp(:lwrp_foo).new('hi')
- expect(lwrp.kind_of?(subclass)).to be_falsey
- expect(lwrp.is_a?(subclass)).to be_falsey
- expect(subclass === lwrp.class).to be_falsey
- expect(subclass === get_lwrp(:lwrp_foo)).to be_falsey
- end
- end
- end
-
context "resource_name" do
let(:klass) { Class.new(Chef::Resource::LWRPBase) }
@@ -714,7 +579,144 @@ describe "LWRP" do
end
end
-
end
+ context "resource class created" do
+ before(:context) do
+ @tmpdir = Dir.mktmpdir("lwrp_test")
+ resource_path = File.join(@tmpdir, "once.rb")
+ IO.write(resource_path, "default_action :create")
+
+ @old_treat_deprecation_warnings_as_errors = Chef::Config[:treat_deprecation_warnings_as_errors]
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ Chef::Resource::LWRPBase.build_from_file("lwrp", resource_path, nil)
+ end
+
+ after(:context) do
+ FileUtils.remove_entry @tmpdir
+ Chef::Config[:treat_deprecation_warnings_as_errors] = @old_treat_deprecation_warnings_as_errors
+ end
+
+ it "should load the resource into a properly-named class" do
+ expect(Chef::Resource::LwrpOnce).to be_kind_of(Class)
+ expect(Chef::Resource::LwrpOnce <= Chef::Resource::LWRPBase).to be_truthy
+ end
+
+ it "get_lwrp(:lwrp_once).new is a Chef::Resource::LwrpOnce" do
+ lwrp = get_lwrp(:lwrp_once).new('hi')
+ expect(lwrp.kind_of?(Chef::Resource::LwrpOnce)).to be_truthy
+ expect(lwrp.is_a?(Chef::Resource::LwrpOnce)).to be_truthy
+ expect(get_lwrp(:lwrp_once) === lwrp).to be_truthy
+ expect(Chef::Resource::LwrpOnce === lwrp).to be_truthy
+ end
+
+ it "Chef::Resource::LwrpOnce.new is a get_lwrp(:lwrp_once)" do
+ lwrp = Chef::Resource::LwrpOnce.new('hi')
+ expect(lwrp.kind_of?(get_lwrp(:lwrp_once))).to be_truthy
+ expect(lwrp.is_a?(get_lwrp(:lwrp_once))).to be_truthy
+ expect(get_lwrp(:lwrp_once) === lwrp).to be_truthy
+ expect(Chef::Resource::LwrpOnce === lwrp).to be_truthy
+ end
+
+ it "works even if LwrpOnce exists in the top level" do
+ module ::LwrpOnce
+ end
+ expect(Chef::Resource::LwrpOnce).not_to eq(::LwrpOnce)
+ end
+
+ it "allows monkey patching of the lwrp through Chef::Resource" do
+ monkey = Module.new do
+ def issue_3607
+ end
+ end
+ Chef::Resource::LwrpOnce.send(:include, monkey)
+ expect { get_lwrp(:lwrp_once).new("blah").issue_3607 }.not_to raise_error
+ end
+
+ context "with a subclass of get_lwrp(:lwrp_once)" do
+ let(:subclass) do
+ Class.new(get_lwrp(:lwrp_once))
+ end
+
+ it "subclass.new is a subclass" do
+ lwrp = subclass.new('hi')
+ expect(lwrp.kind_of?(subclass)).to be_truthy
+ expect(lwrp.is_a?(subclass)).to be_truthy
+ expect(subclass === lwrp).to be_truthy
+ expect(lwrp.class === subclass)
+ end
+ it "subclass.new is a Chef::Resource::LwrpOnce" do
+ lwrp = subclass.new('hi')
+ expect(lwrp.kind_of?(Chef::Resource::LwrpOnce)).to be_truthy
+ expect(lwrp.is_a?(Chef::Resource::LwrpOnce)).to be_truthy
+ expect(Chef::Resource::LwrpOnce === lwrp).to be_truthy
+ expect(lwrp.class === Chef::Resource::LwrpOnce)
+ end
+ it "subclass.new is a get_lwrp(:lwrp_once)" do
+ lwrp = subclass.new('hi')
+ expect(lwrp.kind_of?(get_lwrp(:lwrp_once))).to be_truthy
+ expect(lwrp.is_a?(get_lwrp(:lwrp_once))).to be_truthy
+ expect(get_lwrp(:lwrp_once) === lwrp).to be_truthy
+ expect(lwrp.class === get_lwrp(:lwrp_once))
+ end
+ it "Chef::Resource::LwrpOnce.new is *not* a subclass" do
+ lwrp = Chef::Resource::LwrpOnce.new('hi')
+ expect(lwrp.kind_of?(subclass)).to be_falsey
+ expect(lwrp.is_a?(subclass)).to be_falsey
+ expect(subclass === lwrp.class).to be_falsey
+ expect(subclass === Chef::Resource::LwrpOnce).to be_falsey
+ end
+ it "get_lwrp(:lwrp_once).new is *not* a subclass" do
+ lwrp = get_lwrp(:lwrp_once).new('hi')
+ expect(lwrp.kind_of?(subclass)).to be_falsey
+ expect(lwrp.is_a?(subclass)).to be_falsey
+ expect(subclass === lwrp.class).to be_falsey
+ expect(subclass === get_lwrp(:lwrp_once)).to be_falsey
+ end
+ end
+
+ context "with a subclass of Chef::Resource::LwrpOnce" do
+ let(:subclass) do
+ Class.new(Chef::Resource::LwrpOnce)
+ end
+
+ it "subclass.new is a subclass" do
+ lwrp = subclass.new('hi')
+ expect(lwrp.kind_of?(subclass)).to be_truthy
+ expect(lwrp.is_a?(subclass)).to be_truthy
+ expect(subclass === lwrp).to be_truthy
+ expect(lwrp.class === subclass)
+ end
+ it "subclass.new is a Chef::Resource::LwrpOnce" do
+ lwrp = subclass.new('hi')
+ expect(lwrp.kind_of?(Chef::Resource::LwrpOnce)).to be_truthy
+ expect(lwrp.is_a?(Chef::Resource::LwrpOnce)).to be_truthy
+ expect(Chef::Resource::LwrpOnce === lwrp).to be_truthy
+ expect(lwrp.class === Chef::Resource::LwrpOnce)
+ end
+ it "subclass.new is a get_lwrp(:lwrp_once)" do
+ lwrp = subclass.new('hi')
+ expect(lwrp.kind_of?(get_lwrp(:lwrp_once))).to be_truthy
+ expect(lwrp.is_a?(get_lwrp(:lwrp_once))).to be_truthy
+ expect(get_lwrp(:lwrp_once) === lwrp).to be_truthy
+ expect(lwrp.class === get_lwrp(:lwrp_once))
+ end
+ it "Chef::Resource::LwrpOnce.new is *not* a subclass" do
+ lwrp = Chef::Resource::LwrpOnce.new('hi')
+ expect(lwrp.kind_of?(subclass)).to be_falsey
+ expect(lwrp.is_a?(subclass)).to be_falsey
+ expect(subclass === lwrp.class).to be_falsey
+ expect(subclass === Chef::Resource::LwrpOnce).to be_falsey
+ end
+ it "get_lwrp(:lwrp_once).new is *not* a subclass" do
+ lwrp = get_lwrp(:lwrp_once).new('hi')
+ expect(lwrp.kind_of?(subclass)).to be_falsey
+ expect(lwrp.is_a?(subclass)).to be_falsey
+ expect(subclass === lwrp.class).to be_falsey
+ expect(subclass === get_lwrp(:lwrp_once)).to be_falsey
+ end
+ end
+ end
end
+
+