sinatra 1.3.6 → 1.4.0.a

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

Files changed (71) hide show
  1. data/CHANGES +96 -22
  2. data/Gemfile +11 -3
  3. data/README.de.md +2590 -0
  4. data/README.es.rdoc +66 -38
  5. data/README.fr.md +2630 -0
  6. data/README.hu.rdoc +3 -2
  7. data/README.jp.rdoc +16 -3
  8. data/README.ko.rdoc +11 -5
  9. data/README.md +2699 -0
  10. data/README.pt-br.rdoc +152 -21
  11. data/README.pt-pt.rdoc +3 -2
  12. data/README.ru.md +2724 -0
  13. data/README.zh.rdoc +3 -3
  14. data/Rakefile +3 -4
  15. data/examples/chat.rb +3 -3
  16. data/lib/sinatra/base.rb +433 -247
  17. data/lib/sinatra/main.rb +4 -2
  18. data/lib/sinatra/showexceptions.rb +6 -1
  19. data/lib/sinatra/version.rb +1 -1
  20. data/test/base_test.rb +21 -9
  21. data/test/builder_test.rb +15 -19
  22. data/test/coffee_test.rb +4 -6
  23. data/test/compile_test.rb +154 -0
  24. data/test/contest.rb +4 -6
  25. data/test/creole_test.rb +5 -5
  26. data/test/delegator_test.rb +1 -3
  27. data/test/erb_test.rb +32 -20
  28. data/test/extensions_test.rb +1 -3
  29. data/test/filter_test.rb +65 -56
  30. data/test/haml_test.rb +34 -26
  31. data/test/helpers_test.rb +331 -221
  32. data/test/integration_helper.rb +8 -0
  33. data/test/integration_test.rb +3 -1
  34. data/test/less_test.rb +10 -8
  35. data/test/liquid_test.rb +22 -4
  36. data/test/mapped_error_test.rb +122 -96
  37. data/test/markaby_test.rb +5 -5
  38. data/test/markdown_test.rb +5 -5
  39. data/test/middleware_test.rb +3 -3
  40. data/test/nokogiri_test.rb +4 -6
  41. data/test/rabl_test.rb +89 -0
  42. data/test/radius_test.rb +4 -4
  43. data/test/rdoc_test.rb +7 -7
  44. data/test/readme_test.rb +14 -30
  45. data/test/request_test.rb +15 -0
  46. data/test/response_test.rb +3 -4
  47. data/test/result_test.rb +11 -33
  48. data/test/route_added_hook_test.rb +10 -10
  49. data/test/routing_test.rb +123 -1
  50. data/test/sass_test.rb +26 -26
  51. data/test/scss_test.rb +16 -16
  52. data/test/server_test.rb +2 -2
  53. data/test/settings_test.rb +48 -4
  54. data/test/sinatra_test.rb +2 -7
  55. data/test/slim_test.rb +37 -23
  56. data/test/static_test.rb +56 -15
  57. data/test/streaming_test.rb +11 -2
  58. data/test/templates_test.rb +117 -45
  59. data/test/textile_test.rb +9 -9
  60. data/test/views/hello.rabl +2 -0
  61. data/test/views/hello.wlang +1 -0
  62. data/test/views/hello.yajl +1 -0
  63. data/test/views/layout2.rabl +3 -0
  64. data/test/views/layout2.wlang +2 -0
  65. data/test/wlang_test.rb +87 -0
  66. data/test/yajl_test.rb +86 -0
  67. metadata +27 -17
  68. data/README.de.rdoc +0 -2097
  69. data/README.fr.rdoc +0 -2036
  70. data/README.rdoc +0 -2017
  71. data/README.ru.rdoc +0 -1785
@@ -2,15 +2,10 @@ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  class SinatraTest < Test::Unit::TestCase
4
4
  it 'creates a new Sinatra::Base subclass on new' do
