$:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib") require 'rexml/xpath' require 'test/unit' require 'buildmaster' require 'buildmaster/source_content' module BuildMaster class XTemplateTest < Test::Unit::TestCase protected def setup super end public def test_should_initialize_with_io template = BuildMaster::XTemplate.new(File.open(File.join(File.dirname(__FILE__), "template.xhtml")), Hash.new) end def test_should_initialize_with_content template_content = < BuildMaster Body CONTENT template = XTemplate.new(template_content, Hash.new) xml_output = template.process(SourceContent.new(Pathname.new('content'), '')) assert_equal('Body', REXML::XPath.first(xml_output, '/html/body').text) end def test_should_hook_up_templatelets template_content = < BuildMaster - <template:when test="index_file?">Index</template:when>
  • one
INCLUDE_CONTENT source_content = < Page Title INCLUDE_SOURCE template = XTemplate.new(template_content, load_templatelets) xml_document = template.process(SourceContent.new(nil, source_content)) xml_output = REXML::Document.new(xml_document.to_s()) assert_equal('BuildMaster - Index', REXML::XPath.first(xml_output, '/html/head/title').text) assert_equal('one', REXML::XPath.first(xml_output, '/html/body/ul/li').text) end def what?(path) return true end def index_file?(path) return true end def load_templatelets return {'when' => When.new(self, self)} end end end