diff options
author | Claire McQuin <claire@getchef.com> | 2015-09-21 09:13:11 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2015-09-21 10:19:14 -0700 |
commit | 12461128b1dc82b56568fe8ac6d5d9a8ffb0f3f2 (patch) | |
tree | eb036ed0c4d39643a4808edf8b2270417c965fc0 /spec/unit/win32 | |
parent | 3da8700c1c88a44488732bae47bcc5b1cb545ca2 (diff) | |
download | chef-12461128b1dc82b56568fe8ac6d5d9a8ffb0f3f2.tar.gz |
Safely clean up Win32 namespace after specs
Diffstat (limited to 'spec/unit/win32')
-rw-r--r-- | spec/unit/win32/registry_spec.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/spec/unit/win32/registry_spec.rb b/spec/unit/win32/registry_spec.rb index fdd3e85a8c..3ad26d967e 100644 --- a/spec/unit/win32/registry_spec.rb +++ b/spec/unit/win32/registry_spec.rb @@ -19,6 +19,7 @@ require 'spec_helper' describe Chef::Win32::Registry do + include_context "Win32" let(:value1) { { :name => "one", :type => :string, :data => "1" } } let(:value1_upcase_name) { {:name => "ONE", :type => :string, :data => "1"} } @@ -29,25 +30,32 @@ describe Chef::Win32::Registry do let(:sub_key) {'OpscodePrimes'} let(:missing_key_path) {'HKCU\Software'} + before(:all) do + Win32::Registry = Class.new + Win32::Registry::Error = Class.new(RuntimeError) + end + before(:each) do allow_any_instance_of(Chef::Win32::Registry).to receive(:machine_architecture).and_return(:x86_64) @registry = Chef::Win32::Registry.new() #Making the values for registry constants available on unix - Object.send(:remove_const, 'Win32') if defined?(Win32) - Win32 = Module.new - Win32::Registry = Class.new Win32::Registry::KEY_SET_VALUE = 0x0002 Win32::Registry::KEY_QUERY_VALUE = 0x0001 Win32::Registry::KEY_WRITE = 0x00020000 | 0x0002 | 0x0004 Win32::Registry::KEY_READ = 0x00020000 | 0x0001 | 0x0008 | 0x0010 - Win32::Registry::Error = Class.new(RuntimeError) - @hive_mock = double("::Win32::Registry::HKEY_CURRENT_USER") @reg_mock = double("reg") end + after(:each) do + Win32::Registry.send(:remove_const, 'KEY_SET_VALUE') if defined?(Win32::Registry::KEY_SET_VALUE) + Win32::Registry.send(:remove_const, 'KEY_QUERY_VALUE') if defined?(Win32::Registry::KEY_QUERY_VALUE) + Win32::Registry.send(:remove_const, 'KEY_READ') if defined?(Win32::Registry::KEY_READ) + Win32::Registry.send(:remove_const, 'KEY_WRITE') if defined?(Win32::Registry::KEY_WRITE) + end + describe "get_values" do it "gets all values for a key if the key exists" do expect(@registry).to receive(:get_hive_and_key).with(key_path).and_return([@hive_mock, key]) |