5
- app =
6
- Sinatra.new do
7
- get '/' do
8
- 'Hello World'
9
- end
10
- end
5
+ app = Sinatra.new { get('/') { 'Hello World' } }
11
6
  assert_same Sinatra::Base, app.superclass
12
7
  end
13
-
8
+
14
9
  it "responds to #template_cache" do
15
10
  assert_kind_of Tilt::Cache, Sinatra::Base.new!.template_cache
16
11
  end
@@ -5,10 +5,10 @@ require 'slim'
5
5
 
6
6
  class SlimTest < Test::Unit::TestCase
7
7
  def slim_app(&block)
8
- mock_app {
8
+ mock_app do
9
9
  set :views, File.dirname(__FILE__) + '/views'
10
- get '/', &block
11
- }
10
+ get('/', &block)
11
+ end
12
12
  get '/'
13
13
  end
14
14
 
@@ -17,62 +17,58 @@ class SlimTest < Test::Unit::TestCase
17
17
  assert ok?
18
18
  assert_equal "<h1>Hiya</h1>", body
19
19
  end
20
-
20
+
21
21
  it 'renders .slim files in views path' do
22
22
  slim_app { slim :hello }
23
23
  assert ok?
24
24
  assert_equal "<h1>Hello From Slim</h1>", body
25
25
  end
26
-
26
+
27
27
  it "renders with inline layouts" do
28
- mock_app {
28
+ mock_app do
29
29
  layout { %(h1\n | THIS. IS. \n == yield.upcase ) }
30
30
  get('/') { slim 'em Sparta' }
31
- }
31
+ end
32
32
  get '/'
33
33
  assert ok?
34
34
  assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>", body
35
35
  end
36
-
36
+
37
37
  it "renders with file layouts" do
38
- slim_app {
39
- slim '| Hello World', :layout => :layout2
40
- }
38
+ slim_app { slim('| Hello World', :layout => :layout2) }
41
39
  assert ok?
42
40
  assert_equal "<h1>Slim Layout!</h1><p>Hello World</p>", body
43
41
  end
44
-
42
+
45
43
  it "raises error if template not found" do
46
- mock_app {
47
- get('/') { slim :no_such_template }
48
- }
44
+ mock_app { get('/') { slim(:no_such_template) } }
49
45
  assert_raise(Errno::ENOENT) { get('/') }
50
46
  end
51
-
47
+
52
48
  HTML4_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
53
-
49
+
54
50
  it "passes slim options to the slim engine" do
55
- mock_app { get('/') { slim "x foo='bar'", :attr_wrapper => "'" }}
51
+ mock_app { get('/') { slim("x foo='bar'", :attr_wrapper => "'") }}
56
52
  get '/'
57
53
  assert ok?
58
54
  assert_body "<x foo='bar'></x>"
59
55
  end
60
-
56
+
61
57
  it "passes default slim options to the slim engine" do
62
58
  mock_app do
63
59
  set :slim, :attr_wrapper => "'"
64
- get('/') { slim "x foo='bar'" }
60
+ get('/') { slim("x foo='bar'") }
65
61
  end
66
62
  get '/'
67
63
  assert ok?
68
64
  assert_body "<x foo='bar'></x>"
69
65
  end
70
-
66
+
71
67
  it "merges the default slim options with the overrides and passes them to the slim engine" do
72
68
  mock_app do
73
69
  set :slim, :attr_wrapper => "'"
74
- get('/') { slim "x foo='bar'" }
75
- get('/other') { slim "x foo='bar'", :attr_wrapper => '"' }
70
+ get('/') { slim("x foo='bar'") }
71
+ get('/other') { slim("x foo='bar'", :attr_wrapper => '"') }
76
72
  end
77
73
  get '/'
78
74
  assert ok?
@@ -81,6 +77,24 @@ class SlimTest < Test::Unit::TestCase
81
77
  assert ok?
82
78
  assert_body '<x foo="bar"></x>'
83
79
  end
