From 71800b51f4a612eaa1283aa14e6c1e2c7885126b Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 9 Jul 2018 21:18:30 -0700 Subject: Account for directory being a string via client.rb 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 --- lib/ohai/system.rb | 3 ++- 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") -- cgit v1.2.1