Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 82 lines (72 sloc) 1.727 kb
c00a25e Ryan Tomayko Test framework refactoring
rtomayko authored
1 require File.dirname(__FILE__) + '/helper'
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
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
4 def erb_app(&block)
5 mock_app {
6 set :views, File.dirname(__FILE__) + '/views'
7 get '/', &block
8 }
9 get '/'
becd6d8 ERB in place
Blake Mizerany authored
10 end
60d5006 Ryan Tomayko Fix whitespace errors across all source files and tests
rtomayko authored
11
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
12 it 'renders inline ERB strings' do
13 erb_app { erb '<%= 1 + 1 %>' }
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
14 assert ok?
15 assert_equal '2', body
becd6d8 ERB in place
Blake Mizerany authored
16 end
60d5006 Ryan Tomayko Fix whitespace errors across all source files and tests
rtomayko authored
17
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
18 it 'renders .erb files in views path' do
19 erb_app { erb :hello }
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
20 assert ok?
21 assert_equal "Hello World\n", body
becd6d8 ERB in place
Blake Mizerany authored
22 end
7d5bc1f Haml & Erb redo
Blake Mizerany authored
23
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
24 it 'takes a :locals option' do
25 erb_app {
26 locals = {:foo => 'Bar'}
27 erb '<%= foo %>', :locals => locals
28 }
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
29 assert ok?
30 assert_equal 'Bar', body
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
31 end
7d5bc1f Haml & Erb redo
Blake Mizerany authored
32
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
33 it "renders with inline layouts" do
34 mock_app {
35 layout { 'THIS. IS. <%= yield.upcase %>!' }
36 get('/') { erb 'Sparta' }
37 }
38 get '/'
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
39 assert ok?
40 assert_equal 'THIS. IS. SPARTA!', body
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
41 end
7d5bc1f Haml & Erb redo
Blake Mizerany authored
42
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
43 it "renders with file layouts" do
44 erb_app {
45 erb 'Hello World', :layout => :layout2
46 }
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
47 assert ok?
48 assert_equal "ERB Layout!\nHello World\n", body
7d5bc1f Haml & Erb redo
Blake Mizerany authored
49 end
f3ed6e4 Allow helper methods to use blocks in erb views
Matias Käkelä authored
50
51 it "renders erb with blocks" do
52 mock_app {
53 def container
54 @_out_buf << "THIS."
55 yield
56 @_out_buf << "SPARTA!"
57 end
58 def is; "IS." end
59 get '/' do
60 erb '<% container do %> <%= is %> <% end %>'
61 end
62 }
63 get '/'
64 assert ok?
65 assert_equal 'THIS. IS. SPARTA!', body
66 end
090c4d7 Ryan Tomayko Fix weirdness with partials in ERB [#158]
rtomayko authored
67
68 it "can be used in a nested fashion for partials and whatnot" do
69 mock_app {
70 template(:inner) { "<inner><%= 'hi' %></inner>" }
71 template(:outer) { "<outer><%= erb :inner %></outer>" }
72 get '/' do
73 erb :outer
74 end
75 }
76
77 get '/'
78 assert ok?
79 assert_equal '<outer><inner>hi</inner></outer>', body
80 end
becd6d8 ERB in place
Blake Mizerany authored
81 end
Something went wrong with that request. Please try again.