deas 0.38.0 → 0.39.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/Gemfile +2 -1
  2. data/{LICENSE.txt → LICENSE} +0 -0
  3. data/deas.gemspec +4 -3
  4. data/lib/deas/deas_runner.rb +17 -12
  5. data/lib/deas/handler_proxy.rb +14 -8
  6. data/lib/deas/redirect_proxy.rb +12 -12
  7. data/lib/deas/runner.rb +169 -19
  8. data/lib/deas/server.rb +14 -10
  9. data/lib/deas/template_source.rb +2 -2
  10. data/lib/deas/test_runner.rb +59 -60
  11. data/lib/deas/version.rb +1 -1
  12. data/lib/deas/view_handler.rb +55 -30
  13. data/test/support/empty_view_handler.rb +7 -0
  14. data/test/support/factory.rb +5 -0
  15. data/test/support/fake_request.rb +29 -0
  16. data/test/support/fake_sinatra_call.rb +11 -16
  17. data/test/support/file1.txt +1 -0
  18. data/test/support/file2.txt +1 -0
  19. data/test/support/routes.rb +7 -7
  20. data/test/support/show.html +0 -0
  21. data/test/support/show.json +0 -0
  22. data/test/system/{rack_tests.rb → deas_tests.rb} +19 -14
  23. data/test/unit/deas_runner_tests.rb +209 -20
  24. data/test/unit/handler_proxy_tests.rb +27 -19
  25. data/test/unit/redirect_proxy_tests.rb +32 -33
  26. data/test/unit/respond_with_proxy_tests.rb +1 -2
  27. data/test/unit/route_proxy_tests.rb +1 -1
  28. data/test/unit/route_tests.rb +1 -1
  29. data/test/unit/router_tests.rb +5 -5
  30. data/test/unit/runner_tests.rb +619 -76
  31. data/test/unit/server_tests.rb +6 -1
  32. data/test/unit/sinatra_app_tests.rb +1 -1
  33. data/test/unit/test_runner_tests.rb +377 -106
  34. data/test/unit/url_tests.rb +1 -1
  35. data/test/unit/view_handler_tests.rb +325 -182
  36. metadata +43 -24
  37. data/lib/deas/sinatra_runner.rb +0 -55
  38. data/lib/deas/test_helpers.rb +0 -23
  39. data/test/support/view_handlers.rb +0 -83
  40. data/test/unit/sinatra_runner_tests.rb +0 -79
  41. data/test/unit/test_helpers_tests.rb +0 -53
@@ -1,7 +1,7 @@
1
1
  require 'assert'
2
2
  require 'deas/url'
3
3
 
4
- require 'test/support/view_handlers'
4
+ require 'test/support/empty_view_handler'
5
5
 
6
6
  class Deas::Url
7
7
 
@@ -1,28 +1,37 @@
1
1
  require 'assert'
2
2
  require 'deas/view_handler'
3
3
 
4
- require 'deas/test_helpers'
4
+ require 'much-plugin'
5
+ require 'rack/request'
6
+ require 'rack/response'
5
7
  require 'deas/template_source'
6
- require 'test/support/view_handlers'
8
+ require 'test/support/empty_view_handler'
7
9
 
8
10
  module Deas::ViewHandler
9
11
 
10
12
  class UnitTests < Assert::Context
11
- include Deas::TestHelpers
13
+ include Deas::ViewHandler::TestHelpers
12
14
 
13
15
  desc "Deas::ViewHandler"
14
16
  setup do
15
- @handler_class = TestViewHandler
17
+ @handler_class = Class.new{ include Deas::ViewHandler }
16
18
  end
17
19
  subject{ @handler_class }
18
20
 
19
21
  should have_imeths :layout, :layouts
