summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2014-09-02 19:04:19 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2014-09-19 12:48:05 -0700
commit4a6714e157511ff13e32f730346530d5fa5c9184 (patch)
tree1e8781e7590ec50ef7c0b22c6e65a2534cc14df4
parente3d685d9cce83342f03a624a3fe7121ccc34443a (diff)
downloadchef-4a6714e157511ff13e32f730346530d5fa5c9184.tar.gz
Cleanup dsc_script_spec to use newer rspec conventions
-rw-r--r--spec/unit/provider/dsc_script_spec.rb83
1 files changed, 40 insertions, 43 deletions
diff --git a/spec/unit/provider/dsc_script_spec.rb b/spec/unit/provider/dsc_script_spec.rb
index b0b4416a66..ff2c7cf3c0 100644
--- a/spec/unit/provider/dsc_script_spec.rb
+++ b/spec/unit/provider/dsc_script_spec.rb
@@ -22,53 +22,51 @@ require 'chef/util/dsc/resource_info'
require 'spec_helper'
describe Chef::Provider::DscScript do
-
- before(:each) do
- @node = Chef::Node.new
- @events = Chef::EventDispatch::Dispatcher.new
- @run_context = Chef::RunContext.new(@node, {}, @events)
- @resource = Chef::Resource::DscScript.new("script", @run_context)
- @provider = Chef::Provider::DscScript.new(@resource, @run_context)
- @provider.current_resource = @current_resource
+ let (:node) { Chef::Node.new }
+ let (:events) { Chef::EventDispatch::Dispatcher.new }
+ let (:run_context) { Chef::RunContext.new(node, {}, events) }
+ let (:resource) { Chef::Resource::DscScript.new("script", run_context) }
+ let (:provider) do
+ Chef::Provider::DscScript.new(resource, run_context)
end
describe '#load_current_resource' do
it "describes the resource as converged if there were 0 DSC resources" do
- @provider.stub(:run_configuration).with(:test).and_return([])
- @provider.load_current_resource
- @provider.instance_variable_get('@resource_converged').should be_true
+ allow(provider).to receive(:run_configuration).with(:test).and_return([])
+ provider.load_current_resource
+ provider.instance_variable_get('@resource_converged').should be_true
end
it "describes the resource as not converged if there is 1 DSC resources that is converged" do
dsc_resource_info = Chef::Util::DSC::ResourceInfo.new('resource', false, ['nothing will change something'])
- @provider.stub(:run_configuration).with(:test).and_return([dsc_resource_info])
- @provider.load_current_resource
- @provider.instance_variable_get('@resource_converged').should be_true
+ allow(provider).to receive(:run_configuration).with(:test).and_return([dsc_resource_info])
+ provider.load_current_resource
+ provider.instance_variable_get('@resource_converged').should be_true
end
it "describes the resource as not converged if there is 1 DSC resources that is not converged" do
dsc_resource_info = Chef::Util::DSC::ResourceInfo.new('resource', true, ['will change something'])
- @provider.stub(:run_configuration).with(:test).and_return([dsc_resource_info])
- @provider.load_current_resource
- @provider.instance_variable_get('@resource_converged').should be_false
+ allow(provider).to receive(:run_configuration).with(:test).and_return([dsc_resource_info])
+ provider.load_current_resource
+ provider.instance_variable_get('@resource_converged').should be_false
end
it "describes the resource as not converged if there are any DSC resources that are not converged" do
dsc_resource_info1 = Chef::Util::DSC::ResourceInfo.new('resource', true, ['will change something'])
dsc_resource_info2 = Chef::Util::DSC::ResourceInfo.new('resource', false, ['nothing will change something'])
- @provider.stub(:run_configuration).with(:test).and_return([dsc_resource_info1, dsc_resource_info2])
- @provider.load_current_resource
- @provider.instance_variable_get('@resource_converged').should be_false
+ allow(provider).to receive(:run_configuration).with(:test).and_return([dsc_resource_info1, dsc_resource_info2])
+ provider.load_current_resource
+ provider.instance_variable_get('@resource_converged').should be_false
end
it "describes the resource as converged if all DSC resources that are converged" do
dsc_resource_info1 = Chef::Util::DSC::ResourceInfo.new('resource', false, ['nothing will change something'])
dsc_resource_info2 = Chef::Util::DSC::ResourceInfo.new('resource', false, ['nothing will change something'])
- @provider.stub(:run_configuration).with(:test).and_return([dsc_resource_info1, dsc_resource_info2])
- @provider.load_current_resource
- @provider.instance_variable_get('@resource_converged').should be_true
+ allow(provider).to receive(:run_configuration).with(:test).and_return([dsc_resource_info1, dsc_resource_info2])
+ provider.load_current_resource
+ provider.instance_variable_get('@resource_converged').should be_true
end
end
@@ -76,48 +74,47 @@ describe Chef::Provider::DscScript do
# I think integration tests should cover these cases
it 'uses configuration_document_from_script_path when a dsc script file is given' do
- @provider.stub(:load_current_resource)
- @resource.command("path_to_script")
+ allow(provider).to receive(:load_current_resource)
+ resource.command("path_to_script")
generator = double('Chef::Util::DSC::ConfigurationGenerator')
generator.should_receive(:configuration_document_from_script_path)
- Chef::Util::DSC::ConfigurationGenerator.stub(:new).and_return(generator)
- @provider.send(:generate_configuration_document, 'tmp', nil)
+ allow(Chef::Util::DSC::ConfigurationGenerator).to receive(:new).and_return(generator)
+ provider.send(:generate_configuration_document, 'tmp', nil)
end
it 'uses configuration_document_from_script_code when a the dsc resource is given' do
- @provider.stub(:load_current_resource)
- @resource.code("ImADSCResource{}")
+ allow(provider).to receive(:load_current_resource)
+ resource.code("ImADSCResource{}")
generator = double('Chef::Util::DSC::ConfigurationGenerator')
generator.should_receive(:configuration_document_from_script_code)
- Chef::Util::DSC::ConfigurationGenerator.stub(:new).and_return(generator)
- @provider.send(:generate_configuration_document, 'tmp', nil)
+ allow(Chef::Util::DSC::ConfigurationGenerator).to receive(:new).and_return(generator)
+ provider.send(:generate_configuration_document, 'tmp', nil)
end
it 'should noop if neither code or command are provided' do
- @provider.stub(:load_current_resource)
+ allow(provider).to receive(:load_current_resource)
generator = double('Chef::Util::DSC::ConfigurationGenerator')
generator.should_receive(:configuration_document_from_script_code).with('', anything(), anything())
- Chef::Util::DSC::ConfigurationGenerator.stub(:new).and_return(generator)
- @provider.send(:generate_configuration_document, 'tmp', nil)
+ allow(Chef::Util::DSC::ConfigurationGenerator).to receive(:new).and_return(generator)
+ provider.send(:generate_configuration_document, 'tmp', nil)
end
end
describe 'action_run' do
it 'should converge the script if it is not converged' do
dsc_resource_info = Chef::Util::DSC::ResourceInfo.new('resource', true, ['will change something'])
- @provider.stub(:run_configuration).with(:test).and_return([dsc_resource_info])
- @provider.stub(:run_configuration).with(:set)
-
- @provider.run_action(:run)
- @resource.should be_updated
+ allow(provider).to receive(:run_configuration).with(:test).and_return([dsc_resource_info])
+ allow(provider).to receive(:run_configuration).with(:set)
+ provider.run_action(:run)
+ resource.should be_updated
end
it 'should not converge if the script is already converged' do
- @provider.stub(:run_configuration).with(:test).and_return([])
-
- @provider.run_action(:run)
- @resource.should_not be_updated
+ allow(provider).to receive(:run_configuration).with(:test).and_return([])
+
+ provider.run_action(:run)
+ resource.should_not be_updated
end
end
end