Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 96 lines (83 sloc) 2.265 kb
e001d62 @rkh adjust require lines for test helper, so it also works properly on 1.9.2
rkh authored
1 require File.expand_path('../helper', __FILE__)
0e8614b @cactus wrap import/test in a rescue block to make it optional
cactus authored
2
3 begin
7030e25 @sr Deprecation warning for auto-require of template engines
sr authored
4 require 'builder'
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
5
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
6 class BuilderTest < Test::Unit::TestCase
1d676f4 @rkh Sets default content type according to template engine used instead o…
rkh authored
7 def builder_app(options = {}, &block)
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
8 mock_app {
9 set :views, File.dirname(__FILE__) + '/views'
1d676f4 @rkh Sets default content type according to template engine used instead o…
rkh authored
10 set options
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
11 get '/', &block
12 }
13 get '/'
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
14 end
15
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
16 it 'renders inline Builder strings' do
17 builder_app { builder 'xml.instruct!' }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
18 assert ok?
19 assert_equal %{<?xml version="1.0" encoding="UTF-8"?>\n}, body
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
20 end
21
1d676f4 @rkh Sets default content type according to template engine used instead o…
rkh authored
22 it 'defaults content type to xml' do
23 builder_app { builder 'xml.instruct!' }
24 assert ok?
25 assert_equal "application/xml;charset=utf-8", response['Content-Type']
26 end
27
28 it 'defaults allows setting content type per route' do
29 builder_app do
30 content_type :html
31 builder 'xml.instruct!'
32 end
33 assert ok?
34 assert_equal "text/html;charset=utf-8", response['Content-Type']
35 end
36
37 it 'defaults allows setting content type globally' do
38 builder_app(:builder => { :content_type => 'html' }) do
39 builder 'xml.instruct!'
40 end
41 assert ok?
42 assert_equal "text/html;charset=utf-8", response['Content-Type']
43 end
44
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
45 it 'renders inline blocks' do
46 builder_app {
47 @name = "Frank & Mary"
48 builder do |xml|
49 xml.couple @name
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
50 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
51 }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
52 assert ok?
53 assert_equal "<couple>Frank &amp; Mary</couple>\n", body
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
54 end
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
55
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
56 it 'renders .builder files in views path' do
57 builder_app {
58 @name = "Blue"
59 builder :hello
60 }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
61 assert ok?
62 assert_equal %(<exclaim>You're my boy, Blue!</exclaim>\n), body
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
63 end
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
64
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
65 it "renders with inline layouts" do
66 mock_app {
67 layout do
68 %(xml.layout { xml << yield })
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
69 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
70 get('/') { builder %(xml.em 'Hello World') }
71 }
72 get '/'
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
73 assert ok?
74 assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
75 end
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
76
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
77 it "renders with file layouts" do
78 builder_app {
79 builder %(xml.em 'Hello World'), :layout => :layout2
80 }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
81 assert ok?
82 assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
83 end
84
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
85 it "raises error if template not found" do
86 mock_app {
87 get('/') { builder :no_such_template }
88 }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
89 assert_raise(Errno::ENOENT) { get('/') }
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
90 end
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
91 end
0e8614b @cactus wrap import/test in a rescue block to make it optional
cactus authored
92
93 rescue LoadError
3edbafe @cactus correct builder test name in load error warning, fixes #196.
cactus authored
94 warn "#{$!.to_s}: skipping builder tests"
0e8614b @cactus wrap import/test in a rescue block to make it optional
cactus authored
95 end
Something went wrong with that request. Please try again.