# # Author:: Claire McQuin () # Copyright:: Copyright (c) 2013 Opscode, 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 File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') describe Ohai::Loader do extend IntegrationSupport before(:each) do @plugin_data = Mash.new @provides_map = Ohai::ProvidesMap.new @ohai = double('Ohai::System', :data => @plugin_data, :provides_map => @provides_map) @loader = Ohai::Loader.new(@ohai) end describe "#initialize" do it "should return an Ohai::Loader object" do loader = Ohai::Loader.new(@ohai) expect(loader).to be_a_kind_of(Ohai::Loader) end end when_plugins_directory "contains both V6 & V7 plugins" do with_plugin("zoo.rb", <:/) @loader.load_plugin(path_to("extra_s.rb")) end it "should not raise an error" do expect{ @loader.load_plugin(path_to("extra_s.rb")) }.not_to raise_error end end describe "when the plugin tries to call an unexisting method" do it "shoud log an unsupported operation warning" do expect(Ohai::Log).to receive(:warn).with(/Plugin Method Error: <#{path_to("no_method.rb")}>:/) @loader.load_plugin(path_to("no_method.rb")) end it "should not raise an error" do expect{ @loader.load_plugin(path_to("no_method.rb")) }.not_to raise_error end end describe "when the plugin defines collect_data on the same platform more than once" do it "shoud log an illegal plugin definition warning" do expect(Ohai::Log).to receive(:warn).with(/Plugin Definition Error: <#{path_to("illegal_def.rb")}>:/) @loader.load_plugin(path_to("illegal_def.rb")) end it "should not raise an error" do expect{ @loader.load_plugin(path_to("illegal_def.rb")) }.not_to raise_error end end describe "when an unexpected error is encountered" do it "should log a warning" do expect(Ohai::Log).to receive(:warn).with(/Plugin Error: <#{path_to("unexpected_error.rb")}>:/) @loader.load_plugin(path_to("unexpected_error.rb")) end it "should not raise an error" do expect{ @loader.load_plugin(path_to("unexpected_error.rb")) }.not_to raise_error end end describe "when the plugin name symbol has bad syntax" do it "should log a syntax error warning" do expect(Ohai::Log).to receive(:warn).with(/Plugin Syntax Error: <#{path_to("bad_symbol.rb")}>:/) @loader.load_plugin(path_to("bad_symbol.rb")) end it "should not raise an error" do expect{ @loader.load_plugin(path_to("bad_symbol.rb")) }.not_to raise_error end end describe "when the plugin forgets an 'end'" do it "should log a syntax error warning" do expect(Ohai::Log).to receive(:warn).with(/Plugin Syntax Error: <#{path_to("no_end.rb")}>:/) @loader.load_plugin(path_to("no_end.rb")) end it "should not raise an error" do expect{ @loader.load_plugin(path_to("no_end.rb")) }.not_to raise_error end end describe "when the plugin has an invalid name" do it "should log an invalid plugin name warning" do expect(Ohai::Log).to receive(:warn).with(/Plugin Name Error: <#{path_to("bad_name.rb")}>:/) @loader.load_plugin(path_to("bad_name.rb")) end it "should not raise an error" do expect{ @loader.load_plugin(path_to("bad_name.rb")) }.not_to raise_error end end end end end