mocha 0.10.5 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.rdoc +1 -1
- data/README.rdoc +6 -4
- data/RELEASE.rdoc +12 -0
- data/Rakefile +29 -60
- data/doc/Mocha.html +112 -0
- data/doc/Mocha/API.html +898 -0
- data/doc/Mocha/ClassMethods.html +246 -0
- data/doc/Mocha/Configuration.html +471 -0
- data/doc/Mocha/Expectation.html +2570 -0
- data/doc/Mocha/Mock.html +830 -0
- data/doc/Mocha/ObjectMethods.html +668 -0
- data/doc/Mocha/ParameterMatchers.html +2715 -0
- data/doc/Mocha/ParameterMatchers/AllOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/AnyOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/AnyParameters.html +136 -0
- data/doc/Mocha/ParameterMatchers/Anything.html +136 -0
- data/doc/Mocha/ParameterMatchers/Base.html +419 -0
- data/doc/Mocha/ParameterMatchers/Equals.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasEntries.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasEntry.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasKey.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasValue.html +137 -0
- data/doc/Mocha/ParameterMatchers/Includes.html +137 -0
- data/doc/Mocha/ParameterMatchers/InstanceOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/IsA.html +136 -0
- data/doc/Mocha/ParameterMatchers/KindOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/Not.html +137 -0
- data/doc/Mocha/ParameterMatchers/Optionally.html +136 -0
- data/doc/Mocha/ParameterMatchers/QueryStringMatches.html +136 -0
- data/doc/Mocha/ParameterMatchers/RegexpMatches.html +137 -0
- data/doc/Mocha/ParameterMatchers/RespondsWith.html +137 -0
- data/doc/Mocha/ParameterMatchers/YamlEquivalent.html +137 -0
- data/doc/Mocha/Sequence.html +133 -0
- data/doc/Mocha/StateMachine.html +510 -0
- data/doc/Mocha/StateMachine/State.html +125 -0
- data/doc/Mocha/StateMachine/StatePredicate.html +125 -0
- data/doc/Mocha/StubbingError.html +134 -0
- data/doc/Mocha/UnexpectedInvocation.html +124 -0
- data/doc/_index.html +481 -0
- data/doc/class_list.html +47 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +55 -0
- data/doc/css/style.css +322 -0
- data/doc/file.COPYING.html +72 -0
- data/doc/file.MIT-LICENSE.html +86 -0
- data/doc/file.README.html +153 -0
- data/doc/file.RELEASE.html +933 -0
- data/doc/file.misc.html +108 -0
- data/doc/file.mocha.html +90 -0
- data/doc/file.stubba.html +129 -0
- data/doc/file_list.html +67 -0
- data/doc/frames.html +13 -0
- data/doc/index.html +153 -0
- data/doc/js/app.js +205 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +16 -0
- data/doc/method_list.html +510 -0
- data/doc/top-level-namespace.html +105 -0
- data/lib/mocha/any_instance_method.rb +16 -11
- data/lib/mocha/api.rb +120 -106
- data/lib/mocha/argument_iterator.rb +6 -6
- data/lib/mocha/backtrace_filter.rb +1 -1
- data/lib/mocha/cardinality.rb +21 -21
- data/lib/mocha/central.rb +8 -8
- data/lib/mocha/change_state_side_effect.rb +5 -5
- data/lib/mocha/class_method.rb +14 -19
- data/lib/mocha/configuration.rb +47 -37
- data/lib/mocha/deprecation.rb +8 -8
- data/lib/mocha/exception_raiser.rb +7 -7
- data/lib/mocha/expectation.rb +173 -77
- data/lib/mocha/expectation_error.rb +2 -2
- data/lib/mocha/expectation_list.rb +11 -11
- data/lib/mocha/in_state_ordering_constraint.rb +5 -5
- data/lib/mocha/inspect.rb +8 -8
- data/lib/mocha/instance_method.rb +1 -17
- data/lib/mocha/integration.rb +9 -9
- data/lib/mocha/integration/mini_test/assertion_counter.rb +9 -9
- data/lib/mocha/integration/mini_test/exception_translation.rb +6 -6
- data/lib/mocha/integration/mini_test/version_13.rb +6 -6
- data/lib/mocha/integration/mini_test/version_140.rb +6 -6
- data/lib/mocha/integration/mini_test/version_141.rb +6 -6
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +7 -7
- data/lib/mocha/integration/mini_test/version_200.rb +7 -7
- data/lib/mocha/integration/test_unit/assertion_counter.rb +10 -10
- data/lib/mocha/integration/test_unit/gem_version_200.rb +6 -6
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +6 -6
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +6 -6
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +6 -6
- data/lib/mocha/is_a.rb +1 -1
- data/lib/mocha/logger.rb +6 -6
- data/lib/mocha/method_matcher.rb +7 -7
- data/lib/mocha/mock.rb +85 -48
- data/lib/mocha/mockery.rb +47 -33
- data/lib/mocha/module_method.rb +2 -2
- data/lib/mocha/multiple_yields.rb +9 -9
- data/lib/mocha/names.rb +18 -18
- data/lib/mocha/no_yields.rb +7 -7
- data/lib/mocha/object.rb +104 -75
- data/lib/mocha/parameter_matchers.rb +3 -3
- data/lib/mocha/parameter_matchers/all_of.rb +22 -12
- data/lib/mocha/parameter_matchers/any_of.rb +23 -12
- data/lib/mocha/parameter_matchers/any_parameters.rb +15 -8
- data/lib/mocha/parameter_matchers/anything.rb +20 -11
- data/lib/mocha/parameter_matchers/base.rb +35 -27
- data/lib/mocha/parameter_matchers/equals.rb +23 -12
- data/lib/mocha/parameter_matchers/has_entries.rb +22 -12
- data/lib/mocha/parameter_matchers/has_entry.rb +31 -13
- data/lib/mocha/parameter_matchers/has_key.rb +21 -11
- data/lib/mocha/parameter_matchers/has_value.rb +21 -11
- data/lib/mocha/parameter_matchers/includes.rb +15 -5
- data/lib/mocha/parameter_matchers/instance_of.rb +23 -12
- data/lib/mocha/parameter_matchers/is_a.rb +23 -12
- data/lib/mocha/parameter_matchers/kind_of.rb +23 -12
- data/lib/mocha/parameter_matchers/not.rb +22 -12
- data/lib/mocha/parameter_matchers/object.rb +5 -3
- data/lib/mocha/parameter_matchers/optionally.rb +24 -12
- data/lib/mocha/parameter_matchers/query_string.rb +14 -3
- data/lib/mocha/parameter_matchers/regexp_matches.rb +21 -11
- data/lib/mocha/parameter_matchers/responds_with.rb +17 -6
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +16 -6
- data/lib/mocha/parameters_matcher.rb +8 -8
- data/lib/mocha/pretty_parameters.rb +7 -7
- data/lib/mocha/return_values.rb +11 -11
- data/lib/mocha/sequence.rb +23 -14
- data/lib/mocha/single_return_value.rb +7 -7
- data/lib/mocha/single_yield.rb +9 -9
- data/lib/mocha/standalone.rb +1 -1
- data/lib/mocha/state_machine.rb +61 -46
- data/lib/mocha/stubbing_error.rb +8 -5
- data/lib/mocha/thrower.rb +2 -2
- data/lib/mocha/unexpected_invocation.rb +9 -6
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +10 -10
- data/lib/mocha_standalone.rb +1 -1
- data/mocha.gemspec +4 -7
- data/test/acceptance/acceptance_test_helper.rb +10 -10
- data/test/acceptance/api_test.rb +20 -20
- data/test/acceptance/bug_18914_test.rb +12 -12
- data/test/acceptance/bug_21465_test.rb +6 -6
- data/test/acceptance/bug_21563_test.rb +5 -5
- data/test/acceptance/exception_rescue_test.rb +1 -1
- data/test/acceptance/expected_invocation_count_test.rb +17 -17
- data/test/acceptance/failure_messages_test.rb +13 -13
- data/test/acceptance/minitest_test.rb +39 -39
- data/test/acceptance/mocha_example_test.rb +26 -26
- data/test/acceptance/mocha_test_result_test.rb +13 -13
- data/test/acceptance/mock_test.rb +5 -5
- data/test/acceptance/mock_with_initializer_block_test.rb +5 -5
- data/test/acceptance/mocked_methods_dispatch_test.rb +4 -4
- data/test/acceptance/multiple_expectations_failure_message_test.rb +2 -2
- data/test/acceptance/optional_parameters_test.rb +5 -5
- data/test/acceptance/parameter_matcher_test.rb +18 -18
- data/test/acceptance/partial_mocks_test.rb +9 -9
- data/test/acceptance/raise_exception_test.rb +1 -1
- data/test/acceptance/return_value_test.rb +5 -5
- data/test/acceptance/sequence_test.rb +29 -29
- data/test/acceptance/states_test.rb +17 -17
- data/test/acceptance/stub_any_instance_method_test.rb +13 -13
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +7 -7
- data/test/acceptance/stub_everything_test.rb +5 -5
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +1 -1
- data/test/acceptance/stub_module_method_test.rb +17 -17
- data/test/acceptance/stub_test.rb +5 -5
- data/test/acceptance/stubba_example_test.rb +24 -24
- data/test/acceptance/stubba_test_result_test.rb +11 -11
- data/test/acceptance/stubbing_error_backtrace_test.rb +6 -6
- data/test/acceptance/stubbing_frozen_object_test.rb +88 -0
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +9 -9
- data/test/acceptance/stubbing_nil_test.rb +59 -0
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +13 -13
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +15 -15
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +14 -14
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +13 -13
- data/test/acceptance/stubbing_non_public_class_method_test.rb +12 -12
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +12 -12
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +9 -9
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +35 -0
- data/test/acceptance/throw_test.rb +1 -1
- data/test/deprecation_disabler.rb +1 -1
- data/test/execution_point.rb +7 -7
- data/test/method_definer.rb +1 -1
- data/test/mini_test_result.rb +21 -21
- data/test/simple_counter.rb +5 -5
- data/test/test_helper.rb +1 -1
- data/test/test_runner.rb +22 -24
- data/test/test_unit_result.rb +20 -0
- data/test/unit/any_instance_method_test.rb +28 -32
- data/test/unit/array_inspect_test.rb +3 -3
- data/test/unit/backtrace_filter_test.rb +3 -3
- data/test/unit/cardinality_test.rb +12 -12
- data/test/unit/central_test.rb +18 -18
- data/test/unit/change_state_side_effect_test.rb +12 -12
- data/test/unit/class_method_test.rb +33 -91
- data/test/unit/date_time_inspect_test.rb +4 -4
- data/test/unit/exception_raiser_test.rb +5 -5
- data/test/unit/expectation_list_test.rb +7 -7
- data/test/unit/expectation_test.rb +66 -66
- data/test/unit/hash_inspect_test.rb +4 -4
- data/test/unit/in_state_ordering_constraint_test.rb +13 -13
- data/test/unit/method_matcher_test.rb +3 -3
- data/test/unit/mock_test.rb +40 -40
- data/test/unit/mockery_test.rb +25 -25
- data/test/unit/multiple_yields_test.rb +2 -2
- data/test/unit/no_yields_test.rb +2 -2
- data/test/unit/object_inspect_test.rb +4 -4
- data/test/unit/object_test.rb +15 -15
- data/test/unit/parameter_matchers/all_of_test.rb +6 -6
- data/test/unit/parameter_matchers/any_of_test.rb +6 -6
- data/test/unit/parameter_matchers/anything_test.rb +5 -5
- data/test/unit/parameter_matchers/has_entries_test.rb +10 -10
- data/test/unit/parameter_matchers/has_entry_test.rb +13 -13
- data/test/unit/parameter_matchers/has_key_test.rb +11 -11
- data/test/unit/parameter_matchers/has_value_test.rb +12 -12
- data/test/unit/parameter_matchers/includes_test.rb +4 -4
- data/test/unit/parameter_matchers/not_test.rb +6 -6
- data/test/unit/parameter_matchers/regexp_matches_test.rb +9 -9
- data/test/unit/parameter_matchers/responds_with_test.rb +6 -6
- data/test/unit/parameter_matchers/stub_matcher.rb +4 -4
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +6 -6
- data/test/unit/parameters_matcher_test.rb +16 -16
- data/test/unit/return_values_test.rb +5 -5
- data/test/unit/sequence_test.rb +10 -10
- data/test/unit/single_return_value_test.rb +3 -3
- data/test/unit/single_yield_test.rb +2 -2
- data/test/unit/state_machine_test.rb +19 -19
- data/test/unit/string_inspect_test.rb +2 -2
- data/test/unit/thrower_test.rb +1 -1
- data/test/unit/yield_parameters_test.rb +11 -11
- metadata +113 -101
@@ -6,73 +6,73 @@ require 'execution_point'
|
|
6
6
|
require 'simple_counter'
|
7
7
|
|
8
8
|
class ExpectationTest < Test::Unit::TestCase
|
9
|
-
|
9
|
+
|
10
10
|
include Mocha
|
11
|
-
|
11
|
+
|
12
12
|
def new_expectation
|
13
13
|
Expectation.new(nil, :expected_method)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def test_should_match_calls_to_same_method_with_any_parameters
|
17
17
|
assert new_expectation.match?(:expected_method, 1, 2, 3)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def test_should_match_calls_to_same_method_with_exactly_zero_parameters
|
21
21
|
expectation = new_expectation.with()
|
22
22
|
assert expectation.match?(:expected_method)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters
|
26
26
|
expectation = new_expectation.with()
|
27
27
|
assert !expectation.match?(:expected_method, 1, 2, 3)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def test_should_match_calls_to_same_method_with_expected_parameter_values
|
31
31
|
expectation = new_expectation.with(1, 2, 3)
|
32
32
|
assert expectation.match?(:expected_method, 1, 2, 3)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected
|
36
36
|
expectation = new_expectation.with() {|x, y, z| x + y == z}
|
37
37
|
assert expectation.match?(:expected_method, 1, 2, 3)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
|
41
41
|
expectation = new_expectation.with() {|x, y, z| x + y == z}
|
42
42
|
assert !expectation.match?(:different_method, 1, 2, 3)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def test_should_not_match_calls_to_different_methods_with_no_parameters
|
46
46
|
assert !new_expectation.match?(:unexpected_method)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def test_should_not_match_calls_to_same_method_with_too_few_parameters
|
50
50
|
expectation = new_expectation.with(1, 2, 3)
|
51
51
|
assert !expectation.match?(:unexpected_method, 1, 2)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def test_should_not_match_calls_to_same_method_with_too_many_parameters
|
55
55
|
expectation = new_expectation.with(1, 2)
|
56
56
|
assert !expectation.match?(:unexpected_method, 1, 2, 3)
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def test_should_not_match_calls_to_same_method_with_unexpected_parameter_values
|
60
60
|
expectation = new_expectation.with(1, 2, 3)
|
61
61
|
assert !expectation.match?(:unexpected_method, 1, 0, 3)
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected
|
65
65
|
expectation = new_expectation.with() {|x, y, z| x + y == z}
|
66
66
|
assert !expectation.match?(:expected_method, 1, 0, 3)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two
|
70
70
|
expectation = new_expectation.times(1)
|
71
71
|
assert expectation.invocations_allowed?
|
72
72
|
expectation.invoke
|
73
73
|
assert !expectation.invocations_allowed?
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def test_should_allow_invocations_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three
|
77
77
|
expectation = new_expectation.times(2)
|
78
78
|
assert expectation.invocations_allowed?
|
@@ -92,18 +92,18 @@ class ExpectationTest < Test::Unit::TestCase
|
|
92
92
|
expectation.invoke
|
93
93
|
assert !expectation.invocations_allowed?
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
def test_should_store_provided_backtrace
|
97
97
|
backtrace = Object.new
|
98
98
|
expectation = Expectation.new(nil, :expected_method, backtrace)
|
99
99
|
assert_equal backtrace, expectation.backtrace
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def test_should_default_backtrace_to_caller
|
103
103
|
execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
|
104
104
|
assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
def test_should_not_yield
|
108
108
|
yielded = false
|
109
109
|
new_expectation.invoke() { yielded = true }
|
@@ -131,7 +131,7 @@ class ExpectationTest < Test::Unit::TestCase
|
|
131
131
|
expectation.invoke() { |*parameters| yielded_parameters << parameters }
|
132
132
|
assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
def test_should_yield_multiple_times_for_single_invocation
|
136
136
|
expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5])
|
137
137
|
yielded_parameters = []
|
@@ -151,20 +151,20 @@ class ExpectationTest < Test::Unit::TestCase
|
|
151
151
|
expectation = new_expectation.returns(99)
|
152
152
|
assert_equal 99, expectation.invoke
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
def test_should_return_same_specified_value_multiple_times
|
156
156
|
expectation = new_expectation.returns(99)
|
157
157
|
assert_equal 99, expectation.invoke
|
158
158
|
assert_equal 99, expectation.invoke
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
def test_should_return_specified_values_on_consecutive_calls
|
162
162
|
expectation = new_expectation.returns(99, 100, 101)
|
163
163
|
assert_equal 99, expectation.invoke
|
164
164
|
assert_equal 100, expectation.invoke
|
165
165
|
assert_equal 101, expectation.invoke
|
166
166
|
end
|
167
|
-
|
167
|
+
|
168
168
|
def test_should_return_specified_values_on_consecutive_calls_even_if_values_are_modified
|
169
169
|
values = [99, 100, 101]
|
170
170
|
expectation = new_expectation.returns(*values)
|
@@ -173,27 +173,27 @@ class ExpectationTest < Test::Unit::TestCase
|
|
173
173
|
assert_equal 100, expectation.invoke
|
174
174
|
assert_equal 101, expectation.invoke
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
def test_should_return_nil_by_default
|
178
178
|
assert_nil new_expectation.invoke
|
179
179
|
end
|
180
|
-
|
180
|
+
|
181
181
|
def test_should_return_nil_if_no_value_specified
|
182
182
|
expectation = new_expectation.returns()
|
183
183
|
assert_nil expectation.invoke
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
def test_should_raise_runtime_exception
|
187
187
|
expectation = new_expectation.raises
|
188
188
|
assert_raise(RuntimeError) { expectation.invoke }
|
189
189
|
end
|
190
|
-
|
190
|
+
|
191
191
|
def test_should_raise_custom_exception
|
192
192
|
exception = Class.new(Exception)
|
193
193
|
expectation = new_expectation.raises(exception)
|
194
194
|
assert_raise(exception) { expectation.invoke }
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
def test_should_raise_same_instance_of_custom_exception
|
198
198
|
exception_klass = Class.new(StandardError)
|
199
199
|
expected_exception = exception_klass.new
|
@@ -201,40 +201,40 @@ class ExpectationTest < Test::Unit::TestCase
|
|
201
201
|
actual_exception = assert_raise(exception_klass) { expectation.invoke }
|
202
202
|
assert_same expected_exception, actual_exception
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
def test_should_use_the_default_exception_message
|
206
206
|
expectation = new_expectation.raises(Exception)
|
207
207
|
exception = assert_raise(Exception) { expectation.invoke }
|
208
208
|
assert_equal Exception.new.message, exception.message
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
def test_should_raise_custom_exception_with_message
|
212
212
|
exception_msg = "exception message"
|
213
213
|
expectation = new_expectation.raises(Exception, exception_msg)
|
214
214
|
exception = assert_raise(Exception) { expectation.invoke }
|
215
215
|
assert_equal exception_msg, exception.message
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
def test_should_return_values_then_raise_exception
|
219
219
|
expectation = new_expectation.returns(1, 2).then.raises()
|
220
220
|
assert_equal 1, expectation.invoke
|
221
221
|
assert_equal 2, expectation.invoke
|
222
222
|
assert_raise(RuntimeError) { expectation.invoke }
|
223
223
|
end
|
224
|
-
|
224
|
+
|
225
225
|
def test_should_raise_exception_then_return_values
|
226
226
|
expectation = new_expectation.raises().then.returns(1, 2)
|
227
227
|
assert_raise(RuntimeError) { expectation.invoke }
|
228
228
|
assert_equal 1, expectation.invoke
|
229
229
|
assert_equal 2, expectation.invoke
|
230
230
|
end
|
231
|
-
|
231
|
+
|
232
232
|
def test_should_verify_successfully_if_expected_call_was_made
|
233
233
|
expectation = new_expectation
|
234
234
|
expectation.invoke
|
235
235
|
assert expectation.verified?
|
236
236
|
end
|
237
|
-
|
237
|
+
|
238
238
|
def test_should_not_verify_successfully_if_call_expected_once_but_invoked_twice
|
239
239
|
expectation = new_expectation.once
|
240
240
|
expectation.invoke
|
@@ -279,32 +279,32 @@ class ExpectationTest < Test::Unit::TestCase
|
|
279
279
|
3.times {expectation.invoke}
|
280
280
|
assert expectation.verified?
|
281
281
|
end
|
282
|
-
|
282
|
+
|
283
283
|
def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once
|
284
284
|
expectation = new_expectation.with(1, 2, 3).at_least_once
|
285
285
|
assert !expectation.verified?
|
286
286
|
assert_match(/expected at least once, not yet invoked/i, expectation.mocha_inspect)
|
287
287
|
end
|
288
|
-
|
288
|
+
|
289
289
|
def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times
|
290
290
|
expectation = new_expectation.times(2)
|
291
291
|
2.times {expectation.invoke}
|
292
292
|
assert expectation.verified?
|
293
293
|
end
|
294
|
-
|
294
|
+
|
295
295
|
def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times
|
296
296
|
expectation = new_expectation.times(2)
|
297
297
|
1.times {expectation.invoke}
|
298
298
|
assert !expectation.verified?
|
299
299
|
assert_match(/expected exactly twice, invoked once/i, expectation.mocha_inspect)
|
300
300
|
end
|
301
|
-
|
301
|
+
|
302
302
|
def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times
|
303
303
|
expectation = new_expectation.times(2)
|
304
304
|
3.times {expectation.invoke}
|
305
305
|
assert !expectation.verified?
|
306
306
|
end
|
307
|
-
|
307
|
+
|
308
308
|
def test_should_increment_assertion_counter_for_expectation_because_it_does_need_verifyng
|
309
309
|
expectation = new_expectation
|
310
310
|
expectation.invoke
|
@@ -312,21 +312,21 @@ class ExpectationTest < Test::Unit::TestCase
|
|
312
312
|
expectation.verified?(assertion_counter)
|
313
313
|
assert_equal 1, assertion_counter.count
|
314
314
|
end
|
315
|
-
|
315
|
+
|
316
316
|
def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_need_verifying
|
317
317
|
stub = Expectation.new(nil, :expected_method).at_least(0)
|
318
318
|
assertion_counter = SimpleCounter.new
|
319
319
|
stub.verified?(assertion_counter)
|
320
320
|
assert_equal 0, assertion_counter.count
|
321
321
|
end
|
322
|
-
|
322
|
+
|
323
323
|
def test_should_store_backtrace_from_point_where_expectation_was_created
|
324
324
|
execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
|
325
325
|
assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
|
326
326
|
end
|
327
|
-
|
327
|
+
|
328
328
|
class FakeMock
|
329
|
-
|
329
|
+
|
330
330
|
def initialize(name)
|
331
331
|
@name = name
|
332
332
|
end
|
@@ -334,9 +334,9 @@ class ExpectationTest < Test::Unit::TestCase
|
|
334
334
|
def mocha_inspect
|
335
335
|
@name
|
336
336
|
end
|
337
|
-
|
337
|
+
|
338
338
|
end
|
339
|
-
|
339
|
+
|
340
340
|
def test_should_raise_error_with_message_indicating_which_method_was_expected_to_be_called_on_which_mock_object_with_which_parameters_and_in_what_sequences
|
341
341
|
mock = FakeMock.new('mock')
|
342
342
|
sequence_one = Sequence.new('one')
|
@@ -345,19 +345,19 @@ class ExpectationTest < Test::Unit::TestCase
|
|
345
345
|
assert !expectation.verified?
|
346
346
|
assert_match "mock.expected_method(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]); in sequence 'one'; in sequence 'two'", expectation.mocha_inspect
|
347
347
|
end
|
348
|
-
|
348
|
+
|
349
349
|
class FakeConstraint
|
350
|
-
|
350
|
+
|
351
351
|
def initialize(allows_invocation_now)
|
352
352
|
@allows_invocation_now = allows_invocation_now
|
353
353
|
end
|
354
|
-
|
354
|
+
|
355
355
|
def allows_invocation_now?
|
356
356
|
@allows_invocation_now
|
357
357
|
end
|
358
|
-
|
358
|
+
|
359
359
|
end
|
360
|
-
|
360
|
+
|
361
361
|
def test_should_be_in_correct_order_if_all_ordering_constraints_allow_invocation_now
|
362
362
|
constraint_one = FakeConstraint.new(allows_invocation_now = true)
|
363
363
|
constraint_two = FakeConstraint.new(allows_invocation_now = true)
|
@@ -366,7 +366,7 @@ class ExpectationTest < Test::Unit::TestCase
|
|
366
366
|
expectation.add_ordering_constraint(constraint_two)
|
367
367
|
assert expectation.in_correct_order?
|
368
368
|
end
|
369
|
-
|
369
|
+
|
370
370
|
def test_should_not_be_in_correct_order_if_one_ordering_constraint_does_not_allow_invocation_now
|
371
371
|
constraint_one = FakeConstraint.new(allows_invocation_now = true)
|
372
372
|
constraint_two = FakeConstraint.new(allows_invocation_now = false)
|
@@ -375,7 +375,7 @@ class ExpectationTest < Test::Unit::TestCase
|
|
375
375
|
expectation.add_ordering_constraint(constraint_two)
|
376
376
|
assert !expectation.in_correct_order?
|
377
377
|
end
|
378
|
-
|
378
|
+
|
379
379
|
def test_should_match_if_all_ordering_constraints_allow_invocation_now
|
380
380
|
constraint_one = FakeConstraint.new(allows_invocation_now = true)
|
381
381
|
constraint_two = FakeConstraint.new(allows_invocation_now = true)
|
@@ -416,21 +416,21 @@ class ExpectationTest < Test::Unit::TestCase
|
|
416
416
|
2.times { expectation.invoke }
|
417
417
|
assert expectation.satisfied?
|
418
418
|
end
|
419
|
-
|
419
|
+
|
420
420
|
class FakeSequence
|
421
|
-
|
421
|
+
|
422
422
|
attr_reader :expectations
|
423
|
-
|
423
|
+
|
424
424
|
def initialize
|
425
425
|
@expectations = []
|
426
426
|
end
|
427
|
-
|
427
|
+
|
428
428
|
def constrain_as_next_in_sequence(expectation)
|
429
429
|
@expectations << expectation
|
430
430
|
end
|
431
|
-
|
431
|
+
|
432
432
|
end
|
433
|
-
|
433
|
+
|
434
434
|
def test_should_tell_sequences_to_constrain_expectation_as_next_in_sequence
|
435
435
|
sequence_one = FakeSequence.new
|
436
436
|
sequence_two = FakeSequence.new
|
@@ -439,23 +439,23 @@ class ExpectationTest < Test::Unit::TestCase
|
|
439
439
|
assert_equal [expectation], sequence_one.expectations
|
440
440
|
assert_equal [expectation], sequence_two.expectations
|
441
441
|
end
|
442
|
-
|
442
|
+
|
443
443
|
class FakeState
|
444
|
-
|
444
|
+
|
445
445
|
def initialize
|
446
446
|
@active = false
|
447
447
|
end
|
448
|
-
|
448
|
+
|
449
449
|
def activate
|
450
450
|
@active = true
|
451
451
|
end
|
452
|
-
|
452
|
+
|
453
453
|
def active?
|
454
454
|
@active
|
455
455
|
end
|
456
|
-
|
456
|
+
|
457
457
|
end
|
458
|
-
|
458
|
+
|
459
459
|
def test_should_change_state_when_expectation_is_invoked
|
460
460
|
state = FakeState.new
|
461
461
|
expectation = Expectation.new(nil, :method_one)
|
@@ -465,16 +465,16 @@ class ExpectationTest < Test::Unit::TestCase
|
|
465
465
|
expectation.invoke
|
466
466
|
assert state.active?
|
467
467
|
end
|
468
|
-
|
468
|
+
|
469
469
|
def test_should_match_when_state_is_active
|
470
470
|
state = FakeState.new
|
471
471
|
expectation = Expectation.new(nil, :method_one)
|
472
472
|
|
473
473
|
expectation.when(state)
|
474
474
|
assert !expectation.match?(:method_one)
|
475
|
-
|
475
|
+
|
476
476
|
state.activate
|
477
477
|
assert expectation.match?(:method_one)
|
478
478
|
end
|
479
|
-
|
479
|
+
|
480
480
|
end
|
@@ -2,15 +2,15 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
require 'mocha/inspect'
|
3
3
|
|
4
4
|
class HashInspectTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
def test_should_keep_spacing_between_key_value
|
7
7
|
hash = {:a => true}
|
8
8
|
assert_equal '{:a => true}', hash.mocha_inspect
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def test_should_use_mocha_inspect_on_each_item
|
12
12
|
hash = {:a => 'mocha'}
|
13
13
|
assert_equal "{:a => 'mocha'}", hash.mocha_inspect
|
14
14
|
end
|
15
|
-
|
16
|
-
end
|
15
|
+
|
16
|
+
end
|
@@ -3,41 +3,41 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
3
3
|
require 'mocha/in_state_ordering_constraint'
|
4
4
|
|
5
5
|
class InStateOrderingConstraintTest < Test::Unit::TestCase
|
6
|
-
|
6
|
+
|
7
7
|
include Mocha
|
8
|
-
|
8
|
+
|
9
9
|
class FakeStatePredicate
|
10
|
-
|
10
|
+
|
11
11
|
attr_writer :active, :description
|
12
|
-
|
12
|
+
|
13
13
|
def active?
|
14
14
|
@active
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def mocha_inspect
|
18
18
|
@description
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def test_should_allow_invocation_when_state_is_active
|
24
24
|
state_predicate = FakeStatePredicate.new
|
25
25
|
ordering_constraint = InStateOrderingConstraint.new(state_predicate)
|
26
|
-
|
26
|
+
|
27
27
|
state_predicate.active = true
|
28
28
|
assert ordering_constraint.allows_invocation_now?
|
29
|
-
|
29
|
+
|
30
30
|
state_predicate.active = false
|
31
31
|
assert !ordering_constraint.allows_invocation_now?
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def test_should_describe_itself_in_terms_of_the_state_predicates_description
|
35
35
|
state_predicate = FakeStatePredicate.new
|
36
36
|
ordering_constraint = InStateOrderingConstraint.new(state_predicate)
|
37
|
-
|
37
|
+
|
38
38
|
state_predicate.description = 'the-state-predicate'
|
39
|
-
|
39
|
+
|
40
40
|
assert_equal 'when the-state-predicate', ordering_constraint.mocha_inspect
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|