Skip to content

Commit

Permalink
Remove access to ProvidesMap internal data structure
Browse files Browse the repository at this point in the history
Only test code was accessing this, modified to use the public API of the
class.
  • Loading branch information
danielsdeleo committed Dec 4, 2013
1 parent 93967ce commit c16c504
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
15 changes: 0 additions & 15 deletions lib/ohai/provides_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions spec/ohai/dsl/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,24 +271,24 @@
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

it "should collect subattributes of an attribute" do
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
Expand All @@ -299,7 +299,7 @@
plugins << p
end

@ohai.attributes[:attribute][:_plugins].should eql(plugins)
@ohai.attributes.find_providers_for(["attribute"]).should =~ plugins
end
end

Expand Down
11 changes: 5 additions & 6 deletions spec/unit/loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion spec/unit/plugins/fail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c16c504

Please sign in to comment.