summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/resource/powershell_spec.rb43
-rw-r--r--spec/support/shared/functional/windows_script.rb10
-rw-r--r--spec/support/shared/unit/windows_script_resource.rb4
3 files changed, 38 insertions, 19 deletions
diff --git a/spec/functional/resource/powershell_spec.rb b/spec/functional/resource/powershell_spec.rb
index a72a33d1a5..e1e9f787a3 100644
--- a/spec/functional/resource/powershell_spec.rb
+++ b/spec/functional/resource/powershell_spec.rb
@@ -221,32 +221,36 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
before(:each) do
resource.not_if.clear
resource.only_if.clear
- # resource.guard_interpreter should be :default by default
end
- it "evaluates a succeeding not_if block using cmd.exe as false by default" do
- resource.not_if "exit /b 0"
- resource.should_skip?(:run).should be_true
- end
+ context "when the guard_interpreter's default value of :powershell_script is overridden to :default" do
+ before(:each) do
+ resource.guard_interpreter :default
+ end
- it "evaluates a failing not_if block using cmd.exe as true by default" do
- resource.not_if "exit /b 2"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a succeeding not_if block using cmd.exe as false by default" do
+ resource.not_if "exit /b 0"
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates an succeeding only_if block using cmd.exe as true by default" do
- resource.only_if "exit /b 0"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a failing not_if block using cmd.exe as true by default" do
+ resource.not_if "exit /b 2"
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a failing only_if block using cmd.exe as false by default" do
- resource.only_if "exit /b 2"
- resource.should_skip?(:run).should be_true
+ it "evaluates an succeeding only_if block using cmd.exe as true by default" do
+ resource.only_if "exit /b 0"
+ resource.should_skip?(:run).should be_false
+ end
+
+ it "evaluates a failing only_if block using cmd.exe as false by default" do
+ resource.only_if "exit /b 2"
+ resource.should_skip?(:run).should be_true
+ end
end
context "the only_if is specified before the guard" do
before do
- # force the guard_interpreter to :default in case the default changes later
resource.guard_interpreter :default
end
@@ -258,8 +262,9 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
context "with powershell_script as the guard_interpreter" do
- before(:each) do
- resource.guard_interpreter :powershell_script
+
+ it "has a guard_interpreter attribute set to :powershell_script" do
+ expect(resource.guard_interpreter).to eq(:powershell_script)
end
it "evaluates a powershell $false for a not_if block as true" do
diff --git a/spec/support/shared/functional/windows_script.rb b/spec/support/shared/functional/windows_script.rb
index 57bc8432b9..f677828167 100644
--- a/spec/support/shared/functional/windows_script.rb
+++ b/spec/support/shared/functional/windows_script.rb
@@ -120,6 +120,16 @@ shared_context Chef::Resource::WindowsScript do
end
end
+ context "when evaluating guards" do
+ it "has a guard_interpreter attribute set to the short name of the resource" do
+ resource.guard_interpreter.should == resource.resource_name
+ resource.not_if "findstr.exe /thiscommandhasnonzeroexitstatus"
+ expect(Chef::Resource).to receive(:resource_for_node).and_call_original
+ expect(resource.class).to receive(:new).and_call_original
+ resource.should_skip?(:run).should be_false
+ end
+ end
+
context "when the architecture attribute is not set" do
let(:architecture) { nil }
it_behaves_like "a script resource with architecture attribute"
diff --git a/spec/support/shared/unit/windows_script_resource.rb b/spec/support/shared/unit/windows_script_resource.rb
index 837ac1a430..b4a5889b32 100644
--- a/spec/support/shared/unit/windows_script_resource.rb
+++ b/spec/support/shared/unit/windows_script_resource.rb
@@ -40,6 +40,10 @@ shared_examples_for "a Windows script resource" do
end
context "when evaluating guards" do
+ it "should have a default_guard_interpreter attribute that is the same as the resource" do
+ @resource.default_guard_interpreter.should == @resource.resource_name
+ end
+
it "should default to using guard_interpreter attribute that is the same as the resource" do
@resource.guard_interpreter.should == @resource.resource_name
end