From 7f15dbd2f3c9cddfed69c84f4f156e27fe32e9a9 Mon Sep 17 00:00:00 2001 From: Bryan McLellan Date: Mon, 24 Jun 2013 17:25:14 -0700 Subject: OHAI-126: Improve file regex to handle trailing slash --- lib/ohai/system.rb | 2 +- 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 -- cgit v1.2.1