Sha256: 6cd56e9609331230e42529c669ecd36f0da7d7d35f1588eb0649e56d213b3ecf
Contents?: true
Size: 1.42 KB
Versions: 9
Compression:
Stored size: 1.42 KB
Contents
require 'contest' require 'tilt' begin require 'builder' class BuilderTemplateTest < Test::Unit::TestCase test "registered for '.builder' files" do assert_equal Tilt::BuilderTemplate, Tilt['test.builder'] assert_equal Tilt::BuilderTemplate, Tilt['test.xml.builder'] end test "preparing and evaluating the template on #render" do template = Tilt::BuilderTemplate.new { |t| "xml.em 'Hello World!'" } assert_equal "<em>Hello World!</em>\n", template.render end test "passing locals" do template = Tilt::BuilderTemplate.new { "xml.em('Hey ' + name + '!')" } assert_equal "<em>Hey Joe!</em>\n", template.render(Object.new, :name => 'Joe') end test "evaluating in an object scope" do template = Tilt::BuilderTemplate.new { "xml.em('Hey ' + @name + '!')" } scope = Object.new scope.instance_variable_set :@name, 'Joe' assert_equal "<em>Hey Joe!</em>\n", template.render(scope) end test "passing a block for yield" do template = Tilt::BuilderTemplate.new { "xml.em('Hey ' + yield + '!')" } assert_equal "<em>Hey Joe!</em>\n", template.render { 'Joe' } end test "block style templates" do template = Tilt::BuilderTemplate.new do |t| lambda { |xml| xml.em('Hey Joe!') } end assert_equal "<em>Hey Joe!</em>\n", template.render end end rescue LoadError warn "Tilt::BuilderTemplate (disabled)" end
Version data entries
9 entries across 9 versions & 1 rubygems