20
- should have_imeths :before, :prepend_before, :before_callbacks
21
- should have_imeths :after, :prepend_after, :after_callbacks
22
- should have_imeths :before_init, :prepend_before_init, :before_init_callbacks
23
- should have_imeths :after_init, :prepend_after_init, :after_init_callbacks
24
- should have_imeths :before_run, :prepend_before_run, :before_run_callbacks
25
- should have_imeths :after_run, :prepend_after_run, :after_run_callbacks
22
+ should have_imeths :before_callbacks, :after_callbacks
23
+ should have_imeths :before_init_callbacks, :after_init_callbacks
24
+ should have_imeths :before_run_callbacks, :after_run_callbacks
25
+ should have_imeths :before, :after
26
+ should have_imeths :before_init, :after_init
27
+ should have_imeths :before_run, :after_run
28
+ should have_imeths :prepend_before, :prepend_after
29
+ should have_imeths :prepend_before_init, :prepend_after_init
30
+ should have_imeths :prepend_before_run, :prepend_after_run
31
+
32
+ should "use much-plugin" do
33
+ assert_includes MuchPlugin, Deas::ViewHandler
34
+ end
26
35
 
27
36
  should "specify layouts" do
28
37
  subject.layout 'layouts/app'
@@ -32,243 +41,361 @@ module Deas::ViewHandler
32
41
  assert_equal ['layouts/app', 'layouts/web'], subject.layouts.map(&:call)
33
42
  end
34
43
 
44
+ should "return an empty array by default using `before_callbacks`" do
45
+ assert_equal [], subject.before_callbacks
46
+ end
47
+
48
+ should "return an empty array by default using `after_callbacks`" do
49
+ assert_equal [], subject.after_callbacks
50
+ end
51
+
52
+ should "return an empty array by default using `before_init_callbacks`" do
53
+ assert_equal [], subject.before_init_callbacks
54
+ end
55
+
56
+ should "return an empty array by default using `after_init_callbacks`" do
57
+ assert_equal [], subject.after_init_callbacks
58
+ end
59
+
60
+ should "return an empty array by default using `before_run_callbacks`" do
61
+ assert_equal [], subject.before_run_callbacks
62
+ end
63
+
64
+ should "return an empty array by default using `after_run_callbacks`" do
65
+ assert_equal [], subject.after_run_callbacks
66
+ end
67
+
68
+ should "append a block to the before callbacks using `before`" do
69
+ subject.before_callbacks << proc{ Factory.string }
70
+ block = Proc.new{ Factory.string }
71
+ subject.before(&block)
72
+ assert_equal block, subject.before_callbacks.last
73
+ end
74
+
75
+ should "append a block to the after callbacks using `after`" do
76
+ subject.after_callbacks << proc{ Factory.string }
77
+ block = Proc.new{ Factory.string }
78
+ subject.after(&block)
79
+ assert_equal block, subject.after_callbacks.last
80
+ end
81
+
82
+ should "append a block to the before init callbacks using `before_init`" do
83
+ subject.before_init_callbacks << proc{ Factory.string }
84
+ block = Proc.new{ Factory.string }
85
+ subject.before_init(&block)
86
+ assert_equal block, subject.before_init_callbacks.last
87
+ end
88
+
89
+ should "append a block to the after init callbacks using `after_init`" do
90
+ subject.after_init_callbacks << proc{ Factory.string }
91
+ block = Proc.new{ Factory.string }
92
+ subject.after_init(&block)
93
+ assert_equal block, subject.after_init_callbacks.last
94
+ end
95
+
96
+ should "append a block to the before run callbacks using `before_run`" do
97
+ subject.before_run_callbacks << proc{ Factory.string }
98
+ block = Proc.new{ Factory.string }
99
+ subject.before_run(&block)
100
+ assert_equal block, subject.before_run_callbacks.last
101
+ end
102
+
103
+ should "append a block to the after run callbacks using `after_run`" do
104
+ subject.after_run_callbacks << proc{ Factory.string }
105
+ block = Proc.new{ Factory.string }
106
+ subject.after_run(&block)
107
+ assert_equal block, subject.after_run_callbacks.last
108
+ end
109
+
110
+ should "prepend a block to the before callbacks using `prepend_before`" do
111
+ subject.before_callbacks << proc{ Factory.string }
112
+ block = Proc.new{ Factory.string }
113
+ subject.prepend_before(&block)
114
+ assert_equal block, subject.before_callbacks.first
115
+ end
116
+
117
+ should "prepend a block to the after callbacks using `prepend_after`" do
118
+ subject.after_callbacks << proc{ Factory.string }
119
+ block = Proc.new{ Factory.string }
120
+ subject.prepend_after(&block)
121
+ assert_equal block, subject.after_callbacks.first
122
+ end
123
+
124
+ should "prepend a block to the before init callbacks using `prepend_before_init`" do
125
+ subject.before_init_callbacks << proc{ Factory.string }
126
+ block = Proc.new{ Factory.string }
127
+ subject.prepend_before_init(&block)
128
+ assert_equal block, subject.before_init_callbacks.first
129
+ end
130
+
131
+ should "prepend a block to the after init callbacks using `prepend_after_init`" do
132
+ subject.after_init_callbacks << proc{ Factory.string }
133
+ block = Proc.new{ Factory.string }
134
+ subject.prepend_after_init(&block)
135
+ assert_equal block, subject.after_init_callbacks.first
136
+ end
137
+
138
+ should "prepend a block to the before run callbacks using `prepend_before_run`" do
139
+ subject.before_run_callbacks << proc{ Factory.string }
140
+ block = Proc.new{ Factory.string }
141
+ subject.prepend_before_run(&block)
142
+ assert_equal block, subject.before_run_callbacks.first
143
+ end
144
+
145
+ should "prepend a block to the after run callbacks using `prepend_after_run`" do
146
+ subject.after_run_callbacks << proc{ Factory.string }
147
+ block = Proc.new{ Factory.string }
148
+ subject.prepend_after_run(&block)
149
+ assert_equal block, subject.after_run_callbacks.first
150
+ end
151
+
35
152
  end
