test/buildmaster/tc_xtemplate.rb in BuildMaster-0.6.0 vs test/buildmaster/tc_xtemplate.rb in BuildMaster-0.7.0

- old
+ new

@@ -165,11 +165,11 @@ 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 = <<INCLUDE_CONTENT <html xmlns="http://www.w3.org/1999/xhtml" xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0"> <head> @@ -245,12 +245,55 @@ </channel> </rss> 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 + + def test_should_process_link_element_to_anchor_with_relative_path_when_not_current_page + template_content = <<CONTENT +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0"> + <head> + <title>BuildMaster</title> + </head> + <body><template:link href="/dir/file" class="value">File</template:link></body> +</html> +CONTENT + template = XTemplate.new(template_content) + xml_output = template.process('') do |expression| + assert_equal('relative_to_root', expression) + Pathname.new('hello.textile') + end + actual_element = REXML::XPath.first(xml_output, '/html/body/a') + assert_equal('dir/file', actual_element.attributes['href']) + assert_equal('value', actual_element.attributes['class']) + assert_equal('File', actual_element.text) + end + + def test_should_process_link_element_to_div_when_on_current_page + template_content = <<CONTENT +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0"> + <head> + <title>BuildMaster</title> + </head> + <body><template:link href="/dir/file.html" class="value">File</template:link></body> +</html> +CONTENT + template = XTemplate.new(template_content) + xml_output = template.process('') do |expression| + assert_equal('relative_to_root', expression) + Pathname.new('dir/file.textile') + end + actual_element = REXML::XPath.first(xml_output, '/html/body/div') + assert_equal(nil, actual_element.attributes['href']) + assert_equal('value', actual_element.attributes['class']) + assert_equal('File', actual_element.text) + end + + end end