From 524860a0ad575af60169b4651d95c25dbb4d7a6e Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Thu, 25 Oct 2012 16:03:24 -0700 Subject: [CHEF-3561] add template context for template errors ResourceFailureInspector will now notice TemplateErrors and use them to display the relevant lines from a template. --- .../resource_failure_inspector_spec.rb | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'chef/spec') diff --git a/chef/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb b/chef/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb index 54a57d8077..52c719d2fb 100644 --- a/chef/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +++ b/chef/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb @@ -34,7 +34,8 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do before do @description = Chef::Formatters::ErrorDescription.new("Error Converging Resource:") - @outputter = Chef::Formatters::Outputter.new(StringIO.new, STDERR) + @stdout = StringIO.new + @outputter = Chef::Formatters::Outputter.new(@stdout, STDERR) #@outputter = Chef::Formatters::Outputter.new(STDOUT, STDERR) Chef::Config.stub!(:cookbook_path).and_return([ "/var/chef/cache" ]) @@ -77,6 +78,35 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do @description.display(@outputter) end + describe "and the error is a template error" do + before do + @description = Chef::Formatters::ErrorDescription.new("Error Converging Resource:") + @template_class = Class.new { include Chef::Mixin::Template } + @template = @template_class.new + @context = {:chef => "cool"} + + @resource = template("/tmp/foo.txt") do + mode "0644" + end + + @error = begin + @template.render_template("foo\nbar\nbaz\n<%= this_is_not_defined %>\nquin\nqunx\ndunno", @context) {|r| r} + rescue Chef::Mixin::Template::TemplateError => e + e + end + + @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @error) + @inspector.add_explanation(@description) + end + + it "includes contextual info from the template error in the output" do + @description.display(@outputter) + @stdout.string.should include(@error.source_listing) + end + + + end + describe "recipe_snippet" do before do # fake code to run through #recipe_snippet -- cgit v1.2.1