summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb22
-rw-r--r--spec/unit/resource/powershell_script_spec.rb78
2 files changed, 15 insertions, 85 deletions
diff --git a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb
index 0d6289a999..0760bcee1d 100644
--- a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb
+++ b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb
@@ -93,8 +93,8 @@ describe Chef::GuardInterpreter::ResourceGuardInterpreter do
end
describe "script command opts switch" do
- let(:command_opts) { {} }
- let(:guard_interpreter) { Chef::GuardInterpreter::ResourceGuardInterpreter.new(parent_resource, "exit 0", command_opts) }
+ let(:guard_interpreter) { Chef::GuardInterpreter::ResourceGuardInterpreter.new(parent_resource, "exit 0", {}) }
+ let(:resource) { guard_interpreter.instance_variable_get("@resource") }
context "resource is a Script" do
context "and guard_interpreter is a :script" do
@@ -117,9 +117,9 @@ describe Chef::GuardInterpreter::ResourceGuardInterpreter do
end
end
- it "merges to :code" do
- expect(command_opts).to receive(:merge).with({ code: "exit 0" }).and_call_original
- expect(guard_interpreter.evaluate).to eq(true)
+ it "assigns the comand to the resource's code property" do
+ guard_interpreter.evaluate
+ expect(resource.code).to eq("exit 0")
end
end
@@ -130,9 +130,9 @@ describe Chef::GuardInterpreter::ResourceGuardInterpreter do
parent_resource
end
- it "merges to :code" do
- expect(command_opts).to receive(:merge).with({ command: "exit 0" }).and_call_original
- expect(guard_interpreter.evaluate).to eq(true)
+ it "assigns the comand to the resource's command property" do
+ guard_interpreter.evaluate
+ expect(resource.command).to eq("exit 0")
end
end
end
@@ -144,9 +144,9 @@ describe Chef::GuardInterpreter::ResourceGuardInterpreter do
parent_resource
end
- it "merges to :command" do
- expect(command_opts).to receive(:merge).with({ command: "exit 0" }).and_call_original
- expect(guard_interpreter.evaluate).to eq(true)
+ it "assigns the comand to the resource's command property" do
+ guard_interpreter.evaluate
+ expect(resource.command).to eq("exit 0")
end
end
diff --git a/spec/unit/resource/powershell_script_spec.rb b/spec/unit/resource/powershell_script_spec.rb
index 75fdf6ffc6..1c4b081593 100644
--- a/spec/unit/resource/powershell_script_spec.rb
+++ b/spec/unit/resource/powershell_script_spec.rb
@@ -47,81 +47,11 @@ describe Chef::Resource::PowershellScript do
expect(resource.convert_boolean_return).to eq(false)
end
- context "when using guards" do
- before(:each) do
- allow(resource).to receive(:run_action)
- allow(resource).to receive(:updated).and_return(true)
- end
+ it "inherits exactly the :cwd, :environment, :group, :path, :user, :umask, :architecture, :elevated, :interpreter properties from a parent resource class" do
+ inherited_difference = Chef::Resource::PowershellScript.guard_inherited_attributes -
+ %i{cwd environment group path user umask architecture elevated interpreter}
- it "inherits exactly the :cwd, :environment, :group, :path, :user, :umask, :architecture, :elevated, :interpreter properties from a parent resource class" do
- inherited_difference = Chef::Resource::PowershellScript.guard_inherited_attributes -
- %i{cwd environment group path user umask architecture elevated interpreter}
-
- expect(inherited_difference).to eq([])
- end
-
- it "allows guard interpreter to be set to Chef::Resource::Script" do
- resource.guard_interpreter(:script)
- allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
- resource.only_if("echo hi")
- end
-
- it "allows guard interpreter to be set to Chef::Resource::Bash derived from Chef::Resource::Script" do
- resource.guard_interpreter(:bash)
- allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
- resource.only_if("echo hi")
- end
-
- it "allows guard interpreter to be set to Chef::Resource::PowershellScript derived indirectly from Chef::Resource::Script" do
- resource.guard_interpreter(:powershell_script)
- allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
- resource.only_if("echo hi")
- end
-
- it "enables convert_boolean_return by default for guards in the context of powershell_script when no guard params are specified" do
- allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(true)
- allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
- { convert_boolean_return: true, code: "$true" }
- ).and_return(Proc.new {})
- resource.only_if("$true")
- end
-
- it "enables convert_boolean_return by default for guards in non-Chef::Resource::Script derived resources when no guard params are specified" do
- node = Chef::Node.new
- run_context = Chef::RunContext.new(node, nil, nil)
- file_resource = Chef::Resource::File.new("idontexist", run_context)
- file_resource.guard_interpreter :powershell_script
-
- allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
- { convert_boolean_return: true, code: "$true" }
- ).and_return(Proc.new {})
- resource.only_if("$true")
- end
-
- it "enables convert_boolean_return by default for guards in the context of powershell_script when guard params are specified" do
- guard_parameters = { cwd: "/etc/chef", architecture: :x86_64 }
- allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
- { convert_boolean_return: true, code: "$true" }.merge(guard_parameters)
- ).and_return(Proc.new {})
- resource.only_if("$true", guard_parameters)
- end
-
- it "passes convert_boolean_return as true if it was specified as true in a guard parameter" do
- guard_parameters = { cwd: "/etc/chef", convert_boolean_return: true, architecture: :x86_64 }
- allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
- { convert_boolean_return: true, code: "$true" }.merge(guard_parameters)
- ).and_return(Proc.new {})
- resource.only_if("$true", guard_parameters)
- end
-
- it "passes convert_boolean_return as false if it was specified as true in a guard parameter" do
- other_guard_parameters = { cwd: "/etc/chef", architecture: :x86_64 }
- parameters_with_boolean_disabled = other_guard_parameters.merge({ convert_boolean_return: false, code: "$true" })
- allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
- parameters_with_boolean_disabled
- ).and_return(Proc.new {})
- resource.only_if("$true", parameters_with_boolean_disabled)
- end
+ expect(inherited_difference).to eq([])
end
context "as a script running in Windows-based scripting language" do