diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-10-10 23:34:15 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-10-10 23:34:15 -0700 |
commit | ed9fdcb3e1f0e40f88f74a538c64981c29d74b66 (patch) | |
tree | d6ca985be19c3821c6279012294eabfd85f34b9d | |
parent | 0fb570467abd6bc19871fa0373d0201c1432ecc5 (diff) | |
parent | 0b0eef02c7f5b0200ffbda60811e7bf4fa99bab0 (diff) | |
download | chef-ed9fdcb3e1f0e40f88f74a538c64981c29d74b66.tar.gz |
Merge pull request #2207 from opscode/sersut/rebase-chef-1971
Rebase CHEF-1971: Report a more appropriate error when no recipe is given
-rw-r--r-- | lib/chef/application/apply.rb | 18 | ||||
-rw-r--r-- | spec/spec_helper.rb | 4 | ||||
-rw-r--r-- | spec/unit/application/apply_spec.rb (renamed from spec/unit/application/apply.rb) | 18 |
3 files changed, 27 insertions, 13 deletions
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb index ea9154c6f2..22d835e876 100644 --- a/lib/chef/application/apply.rb +++ b/lib/chef/application/apply.rb @@ -31,7 +31,6 @@ class Chef::Application::Apply < Chef::Application banner "Usage: chef-apply [RECIPE_FILE] [-e RECIPE_TEXT] [-s]" - option :execute, :short => "-e RECIPE_TEXT", :long => "--execute RECIPE_TEXT", @@ -92,14 +91,17 @@ class Chef::Application::Apply < Chef::Application end def read_recipe_file(file_name) - recipe_path = file_name - unless File.exist?(recipe_path) - Chef::Application.fatal!("No file exists at #{recipe_path}", 1) + if file_name.nil? + Chef::Application.fatal!("No recipe file was provided", 1) + else + recipe_path = File.expand_path(file_name) + unless File.exist?(recipe_path) + Chef::Application.fatal!("No file exists at #{recipe_path}", 1) + end + recipe_fh = open(recipe_path) + recipe_text = recipe_fh.read + [recipe_text, recipe_fh] end - recipe_path = File.expand_path(recipe_path) - recipe_fh = open(recipe_path) - recipe_text = recipe_fh.read - [recipe_text, recipe_fh] end def get_recipe_and_run_context diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1760aab871..e282a88100 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -162,6 +162,10 @@ RSpec.configure do |config| config.before(:each) do Chef::Config.reset end + + config.before(:suite) do + ARGV.clear + end end require 'webrick/utils' diff --git a/spec/unit/application/apply.rb b/spec/unit/application/apply_spec.rb index 62a53c2a31..e29c038340 100644 --- a/spec/unit/application/apply.rb +++ b/spec/unit/application/apply_spec.rb @@ -35,24 +35,32 @@ describe Chef::Application::Apply do describe "read_recipe_file" do before do @recipe_file_name = "foo.rb" - @recipe_path = File.expand_path("foo.rb") + @recipe_path = File.expand_path(@recipe_file_name) @recipe_file = double("Tempfile (mock)", :read => @recipe_text) @app.stub(:open).with(@recipe_path).and_return(@recipe_file) - File.stub(:exist?).with("foo.rb").and_return(true) + File.stub(:exist?).with(@recipe_path).and_return(true) Chef::Application.stub(:fatal!).and_return(true) end + it "should read text properly" do @app.read_recipe_file(@recipe_file_name)[0].should == @recipe_text end it "should return a file_handle" do @app.read_recipe_file(@recipe_file_name)[1].should be_instance_of(RSpec::Mocks::Mock) end + + describe "when recipe is nil" do + it "should raise a fatal with the missing filename message" do + Chef::Application.should_receive(:fatal!).with("No recipe file was provided", 1) + @app.read_recipe_file(nil) + end + end describe "when recipe doesn't exist" do before do - File.stub(:exist?).with(@recipe_file_name).and_return(false) + File.stub(:exist?).with(@recipe_path).and_return(false) end - it "should raise a fatal" do - Chef::Application.should_receive(:fatal!) + it "should raise a fatal with the file doesn't exist message" do + Chef::Application.should_receive(:fatal!).with(/^No file exists at/, 1) @app.read_recipe_file(@recipe_file_name) end end |