summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamedx <admed@opscode.com>2013-01-26 22:15:02 -0800
committeradamedx <adamed@opscode.com>2013-02-19 09:32:06 -0800
commita3f5ab6223e1b108dbbf464dcafd15f1872d017f (patch)
tree0ea6bfee58ef2dddf73d7bbc5aa5596485070477
parent63d34bb7887606ee5d55ad70264ff14a90aa3f09 (diff)
downloadchef-a3f5ab6223e1b108dbbf464dcafd15f1872d017f.tar.gz
OC-4739: OC-4748: Refactor tests to share examples across batch and powershell resource specs
-rw-r--r--lib/chef/provider/powershell.rb2
-rw-r--r--lib/chef/provider/script.rb2
-rw-r--r--lib/chef/provider/windows_script.rb2
-rw-r--r--spec/unit/provider/powershell_spec.rb6
-rw-r--r--spec/unit/resource/batch_spec.rb23
-rw-r--r--spec/unit/resource/execute_spec.rb104
-rw-r--r--spec/unit/resource/powershell_spec.rb18
-rw-r--r--spec/unit/resource/script_spec.rb49
8 files changed, 38 insertions, 168 deletions
diff --git a/lib/chef/provider/powershell.rb b/lib/chef/provider/powershell.rb
index 2ae7552197..aaa4a9255e 100644
--- a/lib/chef/provider/powershell.rb
+++ b/lib/chef/provider/powershell.rb
@@ -27,7 +27,7 @@ class Chef
end
def flags
- @new_resource.flags.nil? ? '-ExecutionPolicy RemoteSigned -Command' : new_resource.flags + '-ExecutionPolicy RemoteSigned -Commmand'
+ @new_resource.flags.nil? ? '-ExecutionPolicy RemoteSigned -Command' : @new_resource.flags + '-ExecutionPolicy RemoteSigned -Command'
end
end
diff --git a/lib/chef/provider/script.rb b/lib/chef/provider/script.rb
index 5c3d2ebb33..4d405e59f1 100644
--- a/lib/chef/provider/script.rb
+++ b/lib/chef/provider/script.rb
@@ -63,7 +63,7 @@ class Chef
protected
def interpreter_script_path
- @script_file.path
+ script_file.path
end
end
diff --git a/lib/chef/provider/windows_script.rb b/lib/chef/provider/windows_script.rb
index 0dfd4d81b3..94ffa1d3be 100644
--- a/lib/chef/provider/windows_script.rb
+++ b/lib/chef/provider/windows_script.rb
@@ -41,7 +41,7 @@ class Chef
end
def interpreter_script_path
- @script_file.path.gsub(::File::SEPARATOR) { | replace | ::File::ALT_SEPARATOR }
+ script_file.path.gsub(::File::SEPARATOR) { | replace | ::File::ALT_SEPARATOR }
end
end
end
diff --git a/spec/unit/provider/powershell_spec.rb b/spec/unit/provider/powershell_spec.rb
index 37b299ebbf..fc973a686a 100644
--- a/spec/unit/provider/powershell_spec.rb
+++ b/spec/unit/provider/powershell_spec.rb
@@ -21,8 +21,12 @@ describe Chef::Provider::Powershell, "action_run" do
before(:each) do
@node = Chef::Node.new
+
+ @node.default["kernel"] = Hash.new
+ @node.default["kernel"][:machine] = :x86_64.to_s
+
@run_context = Chef::RunContext.new(@node, {}, @events)
- @new_resource = Chef::Resource::Powershell.new('run some powershell code')
+ @new_resource = Chef::Resource::Powershell.new('run some powershell code', @run_context)
# @new_resource.code "$| = 1; print 'i like beans'"
# @new_resource.interpreter 'perl'
diff --git a/spec/unit/resource/batch_spec.rb b/spec/unit/resource/batch_spec.rb
index 1e4d65da7c..119b0dd5f1 100644
--- a/spec/unit/resource/batch_spec.rb
+++ b/spec/unit/resource/batch_spec.rb
@@ -33,25 +33,16 @@ describe Chef::Resource::Batch do
end
it "should create a new Chef::Resource::Batch" do
- @resource.should be_a_kind_of(Chef::Resource)
@resource.should be_a_kind_of(Chef::Resource::Batch)
end
- it "should have a resource name of :batch" do
- @resource.resource_name.should eql(:batch)
- end
-
- it "should have an interpreter with a file name of cmd.exe" do
-
+ context "windowssystemscript" do
+ let(:resource_instance) { @resource }
+ let(:resource_instance_name ) { @resource.command }
+ let(:resource_name) { :batch }
+ let(:interpreter_file_name) { 'cmd.exe' }
- # When rspec-mocks 2.11 is released, switch to constant_stubbing
- # with const_stub below
- # stub_const("::File::ALT_SEPARATOR",::File::SEPARATOR).
- # For now, stub out a method that exists just for this purpose
-# @resource.respond_to?(:windows_separator).should == true
-# @resource.stub(:windows_separator) { ::File::SEPARATOR }
-
- @resource.interpreter.split('\\').pop.casecmp('cmd.exe').should == 0
+ it_should_behave_like "a Windows system script resource"
end
-
+
end
diff --git a/spec/unit/resource/execute_spec.rb b/spec/unit/resource/execute_spec.rb
index 0dcdab7409..8c8dcfb6ca 100644
--- a/spec/unit/resource/execute_spec.rb
+++ b/spec/unit/resource/execute_spec.rb
@@ -20,105 +20,7 @@
require 'spec_helper'
describe Chef::Resource::Execute do
-
- before(:each) do
- @resource = Chef::Resource::Execute.new("some command")
- end
-
- it "should create a new Chef::Resource::Execute" do
- @resource.should be_a_kind_of(Chef::Resource)
- @resource.should be_a_kind_of(Chef::Resource::Execute)
- end
-
- it "should set the command to the first argument to new" do
- @resource.command.should eql("some command")
- end
-
- it "should accept an array on instantiation, too" do
- resource = Chef::Resource::Execute.new(%w{something else})
- resource.should be_a_kind_of(Chef::Resource)
- resource.should be_a_kind_of(Chef::Resource::Execute)
- resource.command.should eql(%w{something else})
- end
-
- it "should accept a string for the command to run" do
- @resource.command "something"
- @resource.command.should eql("something")
- end
-
- it "should accept an array for the command to run" do
- @resource.command %w{something else}
- @resource.command.should eql(%w{something else})
- end
-
- it "should accept a string for the cwd" do
- @resource.cwd "something"
- @resource.cwd.should eql("something")
- end
-
- it "should accept a hash for the environment" do
- test_hash = { :one => :two }
- @resource.environment(test_hash)
- @resource.environment.should eql(test_hash)
- end
-
- it "allows the environment to be specified with #env" do
- @resource.should respond_to(:env)
- end
-
- it "should accept a string for the group" do
- @resource.group "something"
- @resource.group.should eql("something")
- end
-
- it "should accept an integer for the group" do
- @resource.group 1
- @resource.group.should eql(1)
- end
-
- it "should accept an array for the execution path" do
- @resource.path ["woot"]
- @resource.path.should eql(["woot"])
- end
-
- it "should accept an integer for the return code" do
- @resource.returns 1
- @resource.returns.should eql(1)
- end
-
- it "should accept an integer for the timeout" do
- @resource.timeout 1
- @resource.timeout.should eql(1)
- end
-
- it "should accept a string for the user" do
- @resource.user "something"
- @resource.user.should eql("something")
- end
-
- it "should accept an integer for the user" do
- @resource.user 1
- @resource.user.should eql(1)
- end
-
- it "should accept a string for creates" do
- @resource.creates "something"
- @resource.creates.should eql("something")
- end
-
- describe "when it has cwd, environment, group, path, return value, and a user" do
- before do
- @resource.command("grep")
- @resource.cwd("/tmp/")
- @resource.environment({ :one => :two })
- @resource.group("legos")
- @resource.path(["/var/local/"])
- @resource.returns(1)
- @resource.user("root")
- end
-
- it "returns the command as its identity" do
- @resource.identity.should == "grep"
- end
- end
+ let(:resource_instance_name) { "some command" }
+ let(:execute_resource) { Chef::Resource::Execute.new(resource_instance_name) }
+ it_behaves_like "an execute resource"
end
diff --git a/spec/unit/resource/powershell_spec.rb b/spec/unit/resource/powershell_spec.rb
index fad4ae4eee..c6650f4daa 100644
--- a/spec/unit/resource/powershell_spec.rb
+++ b/spec/unit/resource/powershell_spec.rb
@@ -27,26 +27,22 @@ describe Chef::Resource::Powershell do
node.default["kernel"][:machine] = :x86_64.to_s
run_context = Chef::RunContext.new(node, nil, nil)
-
- @resource = Chef::Resource::Batch.new("batch_unit_test", run_context)
-
- run_context = Chef::RunContext.new(node, nil, nil)
@resource = Chef::Resource::Powershell.new("powershell_unit_test", run_context)
end
it "should create a new Chef::Resource::Powershell" do
- @resource.should be_a_kind_of(Chef::Resource)
@resource.should be_a_kind_of(Chef::Resource::Powershell)
end
- it "should have a resource name of :powershell" do
- @resource.resource_name.should eql(:powershell)
- end
-
- it "should have an interpreter with a file name of powershell.exe" do
- @resource.interpreter.split('\\').pop.casecmp('powershell.exe').should == 0
+ context "windowssystemscript" do
+ let(:resource_instance) { @resource }
+ let(:resource_instance_name ) { @resource.command }
+ let(:resource_name) { :powershell }
+ let(:interpreter_file_name) { 'powershell.exe' }
+
+ it_should_behave_like "a Windows system script resource"
end
end
diff --git a/spec/unit/resource/script_spec.rb b/spec/unit/resource/script_spec.rb
index 569602008b..53735daf01 100644
--- a/spec/unit/resource/script_spec.rb
+++ b/spec/unit/resource/script_spec.rb
@@ -20,50 +20,27 @@
require 'spec_helper'
describe Chef::Resource::Script do
+ let(:resource_instance_name) { "fakey_fakerton" }
+ let(:script_resource) { Chef::Resource::Script.new(resource_instance_name) }
+ let(:resource_name) { :script }
- before(:each) do
- @resource = Chef::Resource::Script.new("fakey_fakerton")
- end
-
- it "should create a new Chef::Resource::Script" do
- @resource.should be_a_kind_of(Chef::Resource)
- @resource.should be_a_kind_of(Chef::Resource::Script)
- end
-
- it "should have a resource name of :script" do
- @resource.resource_name.should eql(:script)
- end
-
- it "should set command to the argument provided to new" do
- @resource.command.should eql("fakey_fakerton")
- end
-
- it "should accept a string for the code" do
- @resource.code "hey jude"
- @resource.code.should eql("hey jude")
- end
-
it "should accept a string for the interpreter" do
- @resource.interpreter "naaaaNaNaNaaNaaNaaNaa"
- @resource.interpreter.should eql("naaaaNaNaNaaNaaNaaNaa")
- end
-
- it "should accept a string for the flags" do
- @resource.flags "-f"
- @resource.flags.should eql("-f")
+ script_resource.interpreter "naaaaNaNaNaaNaaNaaNaa"
+ script_resource.interpreter.should eql("naaaaNaNaNaaNaaNaaNaa")
end
describe "when it has interpreter and flags" do
before do
- @resource.command("grep")
- @resource.interpreter("gcc")
- @resource.flags("-al")
+ script_resource.command("grep")
+ script_resource.interpreter("gcc")
+ script_resource.flags("-al")
end
- it "returns the command as its identity" do
- @resource.identity.should == "grep"
+ it "returns the command as its identity" do
+ script_resource.identity.should == "grep"
end
end
-
-
+
+ it_behaves_like "a script resource"
end
+