36
153
 
37
154
  class InitTests < UnitTests
38
155
  desc "when init"
39
156
  setup do
40
- @runner = test_runner(@handler_class)
157
+ @runner = test_runner(TestViewHandler)
41
158
  @handler = @runner.handler
42
159
  end
43
160
  subject{ @handler }
44
161
 
45
- should have_imeths :init, :init!, :run, :run!
46
- should have_imeths :layouts
162
+ should have_imeths :deas_init, :init!, :deas_run, :run!
163
+ should have_imeths :layouts, :deas_run_callback
47
164
 
48
- should "have called `init!` and it's callbacks" do
49
- assert_equal true, subject.before_init_called
50
- assert_equal true, subject.second_before_init_called
51
- assert_equal true, subject.init_bang_called
52
- assert_equal true, subject.after_init_called
165
+ should "have called `init!` and its before/after init callbacks" do
166
+ assert_equal 1, subject.first_before_init_call_order
167
+ assert_equal 2, subject.second_before_init_call_order
168
+ assert_equal 3, subject.init_call_order
169
+ assert_equal 4, subject.first_after_init_call_order
170
+ assert_equal 5, subject.second_after_init_call_order
53
171
  end
54
172
 
55
- should "not have called `run!` or it's callbacks when initialized" do
56
- assert_nil subject.before_run_called
57
- assert_nil subject.run_bang_called
58
- assert_nil subject.after_run_called
173
+ should "not have called `run!` and its before/after run callbacks" do
174
+ assert_nil subject.first_before_run_call_order
175
+ assert_nil subject.second_before_run_call_order
176
+ assert_nil subject.run_call_order
177
+ assert_nil subject.first_after_run_call_order
178
+ assert_nil subject.second_after_run_call_order
59
179
  end
60
180
 
61
- end
62
-
63
- class LayoutsTests < InitTests
64
- desc "with layouts"
65
- setup do
66
- @params = { 'n' => Factory.integer }
67
- @runner = test_runner(LayoutsViewHandler, :params => @params)
68
- @handler = @runner.handler
181
+ should "run its callbacks with `deas_run_callback`" do
182
+ subject.deas_run_callback 'before_run'
183
+ assert_equal 6, subject.first_before_run_call_order
184
+ assert_equal 7, subject.second_before_run_call_order
69
185
  end
70
186
 
71
- should "build its layouts by instance eval'ing its class layout procs" do
72
- exp = subject.class.layouts.map{ |proc| @handler.instance_eval(&proc) }
73
- assert_equal exp, subject.layouts
187
+ should "know if it is equal to another view handler" do
188
+ handler = test_handler(TestViewHandler)
189
+ assert_equal handler, subject
190
+
191
+ handler = test_handler(Class.new{ include Deas::ViewHandler })
192
+ assert_not_equal handler, subject
74
193
  end
75
194
 
76
195
  end
77
196
 
