Sha256: 3184d0811fbc38a437f906063fe96c5b616fe8b2d620c28c2e918e8ae0249748

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")

require 'rexml/xpath'
require 'rexml/document'
require 'test/unit'
require 'buildmaster/template_runner'

module BuildMaster
  class TemplateRunnerTest < Test::Unit::TestCase
    def test_process_element_in_document
      target_content = <<END
<html>
  <h1/>
</html>
END
      template_content = <<END
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
<p>
  <template:include elements="./name/text()"/>
</p>      
</html>
END
      source_content = <<END
<persons>
  <person id="1"><name>Name One</name></person>
  <person id="2"><name>Name Two</name></person>
</persons>
END
      target_xml = REXML::Document.new(target_content)
      target_element = REXML::XPath.first(target_xml, '/html/h1')
      template_element = REXML::XPath.first(REXML::Document.new(template_content), "/html/p")
      source_xml = REXML::Document.new(source_content)
      source_element = REXML::XPath.first(source_xml, '/persons/person[@id="1"]')
      runner = TemplateRunner.new(target_element, template_element, source_element)
      runner.process
      assert_equal('Name One', REXML::XPath.first(REXML::Document.new(target_xml.to_s), '/html/h1/text()').value.strip)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
BuildMaster-0.7.0 test/buildmaster/tc_template_runner.rb