$:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib") require 'rexml/xpath' require 'test/unit' require 'buildmaster' 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"))) end def test_should_initialize_with_content template_content = < BuildMaster Body CONTENT template = XTemplate.new(template_content) xml_output = template.process('') assert_equal('Body', REXML::XPath.first(xml_output, '/html/body').text) end def test_should_process_include_with_elements_attribute template_content = < BuildMaster - <template:include elements="/html/head/title/text()"/> INCLUDE_CONTENT source_content = < Page Title INCLUDE_SOURCE template = XTemplate.new(template_content) xml_output = REXML::Document.new(template.process(source_content).to_s) assert_equal('BuildMaster - Page Title', REXML::XPath.first(xml_output, '/html/head/title').text) end def test_should_process_when_with_select_value_attribute 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) xml_document = template.process(source_content) {|expression| return true} 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 test_should_not_process_when_if_select_false template_content = < BuildMaster<template:when test="index_file?"> - Index</template:when> INCLUDE_CONTENT source_content = < Page Title INCLUDE_SOURCE template = XTemplate.new(template_content) xml_document = template.process(source_content) {|expression| return false} xml_output = REXML::Document.new(xml_document.to_s()) assert_equal('BuildMaster', REXML::XPath.first(xml_output, '/html/head/title').text) end def test_should_process_attr_with_eval_attribute template_content = < BuildMaster INCLUDE_CONTENT source_content = < Page Title INCLUDE_SOURCE template = XTemplate.new(template_content) xml_document = template.process(source_content) {|expression| return 'http://svn.buildmaster/'} xml_output = REXML::Document.new(xml_document.to_s()) assert_equal('http://svn.buildmaster', REXML::XPath.first(xml_output, '/html/body/a/@href').text) end def test_should_process_text_with_eval_attribute template_content = < BuildMaster

INCLUDE_CONTENT source_content = < Page Title INCLUDE_SOURCE template = XTemplate.new(template_content) xml_document = template.process(source_content) {|expression| return 'release 0.0.1 (build 235)'} xml_output = REXML::Document.new(xml_document.to_s()) assert_equal('release 0.0.1 (build 235)', REXML::XPath.first(xml_output, '/html/body/h1').text) end def test_should_process_each_with_children template_content = < BuildMaster

Recent News

INCLUDE_CONTENT source_content = < Page Title INCLUDE_SOURCE template = XTemplate.new(template_content) xml_document = template.process(source_content) do |expression| < BuildMaster News http://buildmaster.rubyforge.org/ BuildMaster is a set of classes in Ruby to help easy the task of project building, releasing and website building en-us Tue, 09 May 2006 17:12:46 GMT http://buildmaster.rubyforge.org/logo.gif BuildMaster http://buildmaster.rubyforge.org/ BuildMaster website created http://buildmaster.rubyforge.org/ BuildMaster website has been created by its own script Documentation Sat, 27 May 2006 16:00:00 GMT XTemplate script created http://buildmaster.rubyforge.org XTemplate script has been created, following the ones that is currently being used for jBehave and jMock Development Wed, 05 Apr 2006 16:00:00 GMT BuildMaster code structure created http://buildmaster.rubyforge.org BuildMaster project structure has been created with according files so that a gem can be created and released onto rubyforge Development Sat, 08 Apr 2006 16:00:00 GMT BuildMaster moved from RubyBuilder RubyBuilder project has been deleted and renamed to BuildMaster to easy any confusion Development Sat, 01 Apr 2006 16:00:00 GMT NEWS end xml_output = REXML::Document.new(xml_document.to_s()) # puts xml_output assert_equal(3, REXML::XPath.match(xml_output, '/html/body/div/div').size) assert_equal('BuildMaster website created', REXML::XPath.first(xml_output, '/html/body/div/div[1]/p').text()) end end end