Skip to content
Newer
Older
100644 105 lines (90 sloc) 2.02 KB
e001d62 @rkh adjust require lines for test helper, so it also works properly on 1.9.2
rkh authored May 11, 2011
1 require File.expand_path('../helper', __FILE__)
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored Dec 13, 2008
2
ff0d068 @sr Use contest instead of test/spec/mini
sr authored Mar 26, 2009
3 class ERBTest < Test::Unit::TestCase
b3e82c5 @rkh test both ERB and Erubis
rkh authored Apr 15, 2011
4 def engine
5 Tilt::ERBTemplate
6 end
7
8 def setup
9 Tilt.prefer engine, :erb
10 super
11 end
12
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored Dec 13, 2008
13 def erb_app(&block)
14 mock_app {
15 set :views, File.dirname(__FILE__) + '/views'
16 get '/', &block
17 }
18 get '/'
becd6d8 ERB in place
Blake Mizerany authored Feb 20, 2008
19 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored Aug 31, 2008
20
b3e82c5 @rkh test both ERB and Erubis
rkh authored Apr 15, 2011
21 it 'uses the correct engine' do
22 assert_equal engine, Tilt[:erb]
23 end
24
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored Dec 13, 2008
25 it 'renders inline ERB strings' do
26 erb_app { erb '<%= 1 + 1 %>' }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored Jan 14, 2009
27 assert ok?
28 assert_equal '2', body
becd6d8 ERB in place
Blake Mizerany authored Feb 21, 2008
29 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored Aug 31, 2008
30
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored Dec 13, 2008
31 it 'renders .erb files in views path' do
32 erb_app { erb :hello }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored Jan 14, 2009
33 assert ok?
34 assert_equal "Hello World\n", body
becd6d8 ERB in place
Blake Mizerany authored Feb 21, 2008
35 end
7d5bc1f Haml & Erb redo
Blake Mizerany authored Feb 27, 2008
36
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored Dec 13, 2008
37 it 'takes a :locals option' do
38 erb_app {
39 locals = {:foo => 'Bar'}
40 erb '<%= foo %>', :locals => locals
41 }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored Jan 14, 2009
42 assert ok?
43 assert_equal 'Bar', body
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored Dec 13, 2008
44 end
7d5bc1f Haml & Erb redo
Blake Mizerany authored Feb 28, 2008
45
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored Dec 13, 2008
46 it "renders with inline layouts" do
47 mock_app {
48 layout { 'THIS. IS. <%= yield.upcase %>!' }
49 get('/') { erb 'Sparta' }
50 }
51 get '/'
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored Jan 14, 2009
52 assert ok?
53 assert_equal 'THIS. IS. SPARTA!', body
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored Dec 13, 2008
54 end
7d5bc1f Haml & Erb redo
Blake Mizerany authored Feb 28, 2008
55
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored Dec 13, 2008
56 it "renders with file layouts" do
57 erb_app {
58 erb 'Hello World', :layout => :layout2
59 }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored Jan 14, 2009
60 assert ok?
8f76d3b @rkh fix erb test to work with erubis
rkh authored Apr 15, 2011
61 assert_body "ERB Layout!\nHello World"
7d5bc1f Haml & Erb redo
Blake Mizerany authored Feb 28, 2008
62 end
f3ed6e4 Allow helper methods to use blocks in erb views
Matias Käkelä authored Feb 18, 2009
63
64 it "renders erb with blocks" do
65 mock_app {
66 def container
67 @_out_buf << "THIS."
68 yield
69 @_out_buf << "SPARTA!"
70 end
71 def is; "IS." end
72 get '/' do
73 erb '<% container do %> <%= is %> <% end %>'
74 end
75 }
76 get '/'
77 assert ok?
78 assert_equal 'THIS. IS. SPARTA!', body
79 end
090c4d7 @rtomayko Fix weirdness with partials in ERB [#158]
rtomayko authored Feb 21, 2009
80
81 it "can be used in a nested fashion for partials and whatnot" do
82 mock_app {
83 template(:inner) { "<inner><%= 'hi' %></inner>" }
84 template(:outer) { "<outer><%= erb :inner %></outer>" }
85 get '/' do
86 erb :outer
87 end
88 }
89
90 get '/'
91 assert ok?
92 assert_equal '<outer><inner>hi</inner></outer>', body
93 end
becd6d8 ERB in place
Blake Mizerany authored Feb 21, 2008
94 end
b3e82c5 @rkh test both ERB and Erubis
rkh authored Apr 15, 2011
95
96
97 begin
98 require 'erubis'
99 class ErubisTest < ERBTest
100 def engine; Tilt::ErubisTemplate end
101 end
102 rescue LoadError
103 warn "#{$!.to_s}: skipping erubis tests"
104 end
Something went wrong with that request. Please try again.