78
197
  class RunTests < InitTests
79
198
  desc "and run"
80
-
81
- should "call `run!` and it's callbacks" do
82
- subject.run
83
- assert_equal true, subject.before_run_called
84
- assert_equal true, subject.run_bang_called
85
- assert_equal true, subject.after_run_called
86
- end
87
-
88
- should "complain if run! is not overwritten" do
89
- assert_raises(NotImplementedError){ test_runner(EmptyViewHandler).run }
199
+ setup do
200
+ @handler.deas_run
90
201
  end
91
202
 
92
- should "send files" do
93
- send_file_args = test_runner(SendFileViewHandler).run
94
- assert_equal "my_file.txt", send_file_args.file_path
95
- assert_equal({:some => :option}, send_file_args.options)
203
+ should "call `run!` and it's callbacks" do
204
+ assert_equal 6, subject.first_before_run_call_order
205
+ assert_equal 7, subject.second_before_run_call_order
206
+ assert_equal 8, subject.run_call_order
207
+ assert_equal 9, subject.first_after_run_call_order
208
+ assert_equal 10, subject.second_after_run_call_order
96
209
  end
97
210
 
98
211
  end
99
212
 
100
- class RenderTests < RunTests
213
+ class PrivateHelpersTests < InitTests
101
214
  setup do
102
- @template_name = Factory.path
103
- @locals = { Factory.string => Factory.string }
104
- @source = Deas::TemplateSource.new(Factory.path)
215
+ @something = Factory.string
216
+ @args = (Factory.integer(3)+1).times.map{ Factory.string }
217
+ @block = proc{}
218
+ end
105
219
 
106
- @render_args = nil
107
- Assert.stub(@runner.template_source, :render){ |*args| @render_args = args }
108
- @source_render_args = nil
109
- Assert.stub(@source, :render){ |*args| @source_render_args = args }
110
- @partial_args = nil
111
- Assert.stub(@runner.template_source, :partial){ |*args| @partial_args = args }
112
- @source_partial_args = nil
113
- Assert.stub(@source, :partial){ |*args| @source_partial_args = args }
220
+ should "call to the runner for its logger" do
221
+ stub_runner_with_something_for(:logger)
222
+ assert_equal @runner.logger, subject.instance_eval{ logger }
114
223
  end
115
224
 
116
- should "render templates" do
117
- subject.send(:render, @template_name, @locals)
118
- exp = [@template_name, subject, @locals]
119
- assert_equal exp, @render_args
225
+ should "call to the runner for its router" do
226
+ stub_runner_with_something_for(:router)
227
+ assert_equal @runner.router, subject.instance_eval{ router }
228
+ end
120
229
 
121
- subject.send(:source_render, @source, @template_name, @locals)
122
- exp = [@template_name, subject, @locals]
123
- assert_equal exp, @source_render_args
230
+ should "call to the runner for its request" do
231
+ stub_runner_with_something_for(:request)
232
+ assert_equal @runner.request, subject.instance_eval{ request }
233
+ end
124
234
 
125
- subject.send(:partial, @template_name, @locals)
126
- exp = [@template_name, @locals]
127
- assert_equal exp, @partial_args
235
+ should "call to the runner for its session" do
236
+ stub_runner_with_something_for(:session)
237
+ assert_equal @runner.session, subject.instance_eval{ session }
238
+ end
128
239
 
129
- subject.send(:source_partial, @source, @template_name, @locals)
130
- exp = [@template_name, @locals]
131
- assert_equal exp, @source_partial_args
240
+ should "call to the runner for its params" do
241
+ stub_runner_with_something_for(:params)
242
+ assert_equal @runner.params, subject.instance_eval{ params }
132
243
  end
133
244
 
134
- end
245
+ should "call to the runner for its status helper" do
246
+ capture_runner_meth_args_for(:status)
247
+ exp_args = @args
248
+ subject.instance_eval{ status(*exp_args) }
135
249
 
136
- class CallbackTests < UnitTests
137
- setup do
138
- @proc1 = proc{ '1' }
139
- @proc2 = proc{ '2' }
140
- @handler = Class.new{ include Deas::ViewHandler }
250
+ assert_equal exp_args, @meth_args
251
+ assert_nil @meth_block
141
252
  end
142
253
 
