summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2014-09-26 11:34:33 -0400
committerBryan McLellan <btm@loftninjas.org>2014-09-30 20:13:32 -0400
commit11dae8e3cdf5ea6044c105beb94336c2778a1705 (patch)
tree34cec4c575f10fd4a841ea134f8d607a3ae29065
parent3eb618e7826115c3be40d68b072adea7e5b0248e (diff)
downloadchef-11dae8e3cdf5ea6044c105beb94336c2778a1705.tar.gz
Refactor resource guard interpreter specs
Refactor the unit tests to not test Chef::GuardInterpreter::ResourceGuardInterpreter directly rather than through Chef::Resource.
-rw-r--r--spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb31
1 files changed, 16 insertions, 15 deletions
diff --git a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb
index a016cbfeb8..a122ac5515 100644
--- a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb
+++ b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb
@@ -19,37 +19,38 @@
require 'spec_helper'
describe Chef::GuardInterpreter::ResourceGuardInterpreter do
- before(:each) do
+ let(:node) do
node = Chef::Node.new
node.default["kernel"] = Hash.new
node.default["kernel"][:machine] = :x86_64.to_s
+ node
+ end
- run_context = Chef::RunContext.new(node, nil, nil)
+ let(:run_context) { Chef::RunContext.new(node, nil, nil) }
- @resource = Chef::Resource.new("powershell_unit_test", run_context)
- @resource.stub(:run_action)
- @resource.stub(:updated).and_return(true)
+ let(:resource) do
+ resource = Chef::Resource.new("powershell_unit_test", run_context)
+ resource.stub(:run_action)
+ resource.stub(:updated).and_return(true)
+ resource
end
- describe "when evaluating a guard resource" do
- let(:resource) { @resource }
- it "should allow guard interpreter to be set to Chef::Resource::Script" do
+ describe "get_interpreter_resource" do
+ it "allows the 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")
+ expect { Chef::GuardInterpreter::ResourceGuardInterpreter.new(resource, "echo hi", nil) }.not_to raise_error
end
- it "should allow guard interpreter to be set to Chef::Resource::PowershellScript derived indirectly from Chef::Resource::Script" do
+ it "allows the 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")
+ expect { Chef::GuardInterpreter::ResourceGuardInterpreter.new(resource, "echo hi", nil) }.not_to raise_error
end
- it "should raise an exception if guard_interpreter is set to a resource not derived from Chef::Resource::Script" do
+ it "raises an exception if guard_interpreter is set to a resource not derived from Chef::Resource::Script" do
resource.guard_interpreter(:file)
- expect { resource.only_if("echo hi") }.to raise_error ArgumentError
+ expect { Chef::GuardInterpreter::ResourceGuardInterpreter.new(resource, "echo hi", nil) }.to raise_error(ArgumentError)
end
end
end