diff options
author | Tim Smith <tsmith@chef.io> | 2018-07-09 21:18:30 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-07-09 21:18:30 -0700 |
commit | 71800b51f4a612eaa1283aa14e6c1e2c7885126b (patch) | |
tree | 775511e4b4fb7dac5ec174a9e9f2b842415b50f7 | |
parent | 0c3e7c0cd5fa8796b75d1280480f1cc781586148 (diff) | |
download | ohai-multiple_dirs.tar.gz |
Account for directory being a string via client.rbmultiple_dirs
Make sure it's an array before we .each it and add a spec that passes it as a string
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/ohai/system.rb | 3 | ||||
-rw-r--r-- | spec/unit/system_spec.rb | 12 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index f13d89e4..7d5d973e 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -178,7 +178,8 @@ module Ohai # add any additional CLI passed directories to the plugin path excluding duplicates unless Ohai.config[:directory].nil? - Ohai.config[:directory].each do |dir| + # make sure the directory config is an array since it could be a string set in client.rb + Array(Ohai.config[:directory]).each do |dir| next if Ohai.config[:plugin_path].include?(dir) Ohai.config[:plugin_path] << dir end diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb index c6fe8ac3..a5b58232 100644 --- a/spec/unit/system_spec.rb +++ b/spec/unit/system_spec.rb @@ -47,10 +47,20 @@ describe "Ohai::System" do end end + context "when a single directory is configured as a string" do + let(:directory) { "/some/fantastic/plugins" } + + it "adds directory to plugin_path" do + Ohai.config[:directory] = directory + Ohai::System.new({ invoked_from_cli: true }) + expect(Ohai.config[:plugin_path]).to include("/some/fantastic/plugins") + end + end + context "when multiple directories are configured" do let(:directory) { ["/some/fantastic/plugins", "/some/other/plugins"] } - it "adds directory to plugin_path" do + it "adds directories to plugin_path" do Ohai.config[:directory] = directory Ohai::System.new({ invoked_from_cli: true }) expect(Ohai.config[:plugin_path]).to include("/some/fantastic/plugins") |