diff options
author | dheerajd-msys <dheeraj.dubey@msystechnologies.com> | 2016-09-12 15:18:11 +0530 |
---|---|---|
committer | dheerajd-msys <dheeraj.dubey@msystechnologies.com> | 2016-09-13 09:44:29 +0530 |
commit | 3ae511bdc32802ffc832a4548bb1cbcd34205a36 (patch) | |
tree | 6fbcc64db03ebcef5d792e185f59df36c79cff8a | |
parent | 407ef2c5abde31698d9fa8c57dc944cb6637a320 (diff) | |
download | chef-3ae511bdc32802ffc832a4548bb1cbcd34205a36.tar.gz |
Refactored specs
-rw-r--r-- | spec/unit/provider/registry_key_spec.rb | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/spec/unit/provider/registry_key_spec.rb b/spec/unit/provider/registry_key_spec.rb index c39864b757..9e19d02d5e 100644 --- a/spec/unit/provider/registry_key_spec.rb +++ b/spec/unit/provider/registry_key_spec.rb @@ -19,23 +19,6 @@ require "spec_helper" shared_examples_for "a registry key" do - before(:each) do - @node = Chef::Node.new - @events = Chef::EventDispatch::Dispatcher.new - @run_context = Chef::RunContext.new(@node, {}, @events) - - @new_resource = Chef::Resource::RegistryKey.new("windows is fun", @run_context) - @new_resource.key keyname - @new_resource.values( testval1 ) - @new_resource.recursive false - - @provider = Chef::Provider::RegistryKey.new(@new_resource, @run_context) - - allow(@provider).to receive(:running_on_windows!).and_return(true) - @double_registry = double(Chef::Win32::Registry) - allow(@provider).to receive(:registry).and_return(@double_registry) - end - describe "when first created" do end @@ -111,13 +94,6 @@ shared_examples_for "a registry key" do @provider.load_current_resource @provider.action_create end - it "should not set the value if the key exists but the datatype of data does not match" do - @new_resource.values( testval3_data_string ) - expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval3 ) - expect(@double_registry).not_to receive(:set_value) - @provider.load_current_resource - @provider.action_create - end it "should set the value if the key exists but the type does not match" do expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1_wrong_type ) expect(@double_registry).to receive(:set_value).with(keyname, testval1) @@ -280,14 +256,30 @@ shared_examples_for "a registry key" do end describe Chef::Provider::RegistryKey do + before(:each) do + @node = Chef::Node.new + @events = Chef::EventDispatch::Dispatcher.new + @run_context = Chef::RunContext.new(@node, {}, @events) + + @new_resource = Chef::Resource::RegistryKey.new("windows is fun", @run_context) + @new_resource.key keyname + @new_resource.values( testval1 ) + @new_resource.recursive false + + @provider = Chef::Provider::RegistryKey.new(@new_resource, @run_context) + + allow(@provider).to receive(:running_on_windows!).and_return(true) + @double_registry = double(Chef::Win32::Registry) + allow(@provider).to receive(:registry).and_return(@double_registry) + end + context "when the key data is safe" do let(:keyname) { 'HKLM\Software\Opscode\Testing\Safe' } let(:testval1) { { :name => "one", :type => :string, :data => "1" } } let(:testval1_wrong_type) { { :name => "one", :type => :multi_string, :data => "1" } } let(:testval1_wrong_data) { { :name => "one", :type => :string, :data => "2" } } let(:testval2) { { :name => "two", :type => :string, :data => "2" } } - let(:testval3) { { :name => "three", :type => :dword, :data => 12345 } } - let(:testval3_data_string) { { :name => "three", :type => :dword, :data => "12345" } } + it_should_behave_like "a registry key" end @@ -297,9 +289,25 @@ describe Chef::Provider::RegistryKey do let(:testval1_wrong_type) { { :name => "one", :type => :string, :data => 255.chr * 1 } } let(:testval1_wrong_data) { { :name => "one", :type => :binary, :data => 254.chr * 1 } } let(:testval2) { { :name => "two", :type => :binary, :data => 0.chr * 1 } } - let(:testval3) { { :name => "three", :type => :binary, :data => 0.chr * 1 } } - let(:testval3_data_string) { { :name => "three", :type => :binary, :data => 0.chr * 1 } } it_should_behave_like "a registry key" end + + describe "action_create" do + context "when key exists and type matches" do + let(:keyname) { 'hklm\\software\\opscode\\testing\\dword' } + let(:dword_passed_as_integer) { { :name => "one", :type => :dword, :data => 12345 } } + let(:testval1) { { :name => "one", :type => :dword, :data => "12345" } } + before do + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(true) + end + + it "does not make a change for datatype of data value differing" do + expect(@double_registry).to receive(:get_values).with(keyname).and_return( dword_passed_as_integer ) + expect(@double_registry).not_to receive(:set_value) + @provider.load_current_resource + @provider.action_create + end + end + end end |