# # Author:: Adam Jacob () # Author:: Claire McQuin () # Copyright:: Copyright (c) 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_relative "../spec_helper.rb" require "ohai/mixin/os" describe "Ohai::System" do extend IntegrationSupport let(:ohai_external) {} let(:ohai) { Ohai::System.new({ invoked_from_cli: true }) } describe "#initialize" do it "returns an Ohai::System object" do expect(ohai).to be_a_kind_of(Ohai::System) end it "sets @attributes to a ProvidesMap" do expect(ohai.provides_map).to be_a_kind_of(Ohai::ProvidesMap) end it "sets @v6_dependency_solver to a Hash" do expect(ohai.v6_dependency_solver).to be_a_kind_of(Hash) end it "merges provided configuration options into the ohai config context" do config = { disabled_plugins: [ :Foo, :Baz ], directory: "/some/extra/plugins", critical_plugins: [ :Foo, :Bar ], } Ohai::System.new(config) config.each do |option, value| expect(Ohai.config[option]).to eq(value) end end context "when directory is configured" 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(directory) end end context "when testing the intializer that does way too much" do it "configures logging" do log_level = :debug Ohai.config[:log_level] = log_level expect(Ohai::Log).to receive(:level=).with(log_level) Ohai::System.new({ invoked_from_cli: true }) end it "resolves log_level when set to :auto" do expect(Ohai::Log).to receive(:level=).with(:info) Ohai::System.new({ invoked_from_cli: true }) end context "when called externally" do it "does not configure logging" do log_level = :debug Ohai.config[:log_level] = log_level expect(Ohai::Log).not_to receive(:level=).with(log_level) Ohai::System.new end it "does not resolve log_level when set to :auto" do expect(Ohai::Log).not_to receive(:level=).with(:info) Ohai::System.new end end end end when_plugins_directory "contains v6 and v7 plugins" do with_plugin("zoo.rb", <