diff options
author | Bryan McLellan <btm@opscode.com> | 2013-06-24 17:25:14 -0700 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2013-06-24 20:40:30 -0400 |
commit | 7f15dbd2f3c9cddfed69c84f4f156e27fe32e9a9 (patch) | |
tree | 4083f68de4102d19e7392e8a5325c608a22d5bc1 | |
parent | 45846ce59dd89b74c3b992d424a0b07d61b1f9f7 (diff) | |
download | ohai-7f15dbd2f3c9cddfed69c84f4f156e27fe32e9a9.tar.gz |
OHAI-126: Improve file regex to handle trailing slashOHAI-126
-rw-r--r-- | lib/ohai/system.rb | 2 | ||||
-rw-r--r-- | spec/unit/system_spec.rb | 20 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index 6526f3f4..8721be32 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -133,7 +133,7 @@ module Ohai 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, "::") diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb index 16df83d3..fcaf8b74 100644 --- a/spec/unit/system_spec.rb +++ b/spec/unit/system_spec.rb @@ -114,7 +114,7 @@ describe Ohai::System, "require_plugin" do @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) @@ -136,3 +136,21 @@ describe Ohai::System, "require_plugin" do 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 |