Skip to content

Commit

Permalink
OHAI-126: Improve file regex to handle trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
btm committed Jun 25, 2013
1 parent 45846ce commit 7f15dbd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ohai/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def all_plugins
Dir[File.join(path, '*')],
Dir[File.join(path, @data[:os], '**', '*')]
].flatten.each do |file|
file_regex = Regexp.new("#{path}#{File::SEPARATOR}(.+).rb$")
file_regex = Regexp.new("#{File.expand_path(path)}#{File::SEPARATOR}(.+).rb$")
md = file_regex.match(file)
if md
plugin_name = md[1].gsub(File::SEPARATOR, "::")
Expand Down
20 changes: 19 additions & 1 deletion spec/unit/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
@ohai.should_receive(:from_file).with(File.expand_path("#{tmp}/plugins/foo.rb")).and_return(true)
@ohai.require_plugin("foo")
end

it "should add a found plugin to the list of seen plugins" do
@ohai.require_plugin("foo")
@ohai.seen_plugins["foo"].should eql(true)
Expand All @@ -136,3 +136,21 @@
end
end

describe Ohai::System, "all_plugins" do
before(:each) do
@ohai = Ohai::System.new
@ohai.stub!(:from_file).and_return(true)
@ohai.stub!(:require_plugin).and_return(false)
@ohai.data[:os] = "ubuntu"
end

it "should load plugins when plugin_path has a trailing slash" do
Ohai::Config[:plugin_path] = ["/tmp/plugins/"]
File.stub(:expand_path).with("/tmp/plugins/").and_return("/tmp/plugins") # windows
Dir.should_receive(:[]).with("/tmp/plugins/*").and_return(["/tmp/plugins/darius.rb"])
Dir.should_receive(:[]).with("/tmp/plugins/ubuntu/**/*").and_return([])
@ohai.should_receive(:require_plugin).with("darius")
@ohai.all_plugins
end

end

0 comments on commit 7f15dbd

Please sign in to comment.