diff options
author | Lamont Granquist <lamont@opscode.com> | 2012-12-10 16:37:57 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@opscode.com> | 2012-12-19 15:56:12 -0800 |
commit | a7b6225369b1bb402e1aaae2875488a0affa6bfe (patch) | |
tree | 44fc09230334b6b3b40819d37bfccb2252c9e667 | |
parent | 61f78fcc426f03874974924b6b62d84c25b2679c (diff) | |
download | chef-a7b6225369b1bb402e1aaae2875488a0affa6bfe.tar.gz |
add unit tests for case when values are not set in the resource
-rw-r--r-- | spec/unit/provider/registry_key_spec.rb | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/spec/unit/provider/registry_key_spec.rb b/spec/unit/provider/registry_key_spec.rb index a9e2647032..2f6f8179e6 100644 --- a/spec/unit/provider/registry_key_spec.rb +++ b/spec/unit/provider/registry_key_spec.rb @@ -77,8 +77,8 @@ describe Chef::Provider::RegistryKey do @provider.load_current_resource end - it "should set the values in the current resource to nil" do - @provider.current_resource.values.should == nil + it "should set the values in the current resource to empty array" do + @provider.current_resource.values.should == [] end end end @@ -113,6 +113,26 @@ describe Chef::Provider::RegistryKey do @provider.action_create end end + context "when the key exists and the values in the new resource are empty" do + it "when a value is in the key, it should do nothing" do + @provider.new_resource.values([]) + @double_registry.should_receive(:key_exists?).twice.with(testkey1).and_return(true) + @double_registry.should_receive(:get_values).with(testkey1).and_return( testval1 ) + @double_registry.should_not_receive(:create_key) + @double_registry.should_not_receive(:set_value) + @provider.load_current_resource + @provider.action_create + end + it "when no value is in the key, it should do nothing" do + @provider.new_resource.values([]) + @double_registry.should_receive(:key_exists?).twice.with(testkey1).and_return(true) + @double_registry.should_receive(:get_values).with(testkey1).and_return( nil ) + @double_registry.should_not_receive(:create_key) + @double_registry.should_not_receive(:set_value) + @provider.load_current_resource + @provider.action_create + end + end context "when the key does not exist" do before(:each) do @double_registry.should_receive(:key_exists?).twice.with(testkey1).and_return(false) @@ -124,6 +144,16 @@ describe Chef::Provider::RegistryKey do @provider.action_create end end + context "when the key does not exist and the values in the new resource are empty" do + it "should create the key" do + @new_resource.values([]) + @double_registry.should_receive(:key_exists?).twice.with(testkey1).and_return(false) + @double_registry.should_receive(:create_key).with(testkey1, false) + @double_registry.should_not_receive(:set_value) + @provider.load_current_resource + @provider.action_create + end + end end describe "action_create_if_missing" do |