deas 0.38.0 → 0.39.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/{LICENSE.txt → LICENSE} +0 -0
- data/deas.gemspec +4 -3
- data/lib/deas/deas_runner.rb +17 -12
- data/lib/deas/handler_proxy.rb +14 -8
- data/lib/deas/redirect_proxy.rb +12 -12
- data/lib/deas/runner.rb +169 -19
- data/lib/deas/server.rb +14 -10
- data/lib/deas/template_source.rb +2 -2
- data/lib/deas/test_runner.rb +59 -60
- data/lib/deas/version.rb +1 -1
- data/lib/deas/view_handler.rb +55 -30
- data/test/support/empty_view_handler.rb +7 -0
- data/test/support/factory.rb +5 -0
- data/test/support/fake_request.rb +29 -0
- data/test/support/fake_sinatra_call.rb +11 -16
- data/test/support/file1.txt +1 -0
- data/test/support/file2.txt +1 -0
- data/test/support/routes.rb +7 -7
- data/test/support/show.html +0 -0
- data/test/support/show.json +0 -0
- data/test/system/{rack_tests.rb → deas_tests.rb} +19 -14
- data/test/unit/deas_runner_tests.rb +209 -20
- data/test/unit/handler_proxy_tests.rb +27 -19
- data/test/unit/redirect_proxy_tests.rb +32 -33
- data/test/unit/respond_with_proxy_tests.rb +1 -2
- data/test/unit/route_proxy_tests.rb +1 -1
- data/test/unit/route_tests.rb +1 -1
- data/test/unit/router_tests.rb +5 -5
- data/test/unit/runner_tests.rb +619 -76
- data/test/unit/server_tests.rb +6 -1
- data/test/unit/sinatra_app_tests.rb +1 -1
- data/test/unit/test_runner_tests.rb +377 -106
- data/test/unit/url_tests.rb +1 -1
- data/test/unit/view_handler_tests.rb +325 -182
- metadata +43 -24
- data/lib/deas/sinatra_runner.rb +0 -55
- data/lib/deas/test_helpers.rb +0 -23
- data/test/support/view_handlers.rb +0 -83
- data/test/unit/sinatra_runner_tests.rb +0 -79
- data/test/unit/test_helpers_tests.rb +0 -53
data/test/unit/url_tests.rb
CHANGED
@@ -1,28 +1,37 @@
|
|
1
1
|
require 'assert'
|
2
2
|
require 'deas/view_handler'
|
3
3
|
|
4
|
-
require '
|
4
|
+
require 'much-plugin'
|
5
|
+
require 'rack/request'
|
6
|
+
require 'rack/response'
|
5
7
|
require 'deas/template_source'
|
6
|
-
require 'test/support/
|
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 =
|
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 :
|
21
|
-
should have_imeths :
|
22
|
-
should have_imeths :
|
23
|
-
should have_imeths :
|
24
|
-
should have_imeths :
|
25
|
-
should have_imeths :
|
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(
|
157
|
+
@runner = test_runner(TestViewHandler)
|
41
158
|
@handler = @runner.handler
|
42
159
|
end
|
43
160
|
subject{ @handler }
|
44
161
|
|
45
|
-
should have_imeths :
|
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
|
49
|
-
assert_equal
|
50
|
-
assert_equal
|
51
|
-
assert_equal
|
52
|
-
assert_equal
|
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!`
|
56
|
-
assert_nil subject.
|
57
|
-
assert_nil subject.
|
58
|
-
assert_nil subject.
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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 "
|
72
|
-
|
73
|
-
assert_equal
|
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
|
-
|
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 "
|
93
|
-
|
94
|
-
assert_equal
|
95
|
-
assert_equal
|
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
|
213
|
+
class PrivateHelpersTests < InitTests
|
101
214
|
setup do
|
102
|
-
@
|
103
|
-
@
|
104
|
-
@
|
215
|
+
@something = Factory.string
|
216
|
+
@args = (Factory.integer(3)+1).times.map{ Factory.string }
|
217
|
+
@block = proc{}
|
218
|
+
end
|
105
219
|
|
106
|
-
|
107
|
-
|
108
|
-
@
|
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 "
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
122
|
-
|
123
|
-
assert_equal
|
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
|
-
|
126
|
-
|
127
|
-
assert_equal
|
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
|
-
|
130
|
-
|
131
|
-
assert_equal
|
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
|
-
|
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
|
-
|
137
|
-
|
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 "
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
150
|
-
|
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 "
|
156
|
-
|
157
|
-
|
158
|
-
|
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
|
-
|
162
|
-
|
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 "
|
168
|
-
|
169
|
-
|
170
|
-
|
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
|
-
|
174
|
-
|
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 "
|
180
|
-
|
181
|
-
|
182
|
-
|
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
|
-
|
186
|
-
|
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 "
|
192
|
-
|
193
|
-
|
194
|
-
|
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
|
-
|
198
|
-
|
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 "
|
204
|
-
|
205
|
-
|
206
|
-
|
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 "
|
210
|
-
|
211
|
-
|
212
|
-
|
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
|
-
|
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
|
-
|
218
|
-
|
322
|
+
assert_equal exp_args, @meth_args
|
323
|
+
assert_equal exp_block, @meth_block
|
324
|
+
end
|
219
325
|
|
220
|
-
should "
|
221
|
-
|
222
|
-
|
223
|
-
|
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
|
229
|
-
assert_equal
|
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
|
-
|
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
|
-
|
236
|
-
|
340
|
+
assert_equal exp_args, @meth_args
|
341
|
+
assert_equal exp_block, @meth_block
|
342
|
+
end
|
237
343
|
|
238
|
-
|
239
|
-
runner = test_runner(ContentTypeViewHandler)
|
240
|
-
content_type_args = runner.run
|
344
|
+
private
|
241
345
|
|
242
|
-
|
243
|
-
|
346
|
+
def stub_runner_with_something_for(meth)
|
347
|
+
Assert.stub(@runner, meth){ @something }
|
244
348
|
end
|
245
349
|
|
246
|
-
|
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
|
-
|
249
|
-
desc "status"
|
357
|
+
end
|
250
358
|
|
251
|
-
|
252
|
-
|
253
|
-
|
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
|
-
|
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
|
261
|
-
desc "
|
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 "
|
264
|
-
runner
|
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
|
-
|
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 :
|
280
|
-
attr_reader :
|
281
|
-
attr_reader :
|
282
|
-
attr_reader :
|
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
|
-
|
285
|
-
|
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
|
-
|
288
|
-
|
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
|
-
|
294
|
-
|
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
|
|