summaryrefslogtreecommitdiff
path: root/spec/unit/mixin/template_spec.rb
diff options
context:
space:
mode:
authorAndrea Campi <andrea.campi@zephirworks.com>2012-11-18 22:43:55 +0100
committerBryan McLellan <btm@opscode.com>2012-12-14 11:10:28 -0800
commit5509897b9f0a536f6b3768f28f569d450ff53232 (patch)
treebffca25f527cb77c67c367c3146f031e87d25ef6 /spec/unit/mixin/template_spec.rb
parentd4b4bd7b658d36d1363879e269963bbbe8089663 (diff)
downloadchef-5509897b9f0a536f6b3768f28f569d450ff53232.tar.gz
[CHEF-3249] Basic implementation of partials in templates.
Diffstat (limited to 'spec/unit/mixin/template_spec.rb')
-rw-r--r--spec/unit/mixin/template_spec.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/unit/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb
index 3d8a723a75..ebe46cbca4 100644
--- a/spec/unit/mixin/template_spec.rb
+++ b/spec/unit/mixin/template_spec.rb
@@ -44,6 +44,47 @@ describe Chef::Mixin::Template, "render_template" do
end
end
+ describe "with a template resource" do
+ before :each do
+ @cookbook_repo = File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks"))
+ Chef::Cookbook::FileVendor.on_create { |manifest| Chef::Cookbook::FileSystemFileVendor.new(manifest, @cookbook_repo) }
+
+ @node = Chef::Node.new
+ cl = Chef::CookbookLoader.new(@cookbook_repo)
+ cl.load_cookbooks
+ @cookbook_collection = Chef::CookbookCollection.new(cl)
+ @events = Chef::EventDispatch::Dispatcher.new
+ @run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
+
+ @rendered_file_location = Dir.tmpdir + '/openldap_stuff.conf'
+
+ @resource = Chef::Resource::Template.new(@rendered_file_location)
+ @resource.cookbook_name = 'openldap'
+
+ @provider = Chef::Provider::Template.new(@resource, @run_context)
+ @current_resource = @resource.dup
+ @provider.current_resource = @current_resource
+ @access_controls = mock("access controls")
+ @provider.stub!(:access_controls).and_return(@access_controls)
+ end
+
+ it "should provide a render method" do
+ _run_context = @run_context
+ context = {}
+ context[:node] = @node
+ context[:partial_resolver] = lambda do |partial_name|
+ @provider.instance_eval do
+ cookbook = run_context.cookbook_collection[resource_cookbook]
+ partial_location = cookbook.preferred_filename_on_disk_location(node, :templates, partial_name)
+ end
+ end
+
+ @provider.render_template("before {<%= render 'test.erb' %>} after", context) do |tmp|
+ tmp.open.read.should == "before {We could be diving for pearls!\n} after"
+ end
+ end
+ end
+
describe "when an exception is raised in the template" do
def do_raise
@context = {:chef => "cool"}