143
- should "append procs in #before_callbacks with #before" do
144
- @handler.before(&@proc1); @handler.before(&@proc2)
145
- assert_equal @proc1, @handler.before_callbacks.first
146
- assert_equal @proc2, @handler.before_callbacks.last
147
- end
254
+ should "call to the runner for its headers helper" do
255
+ capture_runner_meth_args_for(:headers)
256
+ exp_args = @args
257
+ subject.instance_eval{ headers(*exp_args) }
148
258
 
149
- should "prepend procs in #before_callbacks with #before" do
150
- @handler.prepend_before(&@proc1); @handler.prepend_before(&@proc2)
151
- assert_equal @proc2, @handler.before_callbacks.first
152
- assert_equal @proc1, @handler.before_callbacks.last
259
+ assert_equal exp_args, @meth_args
260
+ assert_nil @meth_block
153
261
  end
154
262
 
155
- should "append procs in #after_callbacks with #after" do
156
- @handler.after(&@proc1); @handler.after(&@proc2)
157
- assert_equal @proc1, @handler.after_callbacks.first
158
- assert_equal @proc2, @handler.after_callbacks.last
159
- end
263
+ should "call to the runner for its body helper" do
264
+ capture_runner_meth_args_for(:body)
265
+ exp_args = @args
266
+ subject.instance_eval{ body(*exp_args) }
160
267
 
161
- should "prepend procs in #after_callbacks with #before" do
162
- @handler.prepend_after(&@proc1); @handler.prepend_after(&@proc2)
163
- assert_equal @proc2, @handler.after_callbacks.first
164
- assert_equal @proc1, @handler.after_callbacks.last
268
+ assert_equal exp_args, @meth_args
269
+ assert_nil @meth_block
165
270
  end
166
271
 
167
- should "append procs in #before_init_callbacks with #before_init" do
168
- @handler.before_init(&@proc1); @handler.before_init(&@proc2)
169
- assert_equal @proc1, @handler.before_init_callbacks.first
170
- assert_equal @proc2, @handler.before_init_callbacks.last
171
- end
272
+ should "call to the runner for its content type helper" do
273
+ capture_runner_meth_args_for(:content_type)
274
+ exp_args = @args
275
+ subject.instance_eval{ content_type(*exp_args) }
172
276
 
173
- should "prepend procs in #before_init_callbacks with #before" do
174
- @handler.prepend_before_init(&@proc1); @handler.prepend_before_init(&@proc2)
175
- assert_equal @proc2, @handler.before_init_callbacks.first
176
- assert_equal @proc1, @handler.before_init_callbacks.last
277
+ assert_equal exp_args, @meth_args
278
+ assert_nil @meth_block
177
279
  end
178
280
 
179
- should "append procs in #after_init_callbacks with #after_init" do
180
- @handler.after_init(&@proc1); @handler.after_init(&@proc2)
181
- assert_equal @proc1, @handler.after_init_callbacks.first
182
- assert_equal @proc2, @handler.after_init_callbacks.last
183
- end
281
+ should "call to the runner for its halt helper" do
282
+ capture_runner_meth_args_for(:halt)
283
+ exp_args = @args
284
+ subject.instance_eval{ halt(*exp_args) }
184
285
 
185
- should "prepend procs in #after_init_callbacks with #before" do
186
- @handler.prepend_after_init(&@proc1); @handler.prepend_after_init(&@proc2)
187
- assert_equal @proc2, @handler.after_init_callbacks.first
188
- assert_equal @proc1, @handler.after_init_callbacks.last
286
+ assert_equal exp_args, @meth_args
287
+ assert_nil @meth_block
189
288
  end
190
289
 
191
- should "append procs in #before_run_callbacks with #before_run" do
192
- @handler.before_run(&@proc1); @handler.before_run(&@proc2)
193
- assert_equal @proc1, @handler.before_run_callbacks.first
194
- assert_equal @proc2, @handler.before_run_callbacks.last
195
- end
290
+ should "call to the runner for its redirect helper" do
291
+ capture_runner_meth_args_for(:redirect)
292
+ exp_args = @args
293
+ subject.instance_eval{ redirect(*exp_args) }
196
294
 
