test/buildmaster/tc_xtemplate.rb in BuildMaster-0.8.1 vs test/buildmaster/tc_xtemplate.rb in BuildMaster-0.9.0
- old
+ new
@@ -1,41 +1,55 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
require 'rexml/xpath'
-require 'test/unit'
+require 'spec'
require 'buildmaster'
require 'buildmaster/source_content'
+require 'buildmaster/cotta'
+require 'buildmaster/cotta/in_memory_system'
module BuildMaster
- class XTemplateTest < Test::Unit::TestCase
- protected
- def setup
- super
- end
+
+context 'XTemplate' do
+ setup do
+ @cotta = Cotta.new(InMemorySystem.new)
+ end
+
+ specify 'should_initialize_with_io' do
+ template_file = @cotta.file('template.xhtml')
+ template_file.save <<CONTENT
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:template="http://buildmaster.rubyforge.org/xemplate/1.0">
+ <head>
+ <title>JBehave - <template:include elements="/html/head/title/text()"/></title>
+ <template:include elements="/html/head/*[not(name()='title')]"/>
+ </head>
+
+ <body>
+ </body>
+</html>
+CONTENT
+ template = template_file.read {|file| BuildMaster::XTemplate.new(file, Hash.new)}
+ 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 = <<CONTENT
+ specify 'should_initialize_with_content' do
+ 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>Body</body>
</html>
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
+ template = XTemplate.new(template_content, Hash.new)
+ xml_output = template.process(SourceContent.new(Pathname.new('content'), ''))
+ REXML::XPath.first(xml_output, '/html/body').text.should_equal 'Body'
+ end
- def test_should_hook_up_templatelets
- template_content = <<INCLUDE_CONTENT
+ specify 'should_hook_up_templatelets' do
+ template_content = <<INCLUDE_CONTENT
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
<head>
<title>BuildMaster - <template:when test="index_file?">Index</template:when></title>
</head>
@@ -46,34 +60,34 @@
</ul>
</template:when>
</body>
</html>
INCLUDE_CONTENT
- source_content = <<INCLUDE_SOURCE
+ source_content = <<INCLUDE_SOURCE
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Page Title</title></head>
<body></body>
</html>
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
+ 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())
+ REXML::XPath.first(xml_output, '/html/head/title').text.should_equal 'BuildMaster - Index'
+ REXML::XPath.first(xml_output, '/html/body/ul/li').text.should_equal 'one'
+ 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
+ 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