diff options
author | Yoni Yalovitsky <yoni@fewbytes.com> | 2013-05-19 17:19:18 +0300 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-06-18 09:05:28 -0700 |
commit | a11b6e98c5ab975bb918ce86d35eadf1fbae4683 (patch) | |
tree | 606de19e5c0e9fa68aab2a911b6c24c9540eba02 /spec/unit/application_spec.rb | |
parent | 6776b22d717acd3af9e1c018c8aaf842c1bc23b4 (diff) | |
download | chef-a11b6e98c5ab975bb918ce86d35eadf1fbae4683.tar.gz |
added tests for CHEF-4115
Diffstat (limited to 'spec/unit/application_spec.rb')
-rw-r--r-- | spec/unit/application_spec.rb | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 4ec9112c4f..f3df8c14cd 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -242,7 +242,6 @@ describe Chef::Application do end end - end end @@ -293,4 +292,58 @@ describe Chef::Application 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 |