require 'rubygems' require 'fileutils' require 'radius' require 'log4r' require_relative '../lib/depengine/processor/tags' require_relative '../lib/depengine/processor/template' require_relative '../lib/depengine/log/log' $log = Log::DeploymentLogger.new $log.writer.level = Log4r::ERROR describe "the templates mechanism" do it "should render a template from a string" do result = Processor::Template.parse(">Template< >Content<", {}) result.should include(">Template< >Content<") end it "should render a template from a file" do result = Processor::Template.parse('spec/templates/single.tpl', {}) result.should include(">Template< >Content<") end it "should create Tags from the content hash and provide it to the template" do content = {'parameter' => 'value'} result = Processor::Template.parse('spec/templates/single_hash.tpl', content) result.should include(">Template< >value<") end it "should create a directory structure in analogy to the source tree if a single file is given" do FileUtils.rm_rf 'spec/templates/generated/*' worker = Processor::Template.new worker.basepath = File.join(File.dirname(__FILE__), 'templates') worker.parse_template('base/sub1/single.tpl', {'parameter' => 'value'}, 'generated/') File.open("spec/templates/generated/base/sub1/single", 'r') do |line| line.gets.should include(">Template< >Content<") end end it "should create a directory structure in analogy to the source tree if a directory is given" do FileUtils.rm_rf 'spec/templates/generated/*' worker = Processor::Template.new worker.basepath = File.join(File.dirname(__FILE__), 'templates') worker.parse_template('base/sub2', {'parameter' => 'value'}, 'generated/') File.open("spec/templates/generated/base/sub2/multi2", 'r') do |line| line.gets.should include(">Template< >Content<") end end end