summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-10-10 13:42:02 -0700
committerSerdar Sutay <serdar@opscode.com>2014-10-10 13:42:02 -0700
commit0b0eef02c7f5b0200ffbda60811e7bf4fa99bab0 (patch)
treeee7c015eda2307453db463d7c867cef459fc138b
parentfa6e449b9e01cb4c2c145c1dac6ff054910dc12d (diff)
parent75fa6a4bfcdb9f413779cf11c9caace4e433df0c (diff)
downloadchef-sersut/rebase-chef-1971.tar.gz
Merge branch 'patch-1' of github.com:workmad3/chef into sersut/rebase-chef-1971sersut/rebase-chef-1971
-rw-r--r--lib/chef/application/apply.rb18
-rw-r--r--spec/spec_helper.rb4
-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