80
+
81
+ it "can rendere truly nested layouts by accepting a layout and a block with the contents" do
82
+ mock_app do
83
+ template(:main_outer_layout) { "h1 Title\n== yield" }
84
+ template(:an_inner_layout) { "h2 Subtitle\n== yield" }
85
+ template(:a_page) { "p Contents." }
86
+ get('/') do
87
+ slim :main_outer_layout, :layout => false do
88
+ slim :an_inner_layout do
89
+ slim :a_page
90
+ end
91
+ end
92
+ end
93
+ end
94
+ get '/'
95
+ assert ok?
96
+ assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
97
+ end
84
98
  end
85
99
 
86
100
  rescue LoadError
@@ -2,10 +2,10 @@ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  class StaticTest < Test::Unit::TestCase
4
4
  setup do
5
- mock_app {
5
+ mock_app do
6
6
  set :static, true
7
7
  set :public_folder, File.dirname(__FILE__)
8
- }
8
+ end
9
9
  end
10
10
 
11
11
  it 'serves GET requests for files in the public directory' do
@@ -83,10 +83,10 @@ class StaticTest < Test::Unit::TestCase
83
83
  end
84
84
 
85
85
  it '404s when .. path traverses outside of public directory' do
86
- mock_app {
86
+ mock_app do
87
87
  set :static, true
88
88
  set :public_folder, File.dirname(__FILE__) + '/data'
89
- }
89
+ end
90
90
  get "/../#{File.basename(__FILE__)}"
91
91
  assert not_found?
92
92
  end
@@ -98,11 +98,30 @@ class StaticTest < Test::Unit::TestCase
98
98
  should_be = file[range]
99
99
  expected_range = "bytes #{range.begin}-#{range.end}/#{file.length}"
100
100
 
101
- assert_equal 206,response.status, "Should be HTTP/1.1 206 Partial content"
102
- assert_equal should_be.length, response.body.length, "Unexpected response length for #{http_range}"
103
- assert_equal should_be, response.body, "Unexpected response data for #{http_range}"
104
- assert_equal should_be.length.to_s, response['Content-Length'], "Incorrect Content-Length for #{http_range}"
105
- assert_equal expected_range, response['Content-Range'], "Incorrect Content-Range for #{http_range}"
101
+ assert_equal(
102
+ 206,response.status,
103
+ "Should be HTTP/1.1 206 Partial content"
104
+ )
105
+ assert_equal(
106
+ should_be.length,
107
+ response.body.length,
108
+ "Unexpected response length for #{http_range}"
109
+ )
110
+ assert_equal(
111
+ should_be,
112
+ response.body,
113
+ "Unexpected response data for #{http_range}"
114
+ )
115
+ assert_equal(
116
+ should_be.length.to_s,
117
+ response['Content-Length'],
118
+ "Incorrect Content-Length for #{http_range}"
119
+ )
120
+ assert_equal(
121
+ expected_range,
122
+ response['Content-Range'],
123
+ "Incorrect Content-Range for #{http_range}"
124
+ )
106
125
  end
107
126
 
108
127
  it 'handles valid byte ranges correctly' do
@@ -138,8 +157,16 @@ class StaticTest < Test::Unit::TestCase
138
157
  request = Rack::MockRequest.new(@app)
139
158
  response = request.get("/#{File.basename(__FILE__)}", 'HTTP_RANGE' => http_range)
140
159
 
141
- assert_equal 200,response.status, "Invalid range '#{http_range}' should be ignored"
142
- assert_equal nil,response['Content-Range'], "Invalid range '#{http_range}' should be ignored"
160
+ assert_equal(
161
+ 200,
162
+ response.status,
163
+ "Invalid range '#{http_range}' should be ignored"
164
+ )
165
+ assert_equal(
166
+ nil,
167
+ response['Content-Range'],
168
+ "Invalid range '#{http_range}' should be ignored"
169
+ )
143
170
  end
144
171
  end
145
172
 
@@ -150,8 +177,16 @@ class StaticTest < Test::Unit::TestCase
150
177
  request = Rack::MockRequest.new(@app)
