From c16c5046c5c62d86be74471e003dd44b4a2cb726 Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Tue, 26 Nov 2013 16:54:49 -0800 Subject: [PATCH] Remove access to ProvidesMap internal data structure Only test code was accessing this, modified to use the public API of the class. --- lib/ohai/provides_map.rb | 15 --------------- spec/ohai/dsl/plugin_spec.rb | 12 ++++++------ spec/unit/loader_spec.rb | 11 +++++------ spec/unit/plugins/fail_spec.rb | 3 ++- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/lib/ohai/provides_map.rb b/lib/ohai/provides_map.rb index bbf68fb0d..2f61f550e 100644 --- a/lib/ohai/provides_map.rb +++ b/lib/ohai/provides_map.rb @@ -73,21 +73,6 @@ def all_plugins collect_plugins_in(map, collected).uniq end - # TODO: change this to has_provider? or something domain specific. - def has_key?(key) - @map.has_key?(key) - end - - # TODO: refactor out direct access to the map (mostly only occurs in test code) - def [](key) - @map[key] - end - - # TODO: refactor out direct access to the map (mostly only occurs in test code) - def []=(key, value) - @map[key] = value - end - private def collect_plugins_in(provides_map, collected) diff --git a/spec/ohai/dsl/plugin_spec.rb b/spec/ohai/dsl/plugin_spec.rb index 37876fc3e..0fdb265ad 100644 --- a/spec/ohai/dsl/plugin_spec.rb +++ b/spec/ohai/dsl/plugin_spec.rb @@ -271,15 +271,16 @@ plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, "") plugin.provides("attribute") - @ohai.attributes.should have_key(:attribute) + #@ohai.attributes.should have_key(:attribute) + @ohai.attributes.find_providers_for(["attribute"]).should eq([plugin]) end it "should collect a list of attributes" do plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, "") plugin.provides("attr1", "attr2", "attr3") - [:attr1, :attr2, :attr3].each do |attr| - @ohai.attributes.should have_key(attr) + %w[attr1 attr2 attr3].each do |attr| + @ohai.attributes.find_providers_for([attr]).should eq([plugin]) end end @@ -287,8 +288,7 @@ plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, "") plugin.provides("attr/subattr") - @ohai.attributes.should have_key(:attr) - @ohai.attributes[:attr].should have_key(:subattr) + @ohai.attributes.find_providers_for(["attr/subattr"]).should eq([plugin]) end it "should collect all unique providers for an attribute" do @@ -299,7 +299,7 @@ plugins << p end - @ohai.attributes[:attribute][:_plugins].should eql(plugins) + @ohai.attributes.find_providers_for(["attribute"]).should =~ plugins end end diff --git a/spec/unit/loader_spec.rb b/spec/unit/loader_spec.rb index 2a6602227..c95bb12d2 100644 --- a/spec/unit/loader_spec.rb +++ b/spec/unit/loader_spec.rb @@ -53,7 +53,7 @@ test Mash.new EOF IO.stub(:read).with(@path).and_return(contents) - Ohai::Log.should_receive(:warn).with(/[DEPRECATION]/) + Ohai::Log.should_receive(:warn).with(/\[DEPRECATION\]/) plugin = @loader.load_plugin(@path, @v6name) plugin.version.should eql(:version6) end @@ -89,7 +89,7 @@ end EOF IO.stub(:read).with(@path).and_return(contents) - Ohai::Log.should_receive(:warn).with(/[UNSUPPORTED OPERATION]/) + Ohai::Log.should_receive(:warn).with(/\[UNSUPPORTED OPERATION\]/) @loader.load_plugin(@path) end end @@ -105,15 +105,14 @@ klass = Ohai.plugin(@name) { provides("attr") } plugin = klass.new(@ohai, @path) @loader.collect_provides(plugin) - @ohai.attributes.should have_key(:attr) + @ohai.attributes.find_providers_for(["attr"]).should eq([plugin]) end it "should add provided subattributes to Ohai" do klass = Ohai.plugin(@name) { provides("attr/sub") } plugin = klass.new(@ohai, @plath) @loader.collect_provides(plugin) - @ohai.attributes.should have_key(:attr) - @ohai.attributes[:attr].should have_key(:sub) + @ohai.attributes.find_providers_for([ "attr/sub" ]).should include(plugin) end it "should collect the unique providers for an attribute" do @@ -126,7 +125,7 @@ end plugins.each { |plugin| @loader.collect_provides(plugin) } - @ohai.attributes[:attr][:_plugins].should eql(plugins) + @ohai.attributes.find_providers_for(["attr"]).should =~ plugins end end end diff --git a/spec/unit/plugins/fail_spec.rb b/spec/unit/plugins/fail_spec.rb index 6603bcd37..17d8f84d3 100644 --- a/spec/unit/plugins/fail_spec.rb +++ b/spec/unit/plugins/fail_spec.rb @@ -55,7 +55,8 @@ it "should not have attribute keys" do @loader.load_plugin("#{tmp}/plugins/fail.rb") - @ohai.attributes.should_not have_key("fail") + #@ohai.attributes.should_not have_key("fail") + lambda { @ohai.attributes.find_providers_for(["fail"]) }.should raise_error(Ohai::Exceptions::AttributeNotFound) end it "should not have source key" do