mocha 0.5.6 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -4
- data/RELEASE +45 -0
- data/Rakefile +55 -33
- data/lib/mocha.rb +1 -0
- data/lib/mocha/any_instance_method.rb +24 -4
- data/lib/mocha/backtrace_filter.rb +17 -0
- data/lib/mocha/cardinality.rb +92 -0
- data/lib/mocha/central.rb +1 -9
- data/lib/mocha/change_state_side_effect.rb +19 -0
- data/lib/mocha/class_method.rb +25 -5
- data/lib/mocha/configuration.rb +60 -0
- data/lib/mocha/exception_raiser.rb +1 -1
- data/lib/mocha/expectation.rb +109 -48
- data/lib/mocha/expectation_error.rb +6 -6
- data/lib/mocha/expectation_list.rb +10 -14
- data/lib/mocha/in_state_ordering_constraint.rb +19 -0
- data/lib/mocha/instance_method.rb +9 -0
- data/lib/mocha/logger.rb +15 -0
- data/lib/mocha/mock.rb +19 -14
- data/lib/mocha/mockery.rb +166 -0
- data/lib/mocha/module_method.rb +17 -0
- data/lib/mocha/names.rb +53 -0
- data/lib/mocha/object.rb +26 -9
- data/lib/mocha/parameter_matchers.rb +2 -1
- data/lib/mocha/parameter_matchers/all_of.rb +3 -3
- data/lib/mocha/parameter_matchers/any_of.rb +3 -3
- data/lib/mocha/parameter_matchers/anything.rb +1 -1
- data/lib/mocha/parameter_matchers/has_entries.rb +4 -1
- data/lib/mocha/parameter_matchers/has_entry.rb +3 -2
- data/lib/mocha/parameter_matchers/has_key.rb +1 -1
- data/lib/mocha/parameter_matchers/has_value.rb +1 -1
- data/lib/mocha/parameter_matchers/not.rb +2 -2
- data/lib/mocha/parameter_matchers/object.rb +1 -1
- data/lib/mocha/parameter_matchers/optionally.rb +22 -0
- data/lib/mocha/parameter_matchers/regexp_matches.rb +2 -2
- data/lib/mocha/parameter_matchers/responds_with.rb +43 -0
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +43 -0
- data/lib/mocha/single_return_value.rb +2 -9
- data/lib/mocha/standalone.rb +151 -17
- data/lib/mocha/state_machine.rb +91 -0
- data/lib/mocha/stubbing_error.rb +16 -0
- data/lib/mocha/test_case_adapter.rb +76 -22
- data/lib/stubba.rb +2 -1
- data/test/acceptance/acceptance_test_helper.rb +38 -0
- data/test/acceptance/bug_18914_test.rb +43 -0
- data/test/acceptance/{expected_invocation_count_acceptance_test.rb → expected_invocation_count_test.rb} +29 -20
- data/test/acceptance/failure_messages_test.rb +64 -0
- data/test/acceptance/{mocha_acceptance_test.rb → mocha_example_test.rb} +5 -5
- data/test/{integration/mocha_test_result_integration_test.rb → acceptance/mocha_test_result_test.rb} +19 -40
- data/test/acceptance/mock_test.rb +100 -0
- data/test/acceptance/{mock_with_initializer_block_acceptance_test.rb → mock_with_initializer_block_test.rb} +12 -5
- data/test/acceptance/{mocked_methods_dispatch_acceptance_test.rb → mocked_methods_dispatch_test.rb} +12 -5
- data/test/acceptance/{optional_parameters_acceptance_test.rb → optional_parameters_test.rb} +11 -4
- data/test/acceptance/{parameter_matcher_acceptance_test.rb → parameter_matcher_test.rb} +67 -5
- data/test/acceptance/{partial_mocks_acceptance_test.rb → partial_mocks_test.rb} +12 -5
- data/test/acceptance/return_value_test.rb +52 -0
- data/test/acceptance/{sequence_acceptance_test.rb → sequence_test.rb} +13 -6
- data/test/acceptance/{standalone_acceptance_test.rb → standalone_test.rb} +19 -11
- data/test/acceptance/states_test.rb +70 -0
- data/test/acceptance/stub_any_instance_method_test.rb +195 -0
- data/test/acceptance/stub_class_method_test.rb +203 -0
- data/test/acceptance/stub_everything_test.rb +56 -0
- data/test/acceptance/stub_instance_method_test.rb +165 -0
- data/test/acceptance/stub_module_method_test.rb +163 -0
- data/test/acceptance/stub_test.rb +52 -0
- data/test/acceptance/{stubba_acceptance_test.rb → stubba_example_test.rb} +1 -1
- data/test/{integration/stubba_test_result_integration_test.rb → acceptance/stubba_test_result_test.rb} +17 -36
- data/test/acceptance/stubbing_error_backtrace_test.rb +64 -0
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +65 -0
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +130 -0
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +155 -0
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +145 -0
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +130 -0
- data/test/acceptance/stubbing_non_public_class_method_test.rb +161 -0
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +141 -0
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +64 -0
- data/test/execution_point.rb +3 -1
- data/test/simple_counter.rb +13 -0
- data/test/test_helper.rb +0 -1
- data/test/test_runner.rb +6 -4
- data/test/unit/any_instance_method_test.rb +1 -1
- data/test/unit/array_inspect_test.rb +1 -1
- data/test/unit/backtrace_filter_test.rb +19 -0
- data/test/unit/cardinality_test.rb +56 -0
- data/test/unit/central_test.rb +4 -63
- data/test/unit/change_state_side_effect_test.rb +41 -0
- data/test/unit/class_method_test.rb +38 -1
- data/test/unit/date_time_inspect_test.rb +1 -1
- data/test/unit/{expectation_raiser_test.rb → exception_raiser_test.rb} +14 -0
- data/test/unit/expectation_list_test.rb +4 -22
- data/test/unit/expectation_test.rb +70 -94
- data/test/unit/in_state_ordering_constraint_test.rb +43 -0
- data/test/unit/mock_test.rb +16 -37
- data/test/unit/mockery_test.rb +149 -0
- data/test/unit/{no_yield_test.rb → no_yields_test.rb} +0 -0
- data/test/unit/object_test.rb +6 -89
- data/test/unit/parameter_matchers/equals_test.rb +25 -0
- data/test/unit/parameter_matchers/has_entries_test.rb +22 -1
- data/test/unit/parameter_matchers/has_entry_test.rb +24 -2
- data/test/unit/parameter_matchers/has_key_test.rb +11 -0
- data/test/unit/parameter_matchers/has_value_test.rb +12 -0
- data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -1
- data/test/unit/parameter_matchers/responds_with_test.rb +25 -0
- data/test/unit/parameter_matchers/stub_matcher.rb +4 -0
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +25 -0
- data/test/unit/single_return_value_test.rb +0 -19
- data/test/unit/state_machine_test.rb +98 -0
- metadata +108 -69
- data/lib/mocha/auto_verify.rb +0 -118
- data/lib/mocha/infinite_range.rb +0 -25
- data/lib/mocha/missing_expectation.rb +0 -17
- data/lib/mocha/setup_and_teardown.rb +0 -23
- data/lib/mocha/stub.rb +0 -18
- data/test/integration/stubba_integration_test.rb +0 -89
- data/test/unit/auto_verify_test.rb +0 -129
- data/test/unit/expectation_error_test.rb +0 -24
- data/test/unit/infinite_range_test.rb +0 -53
- data/test/unit/missing_expectation_test.rb +0 -42
- data/test/unit/setup_and_teardown_test.rb +0 -76
- data/test/unit/stub_test.rb +0 -24
data/test/execution_point.rb
CHANGED
@@ -11,10 +11,12 @@ class ExecutionPoint
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def file_name
|
14
|
+
return "unknown" unless @backtrace && @backtrace.first
|
14
15
|
/\A(.*?):\d+/.match(@backtrace.first)[1]
|
15
16
|
end
|
16
17
|
|
17
18
|
def line_number
|
19
|
+
return "unknown" unless @backtrace && @backtrace.first
|
18
20
|
Integer(/\A.*?:(\d+)/.match(@backtrace.first)[1])
|
19
21
|
end
|
20
22
|
|
@@ -24,7 +26,7 @@ class ExecutionPoint
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def to_s
|
27
|
-
"file: #{file_name} line: #{line_number}"
|
29
|
+
"file: #{file_name}; line: #{line_number}"
|
28
30
|
end
|
29
31
|
|
30
32
|
def inspect
|
data/test/test_helper.rb
CHANGED
@@ -6,7 +6,6 @@ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
|
6
6
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
|
7
7
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit'))
|
8
8
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers'))
|
9
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'integration'))
|
10
9
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance'))
|
11
10
|
|
12
11
|
require 'test/unit'
|
data/test/test_runner.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
require 'test/unit/testresult'
|
2
2
|
require 'test/unit/testcase'
|
3
|
-
require 'mocha/standalone'
|
4
|
-
require 'mocha/test_case_adapter'
|
5
3
|
|
6
4
|
module TestRunner
|
7
5
|
|
8
6
|
def run_test(test_result = Test::Unit::TestResult.new, &block)
|
9
7
|
test_class = Class.new(Test::Unit::TestCase) do
|
10
|
-
include Mocha::Standalone
|
11
|
-
include Mocha::TestCaseAdapter
|
12
8
|
define_method(:test_me, &block)
|
13
9
|
end
|
14
10
|
test = test_class.new(:test_me)
|
15
11
|
test.run(test_result) {}
|
16
12
|
class << test_result
|
17
13
|
attr_reader :failures, :errors
|
14
|
+
def failure_messages
|
15
|
+
failures.map { |failure| failure.message }
|
16
|
+
end
|
17
|
+
def error_messages
|
18
|
+
errors.map { |error| error.message }
|
19
|
+
end
|
18
20
|
end
|
19
21
|
test_result
|
20
22
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/backtrace_filter'
|
3
|
+
|
4
|
+
class BacktraceFilterTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include Mocha
|
7
|
+
|
8
|
+
def test_should_exclude_mocha_locations_from_backtrace
|
9
|
+
mocha_lib = "/username/workspace/mocha_wibble/lib/"
|
10
|
+
backtrace = [ mocha_lib + 'exclude/me/1', mocha_lib + 'exclude/me/2', '/keep/me', mocha_lib + 'exclude/me/3']
|
11
|
+
filter = BacktraceFilter.new(mocha_lib)
|
12
|
+
assert_equal ['/keep/me'], filter.filtered(backtrace)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_determine_path_for_mocha_lib_directory
|
16
|
+
assert_match Regexp.new("/lib/$"), BacktraceFilter::LIB_DIRECTORY
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/cardinality'
|
3
|
+
|
4
|
+
class CardinalityTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include Mocha
|
7
|
+
|
8
|
+
def test_should_allow_invocations_if_invocation_count_has_not_yet_reached_maximum
|
9
|
+
cardinality = Cardinality.new(2, 3)
|
10
|
+
assert cardinality.invocations_allowed?(0)
|
11
|
+
assert cardinality.invocations_allowed?(1)
|
12
|
+
assert cardinality.invocations_allowed?(2)
|
13
|
+
assert !cardinality.invocations_allowed?(3)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_be_satisfied_if_invocations_so_far_have_reached_required_threshold
|
17
|
+
cardinality = Cardinality.new(2, 3)
|
18
|
+
assert !cardinality.satisfied?(0)
|
19
|
+
assert !cardinality.satisfied?(1)
|
20
|
+
assert cardinality.satisfied?(2)
|
21
|
+
assert cardinality.satisfied?(3)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_describe_cardinality
|
25
|
+
assert_equal 'allowed any number of times', Cardinality.at_least(0).mocha_inspect
|
26
|
+
|
27
|
+
assert_equal 'expected at most once', Cardinality.at_most(1).mocha_inspect
|
28
|
+
assert_equal 'expected at most 2 times', Cardinality.at_most(2).mocha_inspect
|
29
|
+
assert_equal 'expected at most 3 times', Cardinality.at_most(3).mocha_inspect
|
30
|
+
|
31
|
+
assert_equal 'expected at least once', Cardinality.at_least(1).mocha_inspect
|
32
|
+
assert_equal 'expected at least 2 times', Cardinality.at_least(2).mocha_inspect
|
33
|
+
assert_equal 'expected at least 3 times', Cardinality.at_least(3).mocha_inspect
|
34
|
+
|
35
|
+
assert_equal 'expected never', Cardinality.exactly(0).mocha_inspect
|
36
|
+
assert_equal 'expected exactly once', Cardinality.exactly(1).mocha_inspect
|
37
|
+
assert_equal 'expected exactly 2 times', Cardinality.exactly(2).mocha_inspect
|
38
|
+
assert_equal 'expected exactly 3 times', Cardinality.times(3).mocha_inspect
|
39
|
+
|
40
|
+
assert_equal 'expected between 2 and 4 times', Cardinality.times(2..4).mocha_inspect
|
41
|
+
assert_equal 'expected between 1 and 3 times', Cardinality.times(1..3).mocha_inspect
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_need_verifying
|
45
|
+
assert Cardinality.exactly(2).needs_verifying?
|
46
|
+
assert Cardinality.at_least(3).needs_verifying?
|
47
|
+
assert Cardinality.at_most(2).needs_verifying?
|
48
|
+
assert Cardinality.times(4).needs_verifying?
|
49
|
+
assert Cardinality.times(2..4).needs_verifying?
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_not_need_verifying
|
53
|
+
assert_equal false, Cardinality.at_least(0).needs_verifying?
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/test/unit/central_test.rb
CHANGED
@@ -21,7 +21,7 @@ class CentralTest < Test::Unit::TestCase
|
|
21
21
|
|
22
22
|
stubba.stub(method)
|
23
23
|
|
24
|
-
method.
|
24
|
+
assert method.verified?
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_should_not_stub_method_if_already_stubbed
|
@@ -34,7 +34,7 @@ class CentralTest < Test::Unit::TestCase
|
|
34
34
|
|
35
35
|
stubba.stub(method)
|
36
36
|
|
37
|
-
method.
|
37
|
+
assert method.verified?
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_should_record_method
|
@@ -58,67 +58,8 @@ class CentralTest < Test::Unit::TestCase
|
|
58
58
|
stubba.unstub_all
|
59
59
|
|
60
60
|
assert_equal [], stubba.stubba_methods
|
61
|
-
method_1.
|
62
|
-
method_2.
|
61
|
+
assert method_1.verified?
|
62
|
+
assert method_2.verified?
|
63
63
|
end
|
64
64
|
|
65
|
-
def test_should_collect_mocks_from_all_methods
|
66
|
-
method_1 = Mock.new
|
67
|
-
method_1.stubs(:mock).returns(:mock_1)
|
68
|
-
|
69
|
-
method_2 = Mock.new
|
70
|
-
method_2.stubs(:mock).returns(:mock_2)
|
71
|
-
|
72
|
-
stubba = Central.new
|
73
|
-
stubba.stubba_methods = [method_1, method_2]
|
74
|
-
|
75
|
-
assert_equal 2, stubba.unique_mocks.length
|
76
|
-
assert stubba.unique_mocks.include?(:mock_1)
|
77
|
-
assert stubba.unique_mocks.include?(:mock_2)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_should_return_unique_mochas
|
81
|
-
method_1 = Mock.new
|
82
|
-
method_1.stubs(:mock).returns(:mock_1)
|
83
|
-
|
84
|
-
method_2 = Mock.new
|
85
|
-
method_2.stubs(:mock).returns(:mock_1)
|
86
|
-
|
87
|
-
stubba = Central.new
|
88
|
-
stubba.stubba_methods = [method_1, method_2]
|
89
|
-
|
90
|
-
assert_equal [:mock_1], stubba.unique_mocks
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_should_call_verify_on_all_unique_mocks
|
94
|
-
mock_class = Class.new do
|
95
|
-
attr_accessor :verify_called
|
96
|
-
def verify
|
97
|
-
self.verify_called = true
|
98
|
-
end
|
99
|
-
end
|
100
|
-
mocks = [mock_class.new, mock_class.new]
|
101
|
-
stubba = Central.new
|
102
|
-
stubba.replace_instance_method(:unique_mocks) { mocks }
|
103
|
-
|
104
|
-
stubba.verify_all
|
105
|
-
|
106
|
-
assert mocks.all? { |mock| mock.verify_called }
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_should_call_verify_on_all_unique_mochas
|
110
|
-
mock_class = Class.new do
|
111
|
-
def verify(&block)
|
112
|
-
yield if block_given?
|
113
|
-
end
|
114
|
-
end
|
115
|
-
stubba = Central.new
|
116
|
-
stubba.replace_instance_method(:unique_mocks) { [mock_class.new] }
|
117
|
-
yielded = false
|
118
|
-
|
119
|
-
stubba.verify_all { yielded = true }
|
120
|
-
|
121
|
-
assert yielded
|
122
|
-
end
|
123
|
-
|
124
65
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/change_state_side_effect'
|
4
|
+
|
5
|
+
class ChangeStateSideEffectTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mocha
|
8
|
+
|
9
|
+
class FakeState
|
10
|
+
|
11
|
+
attr_reader :active
|
12
|
+
attr_writer :description
|
13
|
+
|
14
|
+
def activate
|
15
|
+
@active = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def mocha_inspect
|
19
|
+
@description
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_activate_the_given_state
|
25
|
+
state = FakeState.new
|
26
|
+
side_effect = ChangeStateSideEffect.new(state)
|
27
|
+
|
28
|
+
side_effect.perform
|
29
|
+
|
30
|
+
assert state.active
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_describe_itself_in_terms_of_the_activated_state
|
34
|
+
state = FakeState.new
|
35
|
+
state.description = 'the-new-state'
|
36
|
+
side_effect = ChangeStateSideEffect.new(state)
|
37
|
+
|
38
|
+
assert_equal 'then the-new-state', side_effect.mocha_inspect
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -95,7 +95,7 @@ class ClassMethodTest < Test::Unit::TestCase
|
|
95
95
|
result = klass.method_x(:param1, :param2)
|
96
96
|
|
97
97
|
assert_equal :result, result
|
98
|
-
mocha.
|
98
|
+
assert mocha.verified?
|
99
99
|
end
|
100
100
|
|
101
101
|
def test_should_remove_new_method
|
@@ -196,5 +196,42 @@ class ClassMethodTest < Test::Unit::TestCase
|
|
196
196
|
method = ClassMethod.new(stubbee, :method_name)
|
197
197
|
assert_equal stubbee.mocha, method.mock
|
198
198
|
end
|
199
|
+
|
200
|
+
def test_should_not_be_equal_if_other_object_has_a_different_class
|
201
|
+
class_method = ClassMethod.new(Object.new, :method)
|
202
|
+
other_object = Object.new
|
203
|
+
assert class_method != other_object
|
204
|
+
end
|
199
205
|
|
206
|
+
def test_should_not_be_equal_if_other_class_method_has_different_stubbee
|
207
|
+
stubbee_1 = Object.new
|
208
|
+
stubbee_2 = Object.new
|
209
|
+
class_method_1 = ClassMethod.new(stubbee_1, :method)
|
210
|
+
class_method_2 = ClassMethod.new(stubbee_2, :method)
|
211
|
+
assert class_method_1 != class_method_2
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_should_not_be_equal_if_other_class_method_has_different_method
|
215
|
+
stubbee = Object.new
|
216
|
+
class_method_1 = ClassMethod.new(stubbee, :method_1)
|
217
|
+
class_method_2 = ClassMethod.new(stubbee, :method_2)
|
218
|
+
assert class_method_1 != class_method_2
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_should_be_equal_if_other_class_method_has_same_stubbee_and_same_method_so_no_attempt_is_made_to_stub_a_method_twice
|
222
|
+
stubbee = Object.new
|
223
|
+
class_method_1 = ClassMethod.new(stubbee, :method)
|
224
|
+
class_method_2 = ClassMethod.new(stubbee, :method)
|
225
|
+
assert class_method_1 == class_method_2
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_should_be_equal_if_other_class_method_has_same_stubbee_and_same_method_but_stubbee_equal_method_lies_like_active_record_association_proxy
|
229
|
+
stubbee = Class.new do
|
230
|
+
def equal?(other); false; end
|
231
|
+
end.new
|
232
|
+
class_method_1 = ClassMethod.new(stubbee, :method)
|
233
|
+
class_method_2 = ClassMethod.new(stubbee, :method)
|
234
|
+
assert class_method_1 == class_method_2
|
235
|
+
end
|
236
|
+
|
200
237
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
2
|
|
3
3
|
require 'mocha/exception_raiser'
|
4
|
+
require 'timeout'
|
4
5
|
|
5
6
|
class ExceptionRaiserTest < Test::Unit::TestCase
|
6
7
|
|
@@ -20,9 +21,22 @@ class ExceptionRaiserTest < Test::Unit::TestCase
|
|
20
21
|
assert_equal 'message', exception.message
|
21
22
|
end
|
22
23
|
|
24
|
+
def test_should_raise_exception_instance
|
25
|
+
exception_class = Class.new(StandardError)
|
26
|
+
raiser = ExceptionRaiser.new(exception_class.new('message'), nil)
|
27
|
+
exception = assert_raises(exception_class) { raiser.evaluate }
|
28
|
+
assert_equal 'message', exception.message
|
29
|
+
end
|
30
|
+
|
23
31
|
def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
|
24
32
|
raiser = ExceptionRaiser.new(Interrupt, nil)
|
25
33
|
assert_raises(Interrupt) { raiser.evaluate }
|
26
34
|
end
|
27
35
|
|
36
|
+
def test_should_raise_subclass_of_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
|
37
|
+
exception_class = Class.new(Interrupt)
|
38
|
+
raiser = ExceptionRaiser.new(exception_class, nil)
|
39
|
+
assert_raises(exception_class) { raiser.evaluate }
|
40
|
+
end
|
41
|
+
|
28
42
|
end
|
@@ -13,7 +13,7 @@ class ExpectationListTest < Test::Unit::TestCase
|
|
13
13
|
expectation = Expectation.new(nil, :my_method)
|
14
14
|
assert_same expectation, expectation_list.add(expectation)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def test_should_find_matching_expectation
|
18
18
|
expectation_list = ExpectationList.new
|
19
19
|
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
@@ -22,7 +22,7 @@ class ExpectationListTest < Test::Unit::TestCase
|
|
22
22
|
expectation_list.add(expectation2)
|
23
23
|
assert_same expectation2, expectation_list.detect(:my_method, :argument3, :argument4)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_should_find_most_recent_matching_expectation
|
27
27
|
expectation_list = ExpectationList.new
|
28
28
|
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
@@ -31,7 +31,7 @@ class ExpectationListTest < Test::Unit::TestCase
|
|
31
31
|
expectation_list.add(expectation2)
|
32
32
|
assert_same expectation2, expectation_list.detect(:my_method, :argument1, :argument2)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def test_should_find_most_recent_matching_expectation_but_give_preference_to_those_allowing_invocations
|
36
36
|
expectation_list = ExpectationList.new
|
37
37
|
expectation1 = Expectation.new(nil, :my_method)
|
@@ -42,7 +42,7 @@ class ExpectationListTest < Test::Unit::TestCase
|
|
42
42
|
expectation_list.add(expectation2)
|
43
43
|
assert_same expectation1, expectation_list.detect(:my_method)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def test_should_find_most_recent_matching_expectation_if_no_matching_expectations_allow_invocations
|
47
47
|
expectation_list = ExpectationList.new
|
48
48
|
expectation1 = Expectation.new(nil, :my_method)
|
@@ -54,22 +54,4 @@ class ExpectationListTest < Test::Unit::TestCase
|
|
54
54
|
assert_same expectation2, expectation_list.detect(:my_method)
|
55
55
|
end
|
56
56
|
|
57
|
-
def test_should_find_expectations_for_the_same_method_no_matter_what_the_arguments
|
58
|
-
expectation_list = ExpectationList.new
|
59
|
-
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
60
|
-
expectation_list.add(expectation1)
|
61
|
-
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
|
62
|
-
expectation_list.add(expectation2)
|
63
|
-
assert_equal [expectation1, expectation2].to_set, expectation_list.similar(:my_method).to_set
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_should_ignore_expectations_for_different_methods
|
67
|
-
expectation_list = ExpectationList.new
|
68
|
-
expectation1 = Expectation.new(nil, :method1).with(:argument1, :argument2)
|
69
|
-
expectation_list.add(expectation1)
|
70
|
-
expectation2 = Expectation.new(nil, :method2).with(:argument1, :argument2)
|
71
|
-
expectation_list.add(expectation2)
|
72
|
-
assert_equal [expectation2], expectation_list.similar(:method2)
|
73
|
-
end
|
74
|
-
|
75
57
|
end
|