151
178
  response = request.get("/#{File.basename(__FILE__)}", 'HTTP_RANGE' => http_range)
152
179
 
153
- assert_equal 416,response.status, "Unsatisfiable range '#{http_range}' should return 416"
154
- assert_equal "bytes */#{length}",response['Content-Range'], "416 response should include actual length"
180
+ assert_equal(
181
+ 416,
182
+ response.status,
183
+ "Unsatisfiable range '#{http_range}' should return 416"
184
+ )
185
+ assert_equal(
186
+ "bytes */#{length}",
187
+ response['Content-Range'],
188
+ "416 response should include actual length"
189
+ )
155
190
  end
156
191
  end
157
192
 
@@ -168,11 +203,17 @@ class StaticTest < Test::Unit::TestCase
168
203
  assert headers.has_key?('Cache-Control')
169
204
  assert_equal headers['Cache-Control'], 'public'
170
205
 
171
- @app.set :static_cache_control, [:public, :must_revalidate, {:max_age => 300}]
206
+ @app.set(
207
+ :static_cache_control,
208
+ [:public, :must_revalidate, {:max_age => 300}]
209
+ )
172
210
  env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}")
173
211
  status, headers, body = @app.call(env)
174
212
  assert headers.has_key?('Cache-Control')
175
- assert_equal headers['Cache-Control'], 'public, must-revalidate, max-age=300'
213
+ assert_equal(
214
+ headers['Cache-Control'],
215
+ 'public, must-revalidate, max-age=300'
216
+ )
176
217
  end
177
218
 
178
219
  end
@@ -5,7 +5,7 @@ class StreamingTest < Test::Unit::TestCase
5
5
 
6
6
  it 'returns the concatinated body' do
7
7
  mock_app do
8
- get '/' do
8
+ get('/') do
9
9
  stream do |out|
10
10
  out << "Hello" << " "
11
11
  out << "World!"
@@ -115,7 +115,9 @@ class StreamingTest < Test::Unit::TestCase
115
115
 
116
116
  it 'gives access to route specific params' do
117
117
  mock_app do
118
- get('/:name') { stream { |o| o << params[:name] }}
118
+ get('/:name') do
119
+ stream { |o| o << params[:name] }
120
+ end
119
121
  end
120
122
  get '/foo'
121
123
  assert_body 'foo'
@@ -137,4 +139,11 @@ class StreamingTest < Test::Unit::TestCase
137
139
  get '/'
138
140
  assert ran
139
141
  end
142
+
143
+ it 'has a public interface to inspect its open/closed state' do
144
+ stream = Stream.new(Stream) { |out| out << :foo }
145
+ assert !stream.closed?
146
+ stream.close
147
+ assert stream.closed?
148
+ end
140
149
  end
@@ -17,12 +17,12 @@ end
17
17
  class TemplatesTest < Test::Unit::TestCase
18
18
  def render_app(base=Sinatra::Base, options = {}, &block)
19
19
  base, options = Sinatra::Base, base if base.is_a? Hash
20
- mock_app(base) {
20
+ mock_app(base) do
21
21
  set :views, File.dirname(__FILE__) + '/views'
22
22
  set options
23
- get '/', &block
23
+ get('/', &block)
24
24
  template(:layout3) { "Layout 3!\n" }
25
- }
25
+ end
26
26
  get '/'
27
27
  end
28
28
 
@@ -34,27 +34,72 @@ class TemplatesTest < Test::Unit::TestCase
34
34
  File.unlink(layout) rescue nil
35
35
  end
36
36
 
