Skip to content
This repository
Newer
Older
100644 105 lines (90 sloc) 2.062 kb
c00a25ee »
2009-01-13 Test framework refactoring
1 require File.dirname(__FILE__) + '/helper'
a734cf38 »
2008-12-13 I knew I shoulda taken that left turn at Hoboken
2
ff0d0686 »
2009-03-26 Use contest instead of test/spec/mini
3 class ERBTest < Test::Unit::TestCase
b3e82c52 »
2011-04-15 test both ERB and Erubis
4 def engine
5 Tilt::ERBTemplate
6 end
7
8 def setup
9 Tilt.prefer engine, :erb
10 super
11 end
12
a734cf38 »
2008-12-13 I knew I shoulda taken that left turn at Hoboken
13 def erb_app(&block)
14 mock_app {
15 set :views, File.dirname(__FILE__) + '/views'
16 get '/', &block
17 }
18 get '/'
becd6d8a »
2008-02-20 ERB in place
19 end
60d50062 »
2008-08-31 Fix whitespace errors across all source files and tests
20
b3e82c52 »
2011-04-15 test both ERB and Erubis
21 it 'uses the correct engine' do
22 assert_equal engine, Tilt[:erb]
23 end
24
a734cf38 »
2008-12-13 I knew I shoulda taken that left turn at Hoboken
25 it 'renders inline ERB strings' do
26 erb_app { erb '<%= 1 + 1 %>' }
72a6e01d »
2009-01-14 use Test::Unit style assertions in Sinatra specs
27 assert ok?
28 assert_equal '2', body
becd6d8a »
2008-02-20 ERB in place
29 end
60d50062 »
2008-08-31 Fix whitespace errors across all source files and tests
30
a734cf38 »
2008-12-13 I knew I shoulda taken that left turn at Hoboken
31 it 'renders .erb files in views path' do
32 erb_app { erb :hello }
72a6e01d »
2009-01-14 use Test::Unit style assertions in Sinatra specs
33 assert ok?
34 assert_equal "Hello World\n", body
becd6d8a »
2008-02-20 ERB in place
35 end
7d5bc1f0 »
2008-02-27 Haml & Erb redo
36
a734cf38 »
2008-12-13 I knew I shoulda taken that left turn at Hoboken
37 it 'takes a :locals option' do
38 erb_app {
39 locals = {:foo => 'Bar'}
40 erb '<%= foo %>', :locals => locals
41 }
72a6e01d »
2009-01-14 use Test::Unit style assertions in Sinatra specs
42 assert ok?
43 assert_equal 'Bar', body
a734cf38 »
2008-12-13 I knew I shoulda taken that left turn at Hoboken
44 end
7d5bc1f0 »
2008-02-27 Haml & Erb redo
45
a734cf38 »
2008-12-13 I knew I shoulda taken that left turn at Hoboken
46 it "renders with inline layouts" do
47 mock_app {
48 layout { 'THIS. IS. <%= yield.upcase %>!' }
49 get('/') { erb 'Sparta' }
50 }
51 get '/'
72a6e01d »
2009-01-14 use Test::Unit style assertions in Sinatra specs
52 assert ok?
53 assert_equal 'THIS. IS. SPARTA!', body
a734cf38 »
2008-12-13 I knew I shoulda taken that left turn at Hoboken
54 end
7d5bc1f0 »
2008-02-27 Haml & Erb redo
55
a734cf38 »
2008-12-13 I knew I shoulda taken that left turn at Hoboken
56 it "renders with file layouts" do
57 erb_app {
58 erb 'Hello World', :layout => :layout2
59 }
72a6e01d »
2009-01-14 use Test::Unit style assertions in Sinatra specs
60 assert ok?
8f76d3b4 »
2011-04-15 fix erb test to work with erubis
61 assert_body "ERB Layout!\nHello World"
7d5bc1f0 »
2008-02-27 Haml & Erb redo
62 end
f3ed6e4d »
2009-02-18 Allow helper methods to use blocks in erb views
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
090c4d79 »
2009-02-21 Fix weirdness with partials in ERB [#158]
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
becd6d8a »
2008-02-20 ERB in place
94 end
b3e82c52 »
2011-04-15 test both ERB and Erubis
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.