summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-02-24 16:12:51 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2017-02-28 11:19:48 -0800
commit0ca58ffd12e5399792e0f8a3b54c6f3ba7bddab2 (patch)
tree4c6ffee87fac90600b0ba386c6a329a8a27c2abb
parentd8a2bc810381f58eeb4ecd4db7ff104038f8f97c (diff)
downloadchef-0ca58ffd12e5399792e0f8a3b54c6f3ba7bddab2.tar.gz
Chef-13 break: script and all its subclasses now errors on 'command' property
This was always a coding bug. The `command` property is only used internally but is exposed for users to twiddle because script subclasses execute. Thus this still violates Liskov Substitution and this is not an is-a relationship where inheritance might be appropriate, because the script resource should /use/ the execute resource and not /be an/ execute resource. The more you know... Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/resource/script.rb12
-rw-r--r--spec/support/shared/unit/script_resource.rb10
-rw-r--r--spec/unit/resource/script_spec.rb2
3 files changed, 6 insertions, 18 deletions
diff --git a/lib/chef/resource/script.rb b/lib/chef/resource/script.rb
index 5173a76542..e1d71c2924 100644
--- a/lib/chef/resource/script.rb
+++ b/lib/chef/resource/script.rb
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,13 +23,11 @@ require "chef/provider/script"
class Chef
class Resource
class Script < Chef::Resource::Execute
- # Chef-13: go back to using :name as the identity attr
- identity_attr :command
+ identity_attr :name
def initialize(name, run_context = nil)
super
- # Chef-13: the command variable should be initialized to nil
- @command = name
+ @command = nil
@code = nil
@interpreter = nil
@flags = nil
@@ -38,9 +36,7 @@ class Chef
def command(arg = nil)
unless arg.nil?
- # Chef-13: change this to raise if the user is trying to set a value here
- Chef::Log.warn "Specifying command attribute on a script resource is a coding error, use the 'code' attribute, or the execute resource"
- Chef::Log.warn "This attribute is deprecated and must be fixed or this code will fail on Chef 13"
+ raise Chef::Exceptions::Script, "Do not use the command attribute on a #{resource_name} resource, use the 'code' attribute instead."
end
super
end
diff --git a/spec/support/shared/unit/script_resource.rb b/spec/support/shared/unit/script_resource.rb
index 27864e1625..a04da4b63e 100644
--- a/spec/support/shared/unit/script_resource.rb
+++ b/spec/support/shared/unit/script_resource.rb
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,10 +34,6 @@ shared_examples_for "a script resource" do
expect(script_resource.command).to be nil
end
- it "should set command to the name on the resource", chef: "< 13" do
- expect(script_resource.command).to eql script_resource.name
- end
-
it "should accept a string for the code" do
script_resource.code "hey jude"
expect(script_resource.code).to eql("hey jude")
@@ -52,10 +48,6 @@ shared_examples_for "a script resource" do
expect { script_resource.command("foo") }.to raise_error(Chef::Exceptions::Script)
end
- it "should not raise an exception if users set command on the resource", chef: "< 13" do
- expect { script_resource.command("foo") }.not_to raise_error
- end
-
describe "when executing guards" do
let(:resource) do
resource = script_resource
diff --git a/spec/unit/resource/script_spec.rb b/spec/unit/resource/script_spec.rb
index fca9fb0d7b..16f7650712 100644
--- a/spec/unit/resource/script_spec.rb
+++ b/spec/unit/resource/script_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");