spec/unit/application_spec.rb in chef-11.4.4 vs spec/unit/application_spec.rb in chef-11.6.0.hotfix.1
- old
+ new
@@ -181,11 +181,13 @@
Chef::Log.stub!(:init)
end
it "should initialise the chef logger" do
Chef::Log.stub!(:level=)
- Chef::Log.should_receive(:init).with(Chef::Config[:log_location]).and_return(true)
+ @monologger = mock("Monologger")
+ MonoLogger.should_receive(:new).with(Chef::Config[:log_location]).and_return(@monologger)
+ Chef::Log.should_receive(:init).with(@monologger)
@app.configure_logging
end
it "should initialise the chef logger level" do
Chef::Log.should_receive(:level=).with(Chef::Config[:log_level]).and_return(true)
@@ -238,11 +240,10 @@
Chef::Log.level.should == :warn
end
end
end
-
end
end
describe "class method: fatal!" do
before do
@@ -287,8 +288,62 @@
@app = Chef::Application.new
end
it "should raise an error" do
lambda { @app.run_application }.should raise_error(Chef::Exceptions::Application)
+ end
+ end
+
+ describe "configuration errors" do
+ before do
+ Process.stub!(:exit).and_return(true)
+ end
+
+ def raises_informative_fatals_on_configure_chef
+ config_file_regexp = Regexp.new @app.config[:config_file]
+ Chef::Log.should_receive(:fatal).with(config_file_regexp).and_return(true)
+ @app.configure_chef
+ end
+
+ def warns_informatively_on_configure_chef
+ config_file_regexp = Regexp.new @app.config[:config_file]
+ Chef::Log.should_receive(:warn).at_least(:once).with(config_file_regexp).and_return(true)
+ Chef::Log.should_receive(:warn).any_number_of_times.and_return(true)
+ @app.configure_chef
+ end
+
+ it "should warn for bad config file path" do
+ @app.config[:config_file] = "/tmp/non-existing-dir/file"
+ warns_informatively_on_configure_chef
+ end
+
+ it "should raise informative fatals for bad config file url" do
+ non_existing_url = "http://its-stubbed.com/foo.rb"
+ @app.config[:config_file] = non_existing_url
+ Chef::REST.any_instance.stub(:fetch).with(non_existing_url).and_raise(SocketError)
+ raises_informative_fatals_on_configure_chef
+ end
+
+ describe "when config file exists but contains errors" do
+ def create_config_file(text)
+ @config_file = Tempfile.new("rspec-chef-config")
+ @config_file.write(text)
+ @config_file.close
+ @app.config[:config_file] = @config_file.path
+ end
+
+ after(:each) do
+ @config_file.unlink
+ end
+
+ it "should raise informative fatals for missing log file dir" do
+ create_config_file('log_location "/tmp/non-existing-dir/logfile"')
+ raises_informative_fatals_on_configure_chef
+ end
+
+ it "should raise informative fatals for badly written config" do
+ create_config_file("text that should break the config parsing")
+ raises_informative_fatals_on_configure_chef
+ end
end
end
end