Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

67 lines (55 sloc) 1.949 kb
require 'contest'
require 'tilt'
begin
require 'radius'
class RadiusTemplateTest < Test::Unit::TestCase
test "registered for '.radius' files" do
assert_equal Tilt::RadiusTemplate, Tilt['test.radius']
end
test "preparing and evaluating templates on #render" do
template = Tilt::RadiusTemplate.new { |t| "Hello World!" }
assert_equal "Hello World!", template.render
end
test "passing locals" do
template = Tilt::RadiusTemplate.new { "Hey <r:name />!" }
assert_equal "Hey Joe!", template.render(nil, :name => 'Joe')
end
class ExampleRadiusScope
def beer; 'wet'; end
def whisky; 'wetter'; end
end
test "combining scope and locals when scope responds" do
template = Tilt::RadiusTemplate.new {
'Beer is <r:beer /> but Whisky is <r:whisky />.'
}
scope = ExampleRadiusScope.new
assert_equal "Beer is wet but Whisky is wetter.", template.render(scope)
end
test "precedence when locals and scope define same variables" do
template = Tilt::RadiusTemplate.new {
'Beer is <r:beer /> but Whisky is <r:whisky />.'
}
scope = ExampleRadiusScope.new
assert_equal "Beer is great but Whisky is greater.",
template.render(scope, :beer => 'great', :whisky => 'greater')
end
#test "handles local scope" do
# beer = 'wet'
# whisky = 'wetter'
#
# template = Tilt::RadiusTemplate.new {
# 'Beer is <r:beer /> but Whisky is <r:whisky />.'
# }
# assert_equal "Beer is wet but Whisky is wetter.", template.render(self)
#end
test "passing a block for yield" do
template = Tilt::RadiusTemplate.new {
'Beer is <r:yield /> but Whisky is <r:yield />ter.'
}
assert_equal "Beer is wet but Whisky is wetter.",
template.render({}) { 'wet' }
end
end
rescue LoadError => boom
warn "Tilt::RadiusTemplate (disabled)\n"
end
Jump to Line
Something went wrong with that request. Please try again.