diff options
author | John Keiser <john@johnkeiser.com> | 2015-05-18 13:47:49 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-05-18 13:59:06 -0700 |
commit | 05b07f669b9a06799e7e20608d1df3e5bbc2853a (patch) | |
tree | be759c79a05c62466d456db014ce165e7098eb75 | |
parent | b64f37e42952caf744e46394dcc28ab7b7916431 (diff) | |
download | chef-jk/fix_lwrp_class_name.tar.gz |
Fix LWRP instance.to_s to look like normal resources againjk/fix_lwrp_class_name
-rw-r--r-- | lib/chef/provider/lwrp_base.rb | 4 | ||||
-rw-r--r-- | lib/chef/resource/lwrp_base.rb | 4 | ||||
-rw-r--r-- | spec/unit/lwrp_spec.rb | 8 |
3 files changed, 12 insertions, 4 deletions
diff --git a/lib/chef/provider/lwrp_base.rb b/lib/chef/provider/lwrp_base.rb index 38430ced6d..31f93248c6 100644 --- a/lib/chef/provider/lwrp_base.rb +++ b/lib/chef/provider/lwrp_base.rb @@ -103,10 +103,10 @@ class Chef # Respect resource_name set inside the LWRP provider_class.instance_eval do - define_method(:to_s) do + define_singleton_method(:to_s) do "LWRP provider #{resource_name} from cookbook #{cookbook_name}" end - define_method(:inspect) { to_s } + define_singleton_method(:inspect) { to_s } end Chef::Log.debug("Loaded contents of #{filename} into provider #{resource_name} (#{provider_class})") diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb index c79c205285..639399e6bb 100644 --- a/lib/chef/resource/lwrp_base.rb +++ b/lib/chef/resource/lwrp_base.rb @@ -62,10 +62,10 @@ class Chef # Respect resource_name set inside the LWRP resource_class.instance_eval do - define_method(:to_s) do + define_singleton_method(:to_s) do "LWRP resource #{resource_name} from cookbook #{cookbook_name}" end - define_method(:inspect) { to_s } + define_singleton_method(:inspect) { to_s } end Chef::Log.debug("Loaded contents of #{filename} into resource #{resource_name} (#{resource_class})") diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index ff7f8e7d7b..f5b6f32ff2 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -172,6 +172,14 @@ describe "LWRP" do expect(get_lwrp(:lwrp_foo).new("blah").resource_name).to eql(:lwrp_foo) end + it "should output the resource_name in .to_s" do + expect(get_lwrp(:lwrp_foo).new("blah").to_s).to eq "lwrp_foo[blah]" + end + + it "should have a class that outputs a reasonable string" do + expect(get_lwrp(:lwrp_foo).to_s).to eq "LWRP resource lwrp_foo from cookbook lwrp" + end + it "should add the specified actions to the allowed_actions array" do expect(get_lwrp(:lwrp_foo).new("blah").allowed_actions).to include(:pass_buck, :twiddle_thumbs) end |