@@ -146,7 +146,6 @@ def tapout_fault(fault)
146
146
147
147
@stdcom . drain! ( doc )
148
148
149
-
150
149
@trace . emit_stats
151
150
emit doc
152
151
@already_outputted = true
@@ -204,9 +203,94 @@ def emit(doc)
204
203
Test ::Unit ::TestCase . class_eval do
205
204
remove_method :run_test
206
205
def run_test ; end
207
- def run_setup ; end
208
- def run_teardown ; end
206
+
207
+ def run_setup
208
+ yield if block_given?
209
+ end
210
+
209
211
def run_cleanup ; end
212
+ def run_teardown ; end
213
+ end
214
+
215
+ if defined? ( ::ActiveSupport ::Testing ::SetupAndTeardown ::ForClassicTestUnit )
216
+ # Modified from https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/testing/setup_and_teardown.rb#L61
217
+ ::ActiveSupport ::Testing ::SetupAndTeardown ::ForClassicTestUnit . module_eval do
218
+ remove_method :run
219
+
220
+ # This redefinition is unfortunate but test/unit shows us no alternative.
221
+ # Doubly unfortunate: hax to support Mocha's hax.
222
+ def run ( result )
223
+ return if @method_name . to_s == "default_test"
224
+
225
+ @_result = result
226
+ @internal_data . test_started
227
+
228
+ yield ( Test ::Unit ::TestCase ::STARTED , name )
229
+ yield ( Test ::Unit ::TestCase ::STARTED_OBJECT , self )
230
+
231
+ @internal_data . test_finished
232
+ result . add_run
233
+ yield ( Test ::Unit ::TestCase ::FINISHED , name )
234
+ yield ( Test ::Unit ::TestCase ::FINISHED_OBJECT , self )
235
+ end
236
+ end
237
+ end
238
+ else
239
+ if defined? ( ::ActiveSupport ::Testing ::SetupAndTeardown ::ForClassicTestUnit )
240
+ # Modified from https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/testing/setup_and_teardown.rb#L61
241
+ ::ActiveSupport ::Testing ::SetupAndTeardown ::ForClassicTestUnit . module_eval do
242
+ remove_method :run
243
+
244
+ # This redefinition is unfortunate but test/unit shows us no alternative.
245
+ # Doubly unfortunate: hax to support Mocha's hax.
246
+ def run ( result )
247
+ return if @method_name . to_s == "default_test"
248
+
249
+ @_result = result
250
+ @internal_data . test_started
251
+
252
+ mocha_counter = retrieve_mocha_counter ( self , result )
253
+ yield ( Test ::Unit ::TestCase ::STARTED , name )
254
+ yield ( Test ::Unit ::TestCase ::STARTED_OBJECT , self )
255
+
256
+ begin
257
+ begin
258
+ run_callbacks :setup do
259
+ setup
260
+ __send__ ( @method_name )
261
+ mocha_verify ( mocha_counter ) if mocha_counter
262
+ end
263
+ rescue Mocha ::ExpectationError => e
264
+ add_failure ( e . message , e . backtrace )
265
+ rescue Test ::Unit ::AssertionFailedError => e
266
+ add_failure ( e . message , e . backtrace )
267
+ rescue Exception => e
268
+ raise if PASSTHROUGH_EXCEPTIONS . include? ( e . class )
269
+ add_error ( e )
270
+ ensure
271
+ begin
272
+ teardown
273
+ run_callbacks :teardown
274
+ rescue Mocha ::ExpectationError => e
275
+ add_failure ( e . message , e . backtrace )
276
+ rescue Test ::Unit ::AssertionFailedError => e
277
+ add_failure ( e . message , e . backtrace )
278
+ rescue Exception => e
279
+ raise if PASSTHROUGH_EXCEPTIONS . include? ( e . class )
280
+ add_error ( e )
281
+ end
282
+ end
283
+ ensure
284
+ mocha_teardown if mocha_counter
285
+ end
286
+
287
+ result . add_run
288
+ @internal_data . test_finished
289
+
290
+ yield ( Test ::Unit ::TestCase ::FINISHED , name )
291
+ yield ( Test ::Unit ::TestCase ::FINISHED_OBJECT , self )
292
+ end
293
+ end
210
294
end
211
295
end
212
296
0 commit comments