Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 87 lines (79 sloc) 2.704 kB
9e9dde6 @jeremy Require callbacks so AS::TestCase may be required in isolation
jeremy authored
1 require 'active_support/callbacks'
2
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
3 module ActiveSupport
4 module Testing
5 module SetupAndTeardown
6 def self.included(base)
34c51c9 @jeremy Rubinious: setup/teardown override for miniunit
jeremy authored
7 base.class_eval do
8 include ActiveSupport::Callbacks
9 define_callbacks :setup, :teardown
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
10
e7208d3 @jeremy Get ActiveSupport::TestCase working with classic Test::Unit and MiniT…
jeremy authored
11 if defined? MiniTest
18099b0 @jeremy Rework testing extensions to reflect the recent miniunit upheaval
jeremy authored
12 include ForMiniTest
34c51c9 @jeremy Rubinious: setup/teardown override for miniunit
jeremy authored
13 else
e7208d3 @jeremy Get ActiveSupport::TestCase working with classic Test::Unit and MiniT…
jeremy authored
14 include ForClassicTestUnit
34c51c9 @jeremy Rubinious: setup/teardown override for miniunit
jeremy authored
15 end
16 end
17 end
18
18099b0 @jeremy Rework testing extensions to reflect the recent miniunit upheaval
jeremy authored
19 module ForMiniTest
20 def run(runner)
21 result = '.'
34c51c9 @jeremy Rubinious: setup/teardown override for miniunit
jeremy authored
22 begin
18099b0 @jeremy Rework testing extensions to reflect the recent miniunit upheaval
jeremy authored
23 run_callbacks :setup
24 result = super
34c51c9 @jeremy Rubinious: setup/teardown override for miniunit
jeremy authored
25 rescue Exception => e
26 result = runner.puke(self.class, self.name, e)
18099b0 @jeremy Rework testing extensions to reflect the recent miniunit upheaval
jeremy authored
27 ensure
28 begin
29 run_callbacks :teardown, :enumerator => :reverse_each
30 rescue Exception => e
31 result = runner.puke(self.class, self.name, e)
32 end
34c51c9 @jeremy Rubinious: setup/teardown override for miniunit
jeremy authored
33 end
18099b0 @jeremy Rework testing extensions to reflect the recent miniunit upheaval
jeremy authored
34 result
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
35 end
36 end
37
e7208d3 @jeremy Get ActiveSupport::TestCase working with classic Test::Unit and MiniT…
jeremy authored
38 module ForClassicTestUnit
39 # For compatibility with Ruby < 1.8.6
40 PASSTHROUGH_EXCEPTIONS = Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS rescue [NoMemoryError, SignalException, Interrupt, SystemExit]
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
41
e7208d3 @jeremy Get ActiveSupport::TestCase working with classic Test::Unit and MiniT…
jeremy authored
42 # This redefinition is unfortunate but test/unit shows us no alternative.
43 # Doubly unfortunate: hax to support Mocha's hax.
44 def run(result)
45 return if @method_name.to_s == "default_test"
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
46
e7208d3 @jeremy Get ActiveSupport::TestCase working with classic Test::Unit and MiniT…
jeremy authored
47 if using_mocha = respond_to?(:mocha_verify)
48 assertion_counter = Mocha::TestCaseAdapter::AssertionCounter.new(result)
49 end
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
50
e7208d3 @jeremy Get ActiveSupport::TestCase working with classic Test::Unit and MiniT…
jeremy authored
51 yield(Test::Unit::TestCase::STARTED, name)
52 @_result = result
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
53 begin
54 begin
e7208d3 @jeremy Get ActiveSupport::TestCase working with classic Test::Unit and MiniT…
jeremy authored
55 run_callbacks :setup
56 setup
57 __send__(@method_name)
58 mocha_verify(assertion_counter) if using_mocha
59 rescue Mocha::ExpectationError => e
60 add_failure(e.message, e.backtrace)
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
61 rescue Test::Unit::AssertionFailedError => e
62 add_failure(e.message, e.backtrace)
e7208d3 @jeremy Get ActiveSupport::TestCase working with classic Test::Unit and MiniT…
jeremy authored
63 rescue Exception => e
64 raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
65 add_error(e)
66 ensure
67 begin
68 teardown
69 run_callbacks :teardown, :enumerator => :reverse_each
70 rescue Test::Unit::AssertionFailedError => e
71 add_failure(e.message, e.backtrace)
72 rescue Exception => e
73 raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
74 add_error(e)
75 end
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
76 end
e7208d3 @jeremy Get ActiveSupport::TestCase working with classic Test::Unit and MiniT…
jeremy authored
77 ensure
78 mocha_teardown if using_mocha
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
79 end
e7208d3 @jeremy Get ActiveSupport::TestCase working with classic Test::Unit and MiniT…
jeremy authored
80 result.add_run
81 yield(Test::Unit::TestCase::FINISHED, name)
139b924 @jeremy * Continue evolution toward ActiveSupport::TestCase and friends. #10…
jeremy authored
82 end
83 end
84 end
85 end
86 end
Something went wrong with that request. Please try again.