37
+ it 'falls back to engine layout' do
38
+ mock_app do
39
+ template(:layout3) { 'Layout 3!<%= yield %>' }
40
+ set :erb, :layout => :layout3
41
+
42
+ get('/') do
43
+ erb('Hello World!', { :layout => true })
44
+ end
45
+ end
46
+
47
+ get '/'
48
+ assert ok?
49
+ assert_equal "Layout 3!Hello World!", body
50
+ end
51
+
52
+ it 'falls back to default layout if engine layout is true' do
53
+ mock_app do
54
+ template(:layout) { 'Layout!!! <%= yield %>' }
55
+ set :erb, :layout => true
56
+
57
+ get('/') do
58
+ erb('Hello World!', { :layout => true })
59
+ end
60
+ end
61
+
62
+ get '/'
63
+ assert ok?
64
+ assert_equal "Layout!!! Hello World!", body
65
+ end
66
+
67
+ it 'renders no layout if layout if falsy' do
68
+ mock_app do
69
+ template(:layout) { 'Layout!!! <%= yield %>' }
70
+ set :erb, :layout => true
71
+
72
+ get('/') do
73
+ erb('Hello World!', { :layout => nil })
74
+ end
75
+ end
76
+
77
+ get '/'
78
+ assert ok?
79
+ assert_equal "Hello World!", body
80
+ end
81
+
37
82
  it 'renders String templates directly' do
38
- render_app { render :test, 'Hello World' }
83
+ render_app { render(:test, 'Hello World') }
39
84
  assert ok?
40
85
  assert_equal 'Hello World', body
41
86
  end
42
87
 
43
88
  it 'renders Proc templates using the call result' do
44
- render_app { render :test, Proc.new {'Hello World'} }
89
+ render_app { render(:test, Proc.new {'Hello World'}) }
45
90
  assert ok?
46
91
  assert_equal 'Hello World', body
47
92
  end
48
93
 
49
94
  it 'looks up Symbol templates in views directory' do
50
- render_app { render :test, :hello }
95
+ render_app { render(:test, :hello) }
51
96
  assert ok?
52
97
  assert_equal "Hello World!\n", body
53
98
  end
54
99
 
55
100
  it 'uses the default layout template if not explicitly overridden' do
56
101
  with_default_layout do
57
- render_app { render :test, :hello }
102
+ render_app { render(:test, :hello) }
58
103
  assert ok?
59
104
  assert_equal "Layout!\nHello World!\n", body
60
105
  end
@@ -62,34 +107,40 @@ class TemplatesTest < Test::Unit::TestCase
62
107
 
63
108
  it 'uses the default layout template if not really overriden' do
64
109
  with_default_layout do
65
- render_app { render :test, :hello, :layout => true }
110
+ render_app { render(:test, :hello, :layout => true) }
66
111
  assert ok?
67
112
  assert_equal "Layout!\nHello World!\n", body
68
113
  end
69
114
  end
70
115
 
71
116
  it 'uses the layout template specified' do
72
- render_app { render :test, :hello, :layout => :layout2 }
117
+ render_app { render(:test, :hello, :layout => :layout2) }
73
118
  assert ok?
74
119
  assert_equal "Layout 2!\nHello World!\n", body
75
120
  end
76
121
 
77
122
  it 'uses layout templates defined with the #template method' do
78
- render_app { render :test, :hello, :layout => :layout3 }
123
+ render_app { render(:test, :hello, :layout => :layout3) }
79
124
  assert ok?
80
125
  assert_equal "Layout 3!\nHello World!\n", body
81
126
  end
82
127
 
83
128
  it 'avoids wrapping layouts around nested templates' do
84
- render_app { render :str, :nested, :layout => :layout2 }
129
+ render_app { render(:str, :nested, :layout => :layout2) }
85
130
  assert ok?
86
- assert_equal "<h1>String Layout!</h1>\n<content><h1>Hello From String</h1></content>", body
131
+ assert_equal(
132
+ "<h1>String Layout!</h1>\n<content><h1>Hello From String</h1></content>",
133
+ body
134
+ )
87
135
  end
88
136
 
89
137
  it 'allows explicitly wrapping layouts around nested templates' do
90
- render_app { render :str, :explicitly_nested, :layout => :layout2 }
138
+ render_app { render(:str, :explicitly_nested, :layout => :layout2) }
91
139
  assert ok?
