Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 76 lines (62 sloc) 2.312 kB
b280796 @trans support for Radius templates
trans authored
1 require 'contest'
2 require 'tilt'
3
4 begin
851095e @rkh enable radius tests on 1.9 for radius >= 0.7
rkh authored
5 require 'radius'
6
daafed1 @rtomayko disable radius tests under ruby >= 1.9.1
authored
7 # Disable radius tests under Ruby versions >= 1.9.1 since it's still buggy.
8 # Remove when fixed upstream.
851095e @rkh enable radius tests on 1.9 for radius >= 0.7
rkh authored
9 raise LoadError if RUBY_VERSION >= "1.9.1" and Radius.version < "0.7"
b280796 @trans support for Radius templates
trans authored
10
11 class RadiusTemplateTest < Test::Unit::TestCase
12 test "registered for '.radius' files" do
13 assert_equal Tilt::RadiusTemplate, Tilt['test.radius']
14 end
15
16 test "preparing and evaluating templates on #render" do
17 template = Tilt::RadiusTemplate.new { |t| "Hello World!" }
18 assert_equal "Hello World!", template.render
19 end
20
94bde96 @rkh fix doupble render issue
rkh authored
21 test "can be rendered more than once" do
22 template = Tilt::RadiusTemplate.new { |t| "Hello World!" }
82def97 @rkh when testing multiple renders on the same template, also check output
rkh authored
23 3.times { assert_equal "Hello World!", template.render }
94bde96 @rkh fix doupble render issue
rkh authored
24 end
25
b280796 @trans support for Radius templates
trans authored
26 test "passing locals" do
27 template = Tilt::RadiusTemplate.new { "Hey <r:name />!" }
28 assert_equal "Hey Joe!", template.render(nil, :name => 'Joe')
29 end
30
31 class ExampleRadiusScope
32 def beer; 'wet'; end
33 def whisky; 'wetter'; end
34 end
35
36 test "combining scope and locals when scope responds" do
37 template = Tilt::RadiusTemplate.new {
38 'Beer is <r:beer /> but Whisky is <r:whisky />.'
39 }
40 scope = ExampleRadiusScope.new
41 assert_equal "Beer is wet but Whisky is wetter.", template.render(scope)
42 end
43
44 test "precedence when locals and scope define same variables" do
45 template = Tilt::RadiusTemplate.new {
46 'Beer is <r:beer /> but Whisky is <r:whisky />.'
47 }
48 scope = ExampleRadiusScope.new
49 assert_equal "Beer is great but Whisky is greater.",
50 template.render(scope, :beer => 'great', :whisky => 'greater')
51 end
52
c43c8d1 @trans add documentation for Radius and improve implementation
trans authored
53 #test "handles local scope" do
54 # beer = 'wet'
55 # whisky = 'wetter'
56 #
57 # template = Tilt::RadiusTemplate.new {
58 # 'Beer is <r:beer /> but Whisky is <r:whisky />.'
59 # }
60 # assert_equal "Beer is wet but Whisky is wetter.", template.render(self)
61 #end
62
b280796 @trans support for Radius templates
trans authored
63 test "passing a block for yield" do
64 template = Tilt::RadiusTemplate.new {
65 'Beer is <r:yield /> but Whisky is <r:yield />ter.'
66 }
67 assert_equal "Beer is wet but Whisky is wetter.",
68 template.render({}) { 'wet' }
69 end
70 end
71
72 rescue LoadError => boom
6005f55 @rtomayko why are we ending these warns with \n
authored
73 warn "Tilt::RadiusTemplate (disabled)"
b280796 @trans support for Radius templates
trans authored
74 end
75
Something went wrong with that request. Please try again.