Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 92 lines (79 sloc) 2.25 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 of j...
rkh authored
7 def builder_app(options = {}, &block)
46e8bd6 @zzak First pass at block styles for tests
zzak authored
8 mock_app do
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
9 set :views, File.dirname(__FILE__) + '/views'
1d676f4 @rkh Sets default content type according to template engine used instead of j...
rkh authored
10 set options
46e8bd6 @zzak First pass at block styles for tests
zzak authored
11 get('/', &block)
12 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
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 of j...
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
46e8bd6 @zzak First pass at block styles for tests
zzak authored
46 builder_app do
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
47 @name = "Frank & Mary"
46e8bd6 @zzak First pass at block styles for tests
zzak authored
48 builder { |xml| xml.couple @name }
49 end
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
50 assert ok?
51 assert_equal "<couple>Frank &amp; Mary</couple>\n", body
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
52 end
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
53
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
54 it 'renders .builder files in views path' do
46e8bd6 @zzak First pass at block styles for tests
zzak authored
55 builder_app do
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
56 @name = "Blue"
57 builder :hello
46e8bd6 @zzak First pass at block styles for tests
zzak authored
58 end
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
59 assert ok?
60 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
61 end
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
62
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
63 it "renders with inline layouts" do
46e8bd6 @zzak First pass at block styles for tests
zzak authored
64 mock_app do
65 layout { %(xml.layout { xml << yield }) }
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
66 get('/') { builder %(xml.em 'Hello World') }
46e8bd6 @zzak First pass at block styles for tests
zzak authored
67 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
68 get '/'
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
69 assert ok?
70 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
71 end
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
72
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
73 it "renders with file layouts" do
46e8bd6 @zzak First pass at block styles for tests
zzak authored
74 builder_app do
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
75 builder %(xml.em 'Hello World'), :layout => :layout2
46e8bd6 @zzak First pass at block styles for tests
zzak authored
76 end
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
77 assert ok?
78 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
79 end
80
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
81 it "raises error if template not found" do
46e8bd6 @zzak First pass at block styles for tests
zzak authored
82 mock_app do
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
83 get('/') { builder :no_such_template }
46e8bd6 @zzak First pass at block styles for tests
zzak authored
84 end
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
85 assert_raise(Errno::ENOENT) { get('/') }
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
86 end
caf4857 @rtomayko Builder Rendering Helper (.builder templates) w/ doco and tests.
rtomayko authored
87 end
0e8614b @cactus wrap import/test in a rescue block to make it optional
cactus authored
88
89 rescue LoadError
3edbafe @cactus correct builder test name in load error warning, fixes #196.
cactus authored
90 warn "#{$!.to_s}: skipping builder tests"
0e8614b @cactus wrap import/test in a rescue block to make it optional
cactus authored
91 end
Something went wrong with that request. Please try again.