92
- assert_equal "<h1>String Layout!</h1>\n<content><h1>String Layout!</h1>\n<h1>Hello From String</h1></content>", body
140
+ assert_equal(
141
+ "<h1>String Layout!</h1>\n<content><h1>String Layout!</h1>\n<h1>Hello From String</h1></content>",
142
+ body
143
+ )
93
144
  end
94
145
 
95
146
  it 'two independent render calls do not disable layouts' do
@@ -98,7 +149,10 @@ class TemplatesTest < Test::Unit::TestCase
98
149
  render :str, :nested, :layout => :layout2
99
150
  end
100
151
  assert ok?
101
- assert_equal "<h1>String Layout!</h1>\n<content><h1>Hello From String</h1></content>", body
152
+ assert_equal(
153
+ "<h1>String Layout!</h1>\n<content><h1>Hello From String</h1></content>",
154
+ body
155
+ )
102
156
  end
103
157
 
104
158
  it 'is possible to use partials in layouts' do
@@ -111,75 +165,97 @@ class TemplatesTest < Test::Unit::TestCase
111
165
  end
112
166
 
113
167
  it 'loads templates from source file' do
114
- mock_app { enable :inline_templates }
168
+ mock_app { enable(:inline_templates) }
115
169
  assert_equal "this is foo\n\n", @app.templates[:foo][0]
116
170
  assert_equal "X\n= yield\nX\n", @app.templates[:layout][0]
117
171
  end
118
172
 
119
173
  it 'ignores spaces after names of inline templates' do
120
- mock_app { enable :inline_templates }
174
+ mock_app { enable(:inline_templates) }
121
175
  assert_equal "There's a space after 'bar'!\n\n", @app.templates[:bar][0]
122
176
  assert_equal "this is not foo\n\n", @app.templates[:"foo bar"][0]
123
177
  end
124
178
 
125
179
  it 'loads templates from given source file' do
126
- mock_app { set :inline_templates, __FILE__ }
180
+ mock_app { set(:inline_templates, __FILE__) }
127
181
  assert_equal "this is foo\n\n", @app.templates[:foo][0]
128
182
  end
129
183
 
130
184
  test 'inline_templates ignores IO errors' do
131
- assert_nothing_raised {
132
- mock_app {
133
- set :inline_templates, '/foo/bar'
134
- }
135
- }
185
+ assert_nothing_raised { mock_app { set(:inline_templates, '/foo/bar') } }
136
186
 
137
187
  assert @app.templates.empty?
138
188
  end
139
189
 
140
190
  it 'allows unicode in inline templates' do
141
- mock_app { set :inline_templates, __FILE__ }
142
- assert_equal "Den som tror at hemma det är där man bor har aldrig vart hos mig.\n\n",
191
+ mock_app { set(:inline_templates, __FILE__) }
192
+ assert_equal(
193
+ "Den som tror at hemma det är där man bor har aldrig vart hos mig.\n\n",
143
194
  @app.templates[:umlaut][0]
195
+ )
144
196
  end
145
197
 
146
198
  it 'loads templates from specified views directory' do
147
- render_app { render :test, :hello, :views => settings.views + '/foo' }
199
+ render_app { render(:test, :hello, :views => settings.views + '/foo') }
148
200
 
149
201
  assert_equal "from another views directory\n", body
150
202
  end
151
203
 
204
+ it 'takes views directory into consideration for caching' do
205
+ render_app do
206
+ render(:test, :hello) + render(:test, :hello, :views => settings.views + '/foo')
207
+ end
208
+ assert_equal "Hello World!\nfrom another views directory\n", body
209
+ end
210
+
152
211
  it 'passes locals to the layout' do