197
- should "prepend procs in #before_run_callbacks with #before" do
198
- @handler.prepend_before_run(&@proc1); @handler.prepend_before_run(&@proc2)
199
- assert_equal @proc2, @handler.before_run_callbacks.first
200
- assert_equal @proc1, @handler.before_run_callbacks.last
295
+ assert_equal exp_args, @meth_args
296
+ assert_nil @meth_block
201
297
  end
202
298
 
203
- should "append procs in #after_run_callbacks with #after_run" do
204
- @handler.after_run(&@proc1); @handler.after_run(&@proc2)
205
- assert_equal @proc1, @handler.after_run_callbacks.first
206
- assert_equal @proc2, @handler.after_run_callbacks.last
299
+ should "call to the runner for its send file helper" do
300
+ capture_runner_meth_args_for(:send_file)
301
+ exp_args = @args
302
+ subject.instance_eval{ send_file(*exp_args) }
303
+
304
+ assert_equal exp_args, @meth_args
305
+ assert_nil @meth_block
207
306
  end
208
307
 
209
- should "prepend procs in #after_run_callbacks with #before" do
210
- @handler.prepend_after_run(&@proc1); @handler.prepend_after_run(&@proc2)
211
- assert_equal @proc2, @handler.after_run_callbacks.first
212
- assert_equal @proc1, @handler.after_run_callbacks.last
308
+ should "call to the runner for its render helper" do
309
+ capture_runner_meth_args_for(:render)
310
+ exp_args, exp_block = @args, @block
311
+ subject.instance_eval{ render(*exp_args, &exp_block) }
312
+
313
+ assert_equal exp_args, @meth_args
314
+ assert_equal exp_block, @meth_block
213
315
  end
214
316
 
215
- end
317
+ should "call to the runner for its source render helper" do
318
+ capture_runner_meth_args_for(:source_render)
319
+ exp_args, exp_block = @args, @block
320
+ subject.instance_eval{ source_render(*exp_args, &exp_block) }
216
321
 
217
- class HaltTests < UnitTests
218
- desc "halt"
322
+ assert_equal exp_args, @meth_args
323
+ assert_equal exp_block, @meth_block
324
+ end
219
325
 
220
- should "return a response with the status code and the passed data" do
221
- runner = test_runner(HaltViewHandler, :params => {
222
- 'code' => 200,
223
- 'headers' => { 'Content-Type' => 'text/plain' },
224
- 'body' => 'test halting'
225
- })
226
- runner.run
326
+ should "call to the runner for its partial helper" do
327
+ capture_runner_meth_args_for(:partial)
328
+ exp_args, exp_block = @args, @block
329
+ subject.instance_eval{ partial(*exp_args, &exp_block) }
227
330
 
228
- assert_equal 200, runner.response_value.status
229
- assert_equal({ 'Content-Type' => 'text/plain' }, runner.response_value.headers)
230
- assert_equal 'test halting', runner.response_value.body
331
+ assert_equal exp_args, @meth_args
332
+ assert_equal exp_block, @meth_block
231
333
  end
232
334
 
233
- end
335
+ should "call to the runner for its source partial helper" do
336
+ capture_runner_meth_args_for(:source_partial)
337
+ exp_args, exp_block = @args, @block
338
+ subject.instance_eval{ source_partial(*exp_args, &exp_block) }
234
339
 
235
- class ContentTypeTests < UnitTests
236
- desc "content_type"
340
+ assert_equal exp_args, @meth_args
341
+ assert_equal exp_block, @meth_block
342
+ end
237
343
 
238
- should "should set the response content_type/charset" do
239
- runner = test_runner(ContentTypeViewHandler)
240
- content_type_args = runner.run
344
+ private
241
345
 
242
- assert_equal 'text/plain', content_type_args.value
243
- assert_equal({:charset => 'latin1'}, content_type_args.opts)
346
+ def stub_runner_with_something_for(meth)
347
+ Assert.stub(@runner, meth){ @something }
244
348
  end
245
349
 
246
- end
350
+ def capture_runner_meth_args_for(meth)
351
+ Assert.stub(@runner, meth) do |*args, &block|
352
+ @meth_args = args
353
+ @meth_block = block
354
+ end
355
+ end
247
356
 
248
- class StatusTests < UnitTests
249
- desc "status"
357
+ end
250
358
 
