mocha 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -4
- data/RELEASE +32 -0
- data/Rakefile +3 -3
- data/examples/misc.rb +36 -0
- data/examples/mocha.rb +26 -0
- data/examples/stubba.rb +65 -0
- data/lib/mocha.rb +17 -5
- data/lib/{stubba → mocha}/any_instance_method.rb +2 -2
- data/lib/mocha/auto_verify.rb +7 -7
- data/lib/{stubba → mocha}/central.rb +2 -2
- data/lib/{stubba → mocha}/class_method.rb +7 -10
- data/lib/mocha/expectation.rb +88 -33
- data/lib/mocha/expectation_error.rb +6 -0
- data/lib/mocha/inspect.rb +1 -1
- data/lib/mocha/instance_method.rb +8 -0
- data/lib/mocha/metaclass.rb +1 -1
- data/lib/mocha/mock.rb +8 -8
- data/lib/mocha/mock_methods.rb +60 -16
- data/lib/{stubba → mocha}/object.rb +8 -10
- data/lib/mocha/setup_and_teardown.rb +23 -0
- data/lib/mocha/standalone.rb +30 -0
- data/lib/mocha/test_case_adapter.rb +49 -0
- data/lib/mocha_standalone.rb +2 -0
- data/lib/stubba.rb +2 -8
- data/test/all_tests.rb +9 -10
- data/test/method_definer.rb +2 -2
- data/test/{stubba → mocha}/any_instance_method_test.rb +1 -3
- data/test/mocha/auto_verify_test.rb +9 -10
- data/test/{stubba → mocha}/central_test.rb +5 -4
- data/test/{stubba → mocha}/class_method_test.rb +40 -10
- data/test/mocha/expectation_test.rb +144 -67
- data/test/mocha/inspect_test.rb +12 -1
- data/test/mocha/metaclass_test.rb +22 -0
- data/test/mocha/mock_methods_test.rb +65 -7
- data/test/mocha/mock_test.rb +41 -4
- data/test/{stubba → mocha}/object_test.rb +9 -9
- data/test/mocha/setup_and_teardown_test.rb +76 -0
- data/test/mocha_acceptance_test.rb +8 -8
- data/test/mocha_test_result_integration_test.rb +5 -6
- data/test/standalone_acceptance_test.rb +110 -0
- data/test/stubba_acceptance_test.rb +2 -2
- data/test/stubba_integration_test.rb +17 -24
- data/test/stubba_test_result_integration_test.rb +5 -6
- metadata +22 -18
- data/lib/shared/backtracefilter.rb +0 -46
- data/lib/smart_test_case.rb +0 -5
- data/lib/smart_test_case/multiple_setup_and_teardown.rb +0 -123
- data/lib/stubba/instance_method.rb +0 -18
- data/lib/stubba/setup_and_teardown.rb +0 -25
- data/test/smart_test_case/multiple_setup_and_teardown_test.rb +0 -192
- data/test/stubba/instance_method_test.rb +0 -46
- data/test/stubba/setup_and_teardown_test.rb +0 -134
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require '
|
2
|
+
require 'mocha'
|
3
3
|
|
4
4
|
class Widget
|
5
5
|
|
@@ -68,7 +68,7 @@ class StubbaAcceptanceTest < Test::Unit::TestCase
|
|
68
68
|
def test_should_stub_two_different_class_methods_again
|
69
69
|
should_stub_two_different_class_methods
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
private
|
73
73
|
|
74
74
|
def should_stub_module_method
|
@@ -1,31 +1,24 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
3
|
+
require 'mocha/object'
|
4
|
+
require 'mocha/test_case_adapter'
|
5
|
+
require 'mocha/standalone'
|
6
6
|
|
7
7
|
class StubbaIntegrationTest < Test::Unit::TestCase
|
8
8
|
|
9
9
|
class DontMessWithMe
|
10
|
-
def self.
|
10
|
+
def self.my_class_method
|
11
11
|
:original_return_value
|
12
12
|
end
|
13
|
-
def
|
13
|
+
def my_instance_method
|
14
14
|
:original_return_value
|
15
15
|
end
|
16
|
-
# def self.object
|
17
|
-
# @object ||= Class.new do
|
18
|
-
# def instance_method_1
|
19
|
-
# :original_return_value
|
20
|
-
# end
|
21
|
-
# end.new
|
22
|
-
# end
|
23
16
|
end
|
24
17
|
|
25
18
|
def test_should_stub_class_method_within_test
|
26
19
|
test = build_test do
|
27
|
-
DontMessWithMe.expects(:
|
28
|
-
assert_equal :new_return_value, DontMessWithMe.
|
20
|
+
DontMessWithMe.expects(:my_class_method).returns(:new_return_value)
|
21
|
+
assert_equal :new_return_value, DontMessWithMe.my_class_method
|
29
22
|
end
|
30
23
|
|
31
24
|
test_result = Test::Unit::TestResult.new
|
@@ -35,16 +28,16 @@ class StubbaIntegrationTest < Test::Unit::TestCase
|
|
35
28
|
|
36
29
|
def test_should_leave_stubbed_class_method_unchanged_after_test
|
37
30
|
test = build_test do
|
38
|
-
DontMessWithMe.expects(:
|
31
|
+
DontMessWithMe.expects(:my_class_method).returns(:new_return_value)
|
39
32
|
end
|
40
33
|
|
41
34
|
test.run(Test::Unit::TestResult.new) {}
|
42
|
-
assert_equal :original_return_value, DontMessWithMe.
|
35
|
+
assert_equal :original_return_value, DontMessWithMe.my_class_method
|
43
36
|
end
|
44
37
|
|
45
38
|
def test_should_reset_class_expectations_after_test
|
46
39
|
test = build_test do
|
47
|
-
DontMessWithMe.expects(:
|
40
|
+
DontMessWithMe.expects(:my_class_method)
|
48
41
|
end
|
49
42
|
|
50
43
|
test.run(Test::Unit::TestResult.new) {}
|
@@ -54,8 +47,8 @@ class StubbaIntegrationTest < Test::Unit::TestCase
|
|
54
47
|
def test_should_stub_instance_method_within_test
|
55
48
|
instance = DontMessWithMe.new
|
56
49
|
test = build_test do
|
57
|
-
instance.expects(:
|
58
|
-
assert_equal :new_return_value, instance.
|
50
|
+
instance.expects(:my_instance_method).returns(:new_return_value)
|
51
|
+
assert_equal :new_return_value, instance.my_instance_method
|
59
52
|
end
|
60
53
|
test_result = Test::Unit::TestResult.new
|
61
54
|
test.run(test_result) {}
|
@@ -65,17 +58,17 @@ class StubbaIntegrationTest < Test::Unit::TestCase
|
|
65
58
|
def test_should_leave_stubbed_instance_method_unchanged_after_test
|
66
59
|
instance = DontMessWithMe.new
|
67
60
|
test = build_test do
|
68
|
-
instance.expects(:
|
61
|
+
instance.expects(:my_instance_method).returns(:new_return_value)
|
69
62
|
end
|
70
63
|
|
71
64
|
test.run(Test::Unit::TestResult.new) {}
|
72
|
-
assert_equal :original_return_value, instance.
|
65
|
+
assert_equal :original_return_value, instance.my_instance_method
|
73
66
|
end
|
74
67
|
|
75
68
|
def test_should_reset_instance_expectations_after_test
|
76
69
|
instance = DontMessWithMe.new
|
77
70
|
test = build_test do
|
78
|
-
instance.expects(:
|
71
|
+
instance.expects(:my_instance_method).returns(:new_return_value)
|
79
72
|
end
|
80
73
|
|
81
74
|
test.run(Test::Unit::TestResult.new) {}
|
@@ -86,8 +79,8 @@ class StubbaIntegrationTest < Test::Unit::TestCase
|
|
86
79
|
|
87
80
|
def build_test(&block)
|
88
81
|
test_class = Class.new(Test::Unit::TestCase) do
|
89
|
-
include
|
90
|
-
include
|
82
|
+
include Mocha::Standalone
|
83
|
+
include Mocha::TestCaseAdapter
|
91
84
|
define_method(:test_me, &block)
|
92
85
|
end
|
93
86
|
test_class.new(:test_me)
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require 'shared/backtracefilter'
|
2
|
+
require 'mocha/object'
|
3
|
+
require 'mocha/standalone'
|
4
|
+
require 'mocha/test_case_adapter'
|
6
5
|
require 'execution_point'
|
7
6
|
|
8
7
|
class StubbaTestResultIntegrationTest < Test::Unit::TestCase
|
@@ -74,8 +73,8 @@ class StubbaTestResultIntegrationTest < Test::Unit::TestCase
|
|
74
73
|
|
75
74
|
def run_test(test_result = Test::Unit::TestResult.new, &block)
|
76
75
|
test_class = Class.new(Test::Unit::TestCase) do
|
77
|
-
include
|
78
|
-
include
|
76
|
+
include Mocha::Standalone
|
77
|
+
include Mocha::TestCaseAdapter
|
79
78
|
define_method(:test_me, &block)
|
80
79
|
end
|
81
80
|
test = test_class.new(:test_me)
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: mocha
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-01-
|
6
|
+
version: 0.4.0
|
7
|
+
date: 2007-01-22 00:00:00 +00:00
|
8
8
|
summary: Mocking and stubbing library
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -31,48 +31,52 @@ authors:
|
|
31
31
|
- James Mead
|
32
32
|
files:
|
33
33
|
- lib/mocha.rb
|
34
|
-
- lib/
|
34
|
+
- lib/mocha_standalone.rb
|
35
35
|
- lib/stubba.rb
|
36
|
+
- lib/mocha/any_instance_method.rb
|
36
37
|
- lib/mocha/auto_verify.rb
|
38
|
+
- lib/mocha/central.rb
|
39
|
+
- lib/mocha/class_method.rb
|
37
40
|
- lib/mocha/expectation.rb
|
41
|
+
- lib/mocha/expectation_error.rb
|
38
42
|
- lib/mocha/infinite_range.rb
|
39
43
|
- lib/mocha/inspect.rb
|
44
|
+
- lib/mocha/instance_method.rb
|
40
45
|
- lib/mocha/metaclass.rb
|
41
46
|
- lib/mocha/mock.rb
|
42
47
|
- lib/mocha/mock_methods.rb
|
48
|
+
- lib/mocha/object.rb
|
43
49
|
- lib/mocha/pretty_parameters.rb
|
44
|
-
- lib/
|
45
|
-
- lib/
|
46
|
-
- lib/
|
47
|
-
- lib/stubba/central.rb
|
48
|
-
- lib/stubba/class_method.rb
|
49
|
-
- lib/stubba/instance_method.rb
|
50
|
-
- lib/stubba/object.rb
|
51
|
-
- lib/stubba/setup_and_teardown.rb
|
50
|
+
- lib/mocha/setup_and_teardown.rb
|
51
|
+
- lib/mocha/standalone.rb
|
52
|
+
- lib/mocha/test_case_adapter.rb
|
52
53
|
- test/active_record_test_case.rb
|
53
54
|
- test/all_tests.rb
|
54
55
|
- test/execution_point.rb
|
55
56
|
- test/method_definer.rb
|
56
57
|
- test/mocha_acceptance_test.rb
|
57
58
|
- test/mocha_test_result_integration_test.rb
|
59
|
+
- test/standalone_acceptance_test.rb
|
58
60
|
- test/stubba_acceptance_test.rb
|
59
61
|
- test/stubba_integration_test.rb
|
60
62
|
- test/stubba_test_result_integration_test.rb
|
61
63
|
- test/test_helper.rb
|
64
|
+
- test/mocha/any_instance_method_test.rb
|
62
65
|
- test/mocha/auto_verify_test.rb
|
66
|
+
- test/mocha/central_test.rb
|
67
|
+
- test/mocha/class_method_test.rb
|
63
68
|
- test/mocha/expectation_test.rb
|
64
69
|
- test/mocha/infinite_range_test.rb
|
65
70
|
- test/mocha/inspect_test.rb
|
71
|
+
- test/mocha/metaclass_test.rb
|
66
72
|
- test/mocha/mock_methods_test.rb
|
67
73
|
- test/mocha/mock_test.rb
|
74
|
+
- test/mocha/object_test.rb
|
68
75
|
- test/mocha/pretty_parameters_test.rb
|
69
|
-
- test/
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
- test/stubba/instance_method_test.rb
|
74
|
-
- test/stubba/object_test.rb
|
75
|
-
- test/stubba/setup_and_teardown_test.rb
|
76
|
+
- test/mocha/setup_and_teardown_test.rb
|
77
|
+
- examples/misc.rb
|
78
|
+
- examples/mocha.rb
|
79
|
+
- examples/stubba.rb
|
76
80
|
- COPYING
|
77
81
|
- MIT-LICENSE
|
78
82
|
- Rakefile
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Test
|
2
|
-
module Unit
|
3
|
-
module Util
|
4
|
-
module BacktraceFilter
|
5
|
-
|
6
|
-
# quick rip-off of Test::Unit code - there must be a better way of doing this!
|
7
|
-
|
8
|
-
MOCHA_FILE_SEPARATORS = %r{[\\/:]}
|
9
|
-
MOCHA_PREFIX = __FILE__.split(MOCHA_FILE_SEPARATORS)[0..-3]
|
10
|
-
MOCHA_RB_FILE = /\.rb\Z/
|
11
|
-
|
12
|
-
alias_method :__filter_backtrace__, :filter_backtrace
|
13
|
-
|
14
|
-
def filter_backtrace(backtrace, prefix=nil)
|
15
|
-
backtrace = __filter_backtrace__(backtrace, prefix)
|
16
|
-
return ["No backtrace"] unless(backtrace)
|
17
|
-
split_p = if(prefix)
|
18
|
-
prefix.split(MOCHA_FILE_SEPARATORS)
|
19
|
-
else
|
20
|
-
MOCHA_PREFIX
|
21
|
-
end
|
22
|
-
match = proc do |e|
|
23
|
-
split_e = e.split(MOCHA_FILE_SEPARATORS)[0, split_p.size]
|
24
|
-
next false unless(split_e[0..-2] == split_p[0..-2])
|
25
|
-
split_e[-1].sub(MOCHA_RB_FILE, '') == split_p[-1]
|
26
|
-
end
|
27
|
-
return backtrace unless(backtrace.detect(&match))
|
28
|
-
found_prefix = false
|
29
|
-
new_backtrace = backtrace.reverse.reject do |e|
|
30
|
-
if(match[e])
|
31
|
-
found_prefix = true
|
32
|
-
true
|
33
|
-
elsif(found_prefix)
|
34
|
-
false
|
35
|
-
else
|
36
|
-
true
|
37
|
-
end
|
38
|
-
end.reverse
|
39
|
-
new_backtrace = (new_backtrace.empty? ? backtrace : new_backtrace)
|
40
|
-
new_backtrace = new_backtrace.reject(&match)
|
41
|
-
new_backtrace.empty? ? backtrace : new_backtrace
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/lib/smart_test_case.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
module MultipleSetupAndTeardown
|
2
|
-
|
3
|
-
def self.included(base)
|
4
|
-
|
5
|
-
base.class_eval do
|
6
|
-
|
7
|
-
def self.method_added(symbol)
|
8
|
-
# disable until later
|
9
|
-
end
|
10
|
-
|
11
|
-
if method_defined?(:setup) then
|
12
|
-
alias_method :setup_original, :setup
|
13
|
-
define_method(:setup_new) do
|
14
|
-
begin
|
15
|
-
setup_original
|
16
|
-
ensure
|
17
|
-
setup_mocha
|
18
|
-
end
|
19
|
-
end
|
20
|
-
else
|
21
|
-
define_method(:setup_new) do
|
22
|
-
setup_mocha
|
23
|
-
end
|
24
|
-
end
|
25
|
-
alias_method :setup, :setup_new
|
26
|
-
|
27
|
-
if method_defined?(:teardown) then
|
28
|
-
alias_method :teardown_original, :teardown
|
29
|
-
define_method(:teardown_new) do
|
30
|
-
begin
|
31
|
-
teardown_mocha
|
32
|
-
ensure
|
33
|
-
teardown_original
|
34
|
-
end
|
35
|
-
end
|
36
|
-
else
|
37
|
-
define_method(:teardown_new) do
|
38
|
-
teardown_mocha
|
39
|
-
end
|
40
|
-
end
|
41
|
-
alias_method :teardown, :teardown_new
|
42
|
-
|
43
|
-
def self.method_added(method)
|
44
|
-
case method
|
45
|
-
when :setup
|
46
|
-
unless method_defined?(:setup_added)
|
47
|
-
alias_method :setup_added, :setup
|
48
|
-
define_method(:setup) do
|
49
|
-
begin
|
50
|
-
setup_new
|
51
|
-
ensure
|
52
|
-
setup_added
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
when :teardown
|
57
|
-
unless method_defined?(:teardown_added)
|
58
|
-
alias_method :teardown_added, :teardown
|
59
|
-
define_method(:teardown) do
|
60
|
-
begin
|
61
|
-
teardown_added
|
62
|
-
ensure
|
63
|
-
teardown_new
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class << self
|
71
|
-
|
72
|
-
def setup_methods
|
73
|
-
@setup_methods ||= []
|
74
|
-
end
|
75
|
-
|
76
|
-
def teardown_methods
|
77
|
-
@teardown_methods ||= []
|
78
|
-
end
|
79
|
-
|
80
|
-
def add_setup_method(symbol)
|
81
|
-
setup_methods << symbol
|
82
|
-
end
|
83
|
-
|
84
|
-
def add_teardown_method(symbol)
|
85
|
-
teardown_methods << symbol
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
def inherited_with_setup_and_teardown_methods(child)
|
91
|
-
inherited_without_setup_and_teardown_methods(child) if respond_to?(:inherited_without_setup_and_teardown_methods, true)
|
92
|
-
child.instance_variable_set('@setup_methods', setup_methods.dup)
|
93
|
-
child.instance_variable_set('@teardown_methods', teardown_methods.dup)
|
94
|
-
end
|
95
|
-
|
96
|
-
if respond_to?(:inherited, true)
|
97
|
-
alias_method :inherited_without_setup_and_teardown_methods, :inherited
|
98
|
-
end
|
99
|
-
alias_method :inherited, :inherited_with_setup_and_teardown_methods
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
def setup_mocha
|
104
|
-
self.class.class_eval { setup_methods }.each { |symbol| send(symbol) }
|
105
|
-
end
|
106
|
-
|
107
|
-
def teardown_mocha
|
108
|
-
stored_exception = nil
|
109
|
-
self.class.class_eval { teardown_methods }.reverse.each do |symbol|
|
110
|
-
begin
|
111
|
-
send(symbol)
|
112
|
-
rescue Exception => e
|
113
|
-
stored_exception ||= e
|
114
|
-
end
|
115
|
-
end
|
116
|
-
raise stored_exception if stored_exception
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'stubba/central'
|
2
|
-
|
3
|
-
module SetupAndTeardown
|
4
|
-
|
5
|
-
def self.included(base)
|
6
|
-
base.add_setup_method(:setup_stubs)
|
7
|
-
base.add_teardown_method(:teardown_stubs)
|
8
|
-
end
|
9
|
-
|
10
|
-
def setup_stubs
|
11
|
-
$stubba = Stubba::Central.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown_stubs
|
15
|
-
if $stubba then
|
16
|
-
begin
|
17
|
-
$stubba.verify_all { add_assertion }
|
18
|
-
ensure
|
19
|
-
$stubba.unstub_all
|
20
|
-
$stubba = nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
@@ -1,192 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
-
require 'smart_test_case/multiple_setup_and_teardown'
|
3
|
-
require 'active_record_test_case'
|
4
|
-
|
5
|
-
class MultipleSetupAndTeardownTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def test_should_call_added_setup
|
8
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
9
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
10
|
-
include MultipleSetupAndTeardown
|
11
|
-
add_setup_method(:added_setup)
|
12
|
-
define_method(:added_setup) { methods_called << :added_setup }
|
13
|
-
define_method(:test_method) { methods_called << :test_method }
|
14
|
-
end
|
15
|
-
test = test_case.new(:test_method)
|
16
|
-
test_result = Test::Unit::TestResult.new
|
17
|
-
test.run(test_result) {}
|
18
|
-
assert test_result.passed?
|
19
|
-
assert_equal [:added_setup, :test_method], test.methods_called
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_should_call_added_teardown
|
23
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
24
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
25
|
-
include MultipleSetupAndTeardown
|
26
|
-
add_teardown_method(:added_teardown)
|
27
|
-
define_method(:added_teardown) { methods_called << :added_teardown }
|
28
|
-
define_method(:test_method) { methods_called << :test_method }
|
29
|
-
end
|
30
|
-
test = test_case.new(:test_method)
|
31
|
-
test_result = Test::Unit::TestResult.new
|
32
|
-
test.run(test_result) {}
|
33
|
-
assert test_result.passed?
|
34
|
-
assert_equal [:test_method, :added_teardown], test.methods_called
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_should_call_both_added_teardowns_even_if_one_raises_exception
|
38
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
39
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
40
|
-
include MultipleSetupAndTeardown
|
41
|
-
add_teardown_method(:added_teardown_1)
|
42
|
-
add_teardown_method(:added_teardown_2)
|
43
|
-
define_method(:added_teardown_1) { methods_called << :added_teardown_1 }
|
44
|
-
define_method(:added_teardown_2) { methods_called << :added_teardown_2; raise }
|
45
|
-
define_method(:test_method) { methods_called << :test_method }
|
46
|
-
end
|
47
|
-
test = test_case.new(:test_method)
|
48
|
-
test_result = Test::Unit::TestResult.new
|
49
|
-
test.run(test_result) {}
|
50
|
-
assert_equal false, test_result.passed?
|
51
|
-
assert_equal [:test_method, :added_teardown_2, :added_teardown_1], test.methods_called
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_should_call_added_setup_and_setup_defined_before_module_included
|
55
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
56
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
57
|
-
define_method(:setup) { methods_called << :setup }
|
58
|
-
include MultipleSetupAndTeardown
|
59
|
-
add_setup_method(:added_setup)
|
60
|
-
define_method(:added_setup) { methods_called << :added_setup }
|
61
|
-
define_method(:test_method) { methods_called << :test_method }
|
62
|
-
end
|
63
|
-
test = test_case.new(:test_method)
|
64
|
-
test_result = Test::Unit::TestResult.new
|
65
|
-
test.run(test_result) {}
|
66
|
-
assert test_result.passed?
|
67
|
-
assert_equal [:setup, :added_setup, :test_method], test.methods_called
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_should_call_added_teardown_and_teardown_defined_before_module_included
|
71
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
72
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
73
|
-
define_method(:teardown) { methods_called << :teardown }
|
74
|
-
include MultipleSetupAndTeardown
|
75
|
-
add_teardown_method(:added_teardown)
|
76
|
-
define_method(:added_teardown) { methods_called << :added_teardown }
|
77
|
-
define_method(:test_method) { methods_called << :test_method }
|
78
|
-
end
|
79
|
-
test = test_case.new(:test_method)
|
80
|
-
test_result = Test::Unit::TestResult.new
|
81
|
-
test.run(test_result) {}
|
82
|
-
assert test_result.passed?
|
83
|
-
assert_equal [:test_method, :added_teardown, :teardown], test.methods_called
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_should_call_added_setup_and_setup_defined_after_module_included
|
87
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
88
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
89
|
-
include MultipleSetupAndTeardown
|
90
|
-
define_method(:setup) { methods_called << :setup }
|
91
|
-
add_setup_method(:added_setup)
|
92
|
-
define_method(:added_setup) { methods_called << :added_setup }
|
93
|
-
define_method(:test_method) { methods_called << :test_method }
|
94
|
-
end
|
95
|
-
test = test_case.new(:test_method)
|
96
|
-
test_result = Test::Unit::TestResult.new
|
97
|
-
test.run(test_result) {}
|
98
|
-
assert test_result.passed?
|
99
|
-
assert_equal [:added_setup, :setup, :test_method], test.methods_called
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_should_call_added_teardown_and_teardown_defined_after_module_included
|
103
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
104
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
105
|
-
include MultipleSetupAndTeardown
|
106
|
-
define_method(:teardown) { methods_called << :teardown }
|
107
|
-
add_teardown_method(:added_teardown)
|
108
|
-
define_method(:added_teardown) { methods_called << :added_teardown }
|
109
|
-
define_method(:test_method) { methods_called << :test_method }
|
110
|
-
end
|
111
|
-
test = test_case.new(:test_method)
|
112
|
-
test_result = Test::Unit::TestResult.new
|
113
|
-
test.run(test_result) {}
|
114
|
-
assert test_result.passed?
|
115
|
-
assert_equal [:test_method, :teardown, :added_teardown], test.methods_called
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_should_call_added_setup_and_setup_defined_in_derived_test_case
|
119
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
120
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
121
|
-
include MultipleSetupAndTeardown
|
122
|
-
add_setup_method(:added_setup)
|
123
|
-
define_method(:added_setup) { methods_called << :added_setup }
|
124
|
-
end
|
125
|
-
derived_test_case = Class.new(test_case) do
|
126
|
-
define_method(:setup) { methods_called << :setup }
|
127
|
-
define_method(:test_method) { methods_called << :test_method }
|
128
|
-
end
|
129
|
-
test = derived_test_case.new(:test_method)
|
130
|
-
test_result = Test::Unit::TestResult.new
|
131
|
-
test.run(test_result) {}
|
132
|
-
assert test_result.passed?
|
133
|
-
assert_equal [:added_setup, :setup, :test_method], test.methods_called
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_should_call_added_teardown_and_teardown_defined_in_derived_test_case
|
137
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
138
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
139
|
-
include MultipleSetupAndTeardown
|
140
|
-
add_teardown_method(:added_teardown)
|
141
|
-
define_method(:added_teardown) { methods_called << :added_teardown }
|
142
|
-
end
|
143
|
-
derived_test_case = Class.new(test_case) do
|
144
|
-
define_method(:teardown) { methods_called << :teardown }
|
145
|
-
define_method(:test_method) { methods_called << :test_method }
|
146
|
-
end
|
147
|
-
test = derived_test_case.new(:test_method)
|
148
|
-
test_result = Test::Unit::TestResult.new
|
149
|
-
test.run(test_result) {}
|
150
|
-
assert test_result.passed?
|
151
|
-
assert_equal [:test_method, :teardown, :added_teardown], test.methods_called
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_should_call_added_setup_and_setup_defined_in_derived_test_case_with_active_record_setup_with_fixtures
|
155
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
156
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
157
|
-
include ActiveRecordTestCase
|
158
|
-
include MultipleSetupAndTeardown
|
159
|
-
add_setup_method(:added_setup)
|
160
|
-
define_method(:added_setup) { methods_called << :added_setup }
|
161
|
-
end
|
162
|
-
derived_test_case = Class.new(test_case) do
|
163
|
-
define_method(:setup) { methods_called << :setup }
|
164
|
-
define_method(:test_method) { methods_called << :test_method }
|
165
|
-
end
|
166
|
-
test = derived_test_case.new(:test_method)
|
167
|
-
test_result = Test::Unit::TestResult.new
|
168
|
-
test.run(test_result) {}
|
169
|
-
assert test_result.passed?
|
170
|
-
assert_equal [:setup_with_fixtures, :added_setup, :setup, :test_method, :teardown_with_fixtures], test.methods_called
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_should_call_added_teardown_and_teardown_defined_in_derived_test_case_with_active_record_teardown_with_fixtures
|
174
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
175
|
-
define_method(:methods_called) { @methods_called ||= [] }
|
176
|
-
include ActiveRecordTestCase
|
177
|
-
include MultipleSetupAndTeardown
|
178
|
-
add_teardown_method(:added_teardown)
|
179
|
-
define_method(:added_teardown) { methods_called << :added_teardown }
|
180
|
-
end
|
181
|
-
derived_test_case = Class.new(test_case) do
|
182
|
-
define_method(:teardown) { methods_called << :teardown }
|
183
|
-
define_method(:test_method) { methods_called << :test_method }
|
184
|
-
end
|
185
|
-
test = derived_test_case.new(:test_method)
|
186
|
-
test_result = Test::Unit::TestResult.new
|
187
|
-
test.run(test_result) {}
|
188
|
-
assert test_result.passed?
|
189
|
-
assert_equal [:setup_with_fixtures, :test_method, :teardown, :added_teardown, :teardown_with_fixtures], test.methods_called
|
190
|
-
end
|
191
|
-
|
192
|
-
end
|