153
- mock_app {
154
- template :my_layout do
155
- 'Hello <%= name %>!<%= yield %>'
212
+ mock_app do
213
+ template(:my_layout) { 'Hello <%= name %>!<%= yield %>' }
214
+
215
+ get('/') do
216
+ erb('<p>content</p>', { :layout => :my_layout }, { :name => 'Mike'})
156
217
  end
218
+ end
157
219
 
220
+ get '/'
221
+ assert ok?
222
+ assert_equal 'Hello Mike!<p>content</p>', body
223
+ end
224
+
225
+ it 'sets layout-only options via layout_options' do
226
+ mock_app do
158
227
  get '/' do
159
- erb '<p>content</p>', { :layout => :my_layout }, { :name => 'Mike'}
228
+ render(:str, :in_a,
229
+ :views => settings.views + '/a',
230
+ :layout_options => { :views => settings.views },
231
+ :layout => :layout2)
160
232
  end
161
- }
233
+ end
162
234
 
163
235
  get '/'
164
236
  assert ok?
165
- assert_equal 'Hello Mike!<p>content</p>', body
237
+ assert_equal "<h1>String Layout!</h1>\nGimme an A!\n", body
166
238
  end
167
239
 
168
240
  it 'loads templates defined in subclasses' do
169
241
  base = Class.new(Sinatra::Base)
170
242
  base.template(:foo) { 'bar' }
171
- render_app(base) { render :test, :foo }
243
+ render_app(base) { render(:test, :foo) }
172
244
  assert ok?
173
245
  assert_equal 'bar', body
174
246
  end
175
247
 
176
248
  it 'allows setting default content type per template engine' do
177
- render_app(:str => { :content_type => :txt }) { render :str, 'foo' }
249
+ render_app(:str => { :content_type => :txt }) {
250
+ render :str, 'foo'
251
+ }
178
252
  assert_equal 'text/plain;charset=utf-8', response['Content-Type']
179
253
  end
180
254
 
181
255
  it 'setting default content type does not affect other template engines' do
182
- render_app(:str => { :content_type => :txt }) { render :test, 'foo' }
256
+ render_app(:str => { :content_type => :txt }) {
257
+ render :test, 'foo'
258
+ }
183
259
  assert_equal 'text/html;charset=utf-8', response['Content-Type']
184
260
  end
185
261
 
@@ -196,11 +272,11 @@ class TemplatesTest < Test::Unit::TestCase
196
272
  base.template(:foo) { 'template in superclass' }
197
273
  assert_equal 'template in superclass', base.templates[:foo].first.call
198
274
 
199
- mock_app(base) {
275
+ mock_app(base) do
200
276
  set :views, File.dirname(__FILE__) + '/views'
201
277
  template(:foo) { 'template in subclass' }
202
278
  get('/') { render :test, :foo }
203
- }
279
+ end
204
280
  assert_equal 'template in subclass', @app.templates[:foo].first.call
205
281
 
206
282
  get '/'
@@ -240,11 +316,9 @@ class TemplatesTest < Test::Unit::TestCase
240
316
 
241
317
  it "passes scope to the template" do
242
318
  mock_app do
243
- template :scoped do
244
- 'Hello <%= foo %>'
245
- end
319
+ template(:scoped) { 'Hello <%= foo %>' }
246
320
 
247
- get '/' do
321
+ get('/') do
248
322
  some_scope = Object.new
249
323
  def some_scope.foo() 'World!' end
250
324
  erb :scoped, :scope => some_scope
@@ -263,9 +337,7 @@ class TemplatesTest < Test::Unit::TestCase
263
337
  Array(views).each { |v| super(v, name, engine, &block) }
264
338
  end
265
339
 
266
- get('/:name') do
267
- render :str, params[:name].to_sym
268
- end
340
+ get('/:name') { render(:str, params[:name].to_sym) }
269
341
  end
270
342
 
271
343
  get '/in_a'
@@ -283,7 +355,7 @@ __END__
283
355
  @@ foo
284
356
  this is foo
285
357
 
286
- @@ bar
358
+ @@ bar
287
359
  There's a space after 'bar'!
288
360
 
289
361
  @@ foo bar