251
- should "should set the response status" do
252
- runner = test_runner(StatusViewHandler)
253
- status_args = runner.run
359
+ class InitLayoutsTests < UnitTests
360
+ desc "when init with layouts"
361
+ setup do
362
+ @params = { 'n' => Factory.integer }
363
+ @runner = test_runner(LayoutsViewHandler, :params => @params)
364
+ @handler = @runner.handler
365
+ end
366
+ subject{ @handler }
254
367
 
255
- assert_equal 422, status_args.value
368
+ should "build its layouts by instance eval'ing its class layout procs" do
369
+ exp = subject.class.layouts.map{ |proc| subject.instance_eval(&proc) }
370
+ assert_equal exp, subject.layouts
256
371
  end
257
372
 
258
373
  end
259
374
 
260
- class HeadersTests < UnitTests
261
- desc "headers"
375
+ class TestHelpersTests < UnitTests
376
+ desc "TestHelpers"
377
+ setup do
378
+ context_class = Class.new{ include Deas::ViewHandler::TestHelpers }
379
+ @context = context_class.new
380
+ end
381
+ subject{ @context }
382
+
383
+ should have_imeths :test_runner, :test_handler
262
384
 
263
- should "should set the response status" do
264
- runner = test_runner(HeadersViewHandler)
265
- headers_args = runner.run
266
- exp_headers = {
267
- 'a-header' => 'some value',
268
- 'other' => 'other'
269
- }
385
+ should "build a test runner for a given handler class" do
386
+ runner = subject.test_runner(@handler_class)
270
387
 
271
- assert_equal exp_headers, headers_args.value
388
+ assert_kind_of ::Deas::TestRunner, runner
389
+ assert_kind_of Rack::Request, runner.request
390
+ assert_equal runner.request.session, runner.session
391
+ end
392
+
393
+ should "return an initialized handler instance" do
394
+ handler = subject.test_handler(@handler_class)
395
+ assert_kind_of @handler_class, handler
396
+
397
+ exp = subject.test_runner(@handler_class).handler
398
+ assert_equal exp, handler
272
399
  end
273
400
 
274
401
  end
@@ -276,22 +403,38 @@ module Deas::ViewHandler
276
403
  class TestViewHandler
277
404
  include Deas::ViewHandler
278
405
 
279
- attr_reader :before_called, :after_called
280
- attr_reader :before_init_called, :second_before_init_called
281
- attr_reader :init_bang_called, :after_init_called
282
- attr_reader :before_run_called, :run_bang_called, :after_run_called
406
+ attr_reader :first_before_init_call_order, :second_before_init_call_order
407
+ attr_reader :first_after_init_call_order, :second_after_init_call_order
408
+ attr_reader :first_before_run_call_order, :second_before_run_call_order
409
+ attr_reader :first_after_run_call_order, :second_after_run_call_order
410
+ attr_reader :init_call_order, :run_call_order
283
411
 
284
- before{ @before_called = true }
285
- after{ @after_called = true }
412
+ before_init{ @first_before_init_call_order = next_call_order }
413
+ before_init{ @second_before_init_call_order = next_call_order }
286
414
 
287
- before_init{ @before_init_called = true }
288
- before_init{ @second_before_init_called = true }
289
- after_init{ @after_init_called = true }
290
- before_run{ @before_run_called = true }
291
- after_run{ @after_run_called = true }
415
+ after_init{ @first_after_init_call_order = next_call_order }
416
+ after_init{ @second_after_init_call_order = next_call_order }
292
417
 
293
- def init!; @init_bang_called = true; end
294
- def run!; @run_bang_called = true; end
418
+ before_run{ @first_before_run_call_order = next_call_order }
419
+ before_run{ @second_before_run_call_order = next_call_order }
420
+
421
+ after_run{ @first_after_run_call_order = next_call_order }
422
+ after_run{ @second_after_run_call_order = next_call_order }
423
+
424
+ def init!
425
+ @init_call_order = next_call_order
426
+ end
427
+
428
+ def run!
429
+ @run_call_order = next_call_order
430
+ end
431
+
432
+ private
433
+
434
+ def next_call_order
435
+ @order ||= 0
436
+ @order += 1
437
+ end
295
438
 
296
439
  end
297
440