summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/application/apply.rb18
-rw-r--r--spec/unit/application/apply_spec.rb (renamed from spec/unit/application/apply.rb)13
2 files changed, 21 insertions, 10 deletions
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb
index f2dd2cb586..7e5d5406c0 100644
--- a/lib/chef/application/apply.rb
+++ b/lib/chef/application/apply.rb
@@ -92,14 +92,18 @@ class Chef::Application::Apply < Chef::Application
end
def read_recipe_file(file_name)
- recipe_path = file_name.to_s
- 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_name
+ unless File.exist?(recipe_path)
+ Chef::Application.fatal!("No file exists at #{recipe_path}", 1)
+ end
+ recipe_path = File.expand_path(recipe_path)
+ 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/unit/application/apply.rb b/spec/unit/application/apply_spec.rb
index 32c98c6ed6..3f7fb851c2 100644
--- a/spec/unit/application/apply.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -20,7 +20,7 @@ require 'spec_helper'
describe Chef::Application::Apply do
before do
- @app = Chef::Application::Recipe.new
+ @app = Chef::Application::Apply.new
@app.stub(:configure_logging).and_return(true)
@recipe_text = "package 'nyancat'"
Chef::Config[:solo] = true
@@ -41,18 +41,25 @@ describe Chef::Application::Apply do
File.stub(:exist?).with("foo.rb").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)
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