Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 105 lines (90 sloc) 2.067 kb
e001d62 Konstantin Haase adjust require lines for test helper, so it also works properly on 1.9.2
rkh authored
1 require File.expand_path('../helper', __FILE__)
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
2
ff0d068 Simon Rozet Use contest instead of test/spec/mini
sr authored
3 class ERBTest < Test::Unit::TestCase
b3e82c5 Konstantin Haase test both ERB and Erubis
rkh authored
4 def engine
5 Tilt::ERBTemplate
6 end
7
8 def setup
9 Tilt.prefer engine, :erb
10 super
11 end
12
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
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
19 end
60d5006 Ryan Tomayko Fix whitespace errors across all source files and tests
rtomayko authored
20
b3e82c5 Konstantin Haase test both ERB and Erubis
rkh authored
21 it 'uses the correct engine' do
22 assert_equal engine, Tilt[:erb]
23 end
24
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
25 it 'renders inline ERB strings' do
26 erb_app { erb '<%= 1 + 1 %>' }
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
27 assert ok?
28 assert_equal '2', body
becd6d8 ERB in place
Blake Mizerany authored
29 end
60d5006 Ryan Tomayko Fix whitespace errors across all source files and tests
rtomayko authored
30
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
31 it 'renders .erb files in views path' do
32 erb_app { erb :hello }
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
33 assert ok?
34 assert_equal "Hello World\n", body
becd6d8 ERB in place
Blake Mizerany authored
35 end
7d5bc1f Haml & Erb redo
Blake Mizerany authored
36
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
37 it 'takes a :locals option' do
38 erb_app {
39 locals = {:foo => 'Bar'}
40 erb '<%= foo %>', :locals => locals
41 }
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
42 assert ok?
43 assert_equal 'Bar', body
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
44 end
7d5bc1f Haml & Erb redo
Blake Mizerany authored
45
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
46 it "renders with inline layouts" do
47 mock_app {
48 layout { 'THIS. IS. <%= yield.upcase %>!' }
49 get('/') { erb 'Sparta' }
50 }
51 get '/'
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
52 assert ok?
53 assert_equal 'THIS. IS. SPARTA!', body
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
54 end
7d5bc1f Haml & Erb redo
Blake Mizerany authored
55
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
56 it "renders with file layouts" do
57 erb_app {
58 erb 'Hello World', :layout => :layout2
59 }
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
60 assert ok?
8f76d3b Konstantin Haase fix erb test to work with erubis
rkh authored
61 assert_body "ERB Layout!\nHello World"
7d5bc1f Haml & Erb redo
Blake Mizerany authored
62 end
f3ed6e4 Allow helper methods to use blocks in erb views
Matias Käkelä authored
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 Ryan Tomayko Fix weirdness with partials in ERB [#158]
rtomayko authored
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
94 end
b3e82c5 Konstantin Haase test both ERB and Erubis
rkh authored
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.