summaryrefslogtreecommitdiff
path: root/spec/unit/resource
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/resource')
-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
4 files changed, 30 insertions, 164 deletions
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
+