mocha 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +58 -0
- data/.rubocop_todo.yml +50 -0
- data/RELEASE.md +7 -0
- data/Rakefile +35 -28
- data/bin/build-matrix +17 -18
- data/lib/mocha/any_instance_method.rb +19 -25
- data/lib/mocha/api.rb +1 -5
- data/lib/mocha/argument_iterator.rb +4 -8
- data/lib/mocha/backtrace_filter.rb +1 -5
- data/lib/mocha/cardinality.rb +20 -27
- data/lib/mocha/central.rb +7 -15
- data/lib/mocha/change_state_side_effect.rb +0 -4
- data/lib/mocha/class_method.rb +31 -37
- data/lib/mocha/class_methods.rb +5 -13
- data/lib/mocha/configuration.rb +3 -9
- data/lib/mocha/debug.rb +3 -2
- data/lib/mocha/deprecation.rb +4 -11
- data/lib/mocha/detection/mini_test.rb +0 -2
- data/lib/mocha/detection/test_unit.rb +4 -4
- data/lib/mocha/error_with_filtered_backtrace.rb +0 -4
- data/lib/mocha/exception_raiser.rb +2 -5
- data/lib/mocha/expectation.rb +15 -18
- data/lib/mocha/expectation_error.rb +2 -0
- data/lib/mocha/expectation_error_factory.rb +0 -1
- data/lib/mocha/expectation_list.rb +2 -6
- data/lib/mocha/hooks.rb +0 -1
- data/lib/mocha/in_state_ordering_constraint.rb +0 -4
- data/lib/mocha/inspect.rb +3 -5
- data/lib/mocha/instance_method.rb +0 -2
- data/lib/mocha/integration.rb +3 -4
- data/lib/mocha/integration/mini_test/adapter.rb +2 -4
- data/lib/mocha/integration/mini_test/exception_translation.rb +1 -1
- data/lib/mocha/integration/mini_test/nothing.rb +4 -4
- data/lib/mocha/integration/mini_test/version_13.rb +3 -1
- data/lib/mocha/integration/mini_test/version_140.rb +3 -1
- data/lib/mocha/integration/mini_test/version_141.rb +3 -1
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +3 -1
- data/lib/mocha/integration/mini_test/version_200.rb +3 -1
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +3 -1
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +3 -1
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +3 -1
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +3 -1
- data/lib/mocha/integration/monkey_patcher.rb +5 -7
- data/lib/mocha/integration/test_unit/adapter.rb +5 -6
- data/lib/mocha/integration/test_unit/gem_version_200.rb +4 -2
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +4 -2
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +4 -2
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +4 -2
- data/lib/mocha/integration/test_unit/nothing.rb +4 -4
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +3 -1
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +3 -1
- data/lib/mocha/is_a.rb +0 -2
- data/lib/mocha/logger.rb +0 -4
- data/lib/mocha/method_matcher.rb +1 -5
- data/lib/mocha/minitest.rb +1 -1
- data/lib/mocha/mock.rb +25 -30
- data/lib/mocha/mockery.rb +27 -43
- data/lib/mocha/module_method.rb +0 -2
- data/lib/mocha/module_methods.rb +0 -4
- data/lib/mocha/multiple_yields.rb +0 -5
- data/lib/mocha/names.rb +1 -11
- data/lib/mocha/no_yields.rb +1 -7
- data/lib/mocha/not_initialized_error.rb +0 -2
- data/lib/mocha/object_methods.rb +10 -14
- data/lib/mocha/parameter_matchers.rb +0 -2
- data/lib/mocha/parameter_matchers/all_of.rb +1 -7
- data/lib/mocha/parameter_matchers/any_of.rb +1 -7
- data/lib/mocha/parameter_matchers/any_parameters.rb +3 -9
- data/lib/mocha/parameter_matchers/anything.rb +2 -8
- data/lib/mocha/parameter_matchers/base.rb +6 -12
- data/lib/mocha/parameter_matchers/equals.rb +0 -6
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +6 -6
- data/lib/mocha/parameter_matchers/has_entries.rb +2 -6
- data/lib/mocha/parameter_matchers/has_entry.rb +8 -11
- data/lib/mocha/parameter_matchers/has_key.rb +2 -6
- data/lib/mocha/parameter_matchers/has_value.rb +2 -6
- data/lib/mocha/parameter_matchers/includes.rb +2 -6
- data/lib/mocha/parameter_matchers/instance_of.rb +0 -6
- data/lib/mocha/parameter_matchers/is_a.rb +2 -6
- data/lib/mocha/parameter_matchers/kind_of.rb +2 -6
- data/lib/mocha/parameter_matchers/not.rb +2 -6
- data/lib/mocha/parameter_matchers/object.rb +0 -2
- data/lib/mocha/parameter_matchers/optionally.rb +4 -10
- data/lib/mocha/parameter_matchers/regexp_matches.rb +0 -6
- data/lib/mocha/parameter_matchers/responds_with.rb +3 -8
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +2 -6
- data/lib/mocha/parameters_matcher.rb +6 -9
- data/lib/mocha/pretty_parameters.rb +0 -4
- data/lib/mocha/receivers.rb +6 -12
- data/lib/mocha/return_values.rb +3 -7
- data/lib/mocha/sequence.rb +4 -9
- data/lib/mocha/single_return_value.rb +0 -4
- data/lib/mocha/single_yield.rb +0 -5
- data/lib/mocha/state_machine.rb +6 -10
- data/lib/mocha/stubbing_error.rb +0 -2
- data/lib/mocha/test_unit.rb +1 -1
- data/lib/mocha/thrower.rb +2 -5
- data/lib/mocha/unexpected_invocation.rb +3 -5
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +3 -7
- data/mocha.gemspec +34 -58
- data/test/acceptance/acceptance_test_helper.rb +0 -4
- data/test/acceptance/bug_18914_test.rb +7 -12
- data/test/acceptance/bug_21465_test.rb +0 -2
- data/test/acceptance/bug_21563_test.rb +0 -2
- data/test/acceptance/exception_rescue_test.rb +7 -8
- data/test/acceptance/expectations_on_multiple_methods_test.rb +2 -1
- data/test/acceptance/expected_invocation_count_test.rb +27 -29
- data/test/acceptance/failure_messages_test.rb +3 -5
- data/test/acceptance/issue_272_test.rb +0 -1
- data/test/acceptance/issue_65_test.rb +15 -13
- data/test/acceptance/issue_70_test.rb +0 -1
- data/test/acceptance/mocha_example_test.rb +5 -6
- data/test/acceptance/mocha_test_result_test.rb +7 -7
- data/test/acceptance/mock_test.rb +2 -4
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -2
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -2
- data/test/acceptance/multiple_expectations_failure_message_test.rb +16 -17
- data/test/acceptance/optional_parameters_test.rb +0 -2
- data/test/acceptance/parameter_matcher_test.rb +2 -3
- data/test/acceptance/partial_mocks_test.rb +4 -6
- data/test/acceptance/prepend_test.rb +14 -16
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -2
- data/test/acceptance/raise_exception_test.rb +2 -4
- data/test/acceptance/return_value_test.rb +0 -2
- data/test/acceptance/sequence_test.rb +9 -11
- data/test/acceptance/states_test.rb +6 -4
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +5 -4
- data/test/acceptance/stub_any_instance_method_test.rb +19 -17
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +8 -8
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +2 -1
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -1
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +7 -4
- data/test/acceptance/stub_everything_test.rb +1 -3
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +6 -7
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +2 -1
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -2
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -1
- data/test/acceptance/stub_module_method_test.rb +13 -13
- data/test/acceptance/stub_test.rb +1 -3
- data/test/acceptance/stubba_example_test.rb +6 -14
- data/test/acceptance/stubba_test_result_test.rb +5 -8
- data/test/acceptance/stubbing_error_backtrace_test.rb +2 -2
- data/test/acceptance/stubbing_frozen_object_test.rb +2 -1
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +12 -7
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -2
- data/test/acceptance/stubbing_nil_test.rb +4 -5
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +1 -3
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +3 -3
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +1 -3
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -2
- data/test/acceptance/stubbing_non_public_class_method_test.rb +3 -3
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +1 -3
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +4 -10
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +3 -4
- data/test/acceptance/throw_test.rb +0 -2
- data/test/acceptance/unexpected_invocation_test.rb +2 -3
- data/test/acceptance/unstubbing_test.rb +41 -14
- data/test/deprecation_disabler.rb +0 -1
- data/test/execution_point.rb +2 -4
- data/test/integration/mini_test_test.rb +2 -2
- data/test/integration/shared_tests.rb +24 -22
- data/test/integration/test_unit_test.rb +2 -2
- data/test/method_definer.rb +1 -3
- data/test/mini_test_result.rb +17 -11
- data/test/minitest_result.rb +0 -1
- data/test/simple_counter.rb +0 -2
- data/test/test_helper.rb +13 -5
- data/test/test_runner.rb +2 -4
- data/test/test_unit_result.rb +4 -2
- data/test/unit/any_instance_method_test.rb +31 -17
- data/test/unit/array_inspect_test.rb +2 -4
- data/test/unit/backtrace_filter_test.rb +3 -5
- data/test/unit/cardinality_test.rb +0 -2
- data/test/unit/central_test.rb +26 -27
- data/test/unit/change_state_side_effect_test.rb +0 -4
- data/test/unit/class_method_test.rb +59 -34
- data/test/unit/class_methods_test.rb +9 -11
- data/test/unit/configuration_test.rb +1 -2
- data/test/unit/date_time_inspect_test.rb +1 -3
- data/test/unit/exception_raiser_test.rb +0 -2
- data/test/unit/expectation_list_test.rb +0 -2
- data/test/unit/expectation_test.rb +41 -46
- data/test/unit/hash_inspect_test.rb +3 -5
- data/test/unit/hooks_test.rb +9 -4
- data/test/unit/in_state_ordering_constraint_test.rb +0 -4
- data/test/unit/method_matcher_test.rb +1 -3
- data/test/unit/mock_test.rb +35 -22
- data/test/unit/mockery_test.rb +28 -26
- data/test/unit/module_methods_test.rb +0 -2
- data/test/unit/multiple_yields_test.rb +0 -2
- data/test/unit/no_yields_test.rb +0 -2
- data/test/unit/object_inspect_test.rb +16 -7
- data/test/unit/object_methods_test.rb +6 -8
- data/test/unit/parameter_matchers/all_of_test.rb +0 -2
- data/test/unit/parameter_matchers/any_of_test.rb +0 -2
- data/test/unit/parameter_matchers/anything_test.rb +2 -4
- data/test/unit/parameter_matchers/equals_test.rb +1 -3
- data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -1
- data/test/unit/parameter_matchers/has_entries_test.rb +2 -2
- data/test/unit/parameter_matchers/has_entry_test.rb +13 -14
- data/test/unit/parameter_matchers/has_key_test.rb +0 -1
- data/test/unit/parameter_matchers/has_value_test.rb +0 -2
- data/test/unit/parameter_matchers/includes_test.rb +8 -9
- data/test/unit/parameter_matchers/instance_of_test.rb +1 -3
- data/test/unit/parameter_matchers/is_a_test.rb +1 -3
- data/test/unit/parameter_matchers/kind_of_test.rb +1 -3
- data/test/unit/parameter_matchers/not_test.rb +0 -2
- data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -2
- data/test/unit/parameter_matchers/responds_with_test.rb +9 -3
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -4
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +1 -3
- data/test/unit/parameters_matcher_test.rb +2 -4
- data/test/unit/receivers_test.rb +8 -6
- data/test/unit/return_values_test.rb +3 -5
- data/test/unit/sequence_test.rb +1 -5
- data/test/unit/single_return_value_test.rb +0 -2
- data/test/unit/single_yield_test.rb +0 -2
- data/test/unit/state_machine_test.rb +1 -3
- data/test/unit/string_inspect_test.rb +2 -4
- data/test/unit/thrower_test.rb +0 -2
- data/test/unit/yield_parameters_test.rb +0 -2
- data/yard-templates/default/layout/html/setup.rb +2 -3
- metadata +22 -6
data/test/execution_point.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
class ExecutionPoint
|
2
|
-
|
3
2
|
attr_reader :backtrace
|
4
3
|
|
5
4
|
def self.current
|
@@ -11,7 +10,7 @@ class ExecutionPoint
|
|
11
10
|
end
|
12
11
|
|
13
12
|
def first_relevant_line_of_backtrace
|
14
|
-
@backtrace && (@backtrace.reject { |l|
|
13
|
+
@backtrace && (@backtrace.reject { |l| %r{\Aorg/jruby/}.match(l) }.first || 'unknown:0')
|
15
14
|
end
|
16
15
|
|
17
16
|
def file_name
|
@@ -24,7 +23,7 @@ class ExecutionPoint
|
|
24
23
|
|
25
24
|
def ==(other)
|
26
25
|
return false unless other.is_a?(ExecutionPoint)
|
27
|
-
(file_name == other.file_name)
|
26
|
+
(file_name == other.file_name) && (line_number == other.line_number)
|
28
27
|
end
|
29
28
|
|
30
29
|
def to_s
|
@@ -34,5 +33,4 @@ class ExecutionPoint
|
|
34
33
|
def inspect
|
35
34
|
to_s
|
36
35
|
end
|
37
|
-
|
38
36
|
end
|
@@ -11,6 +11,7 @@ module SharedTests
|
|
11
11
|
assert_passed(test_result)
|
12
12
|
end
|
13
13
|
|
14
|
+
# rubocop:disable Style/Semicolon
|
14
15
|
def test_assertion_unsatisfied
|
15
16
|
execution_point = nil
|
16
17
|
test_result = run_as_test do
|
@@ -24,19 +25,19 @@ module SharedTests
|
|
24
25
|
def test_mock_object_unexpected_invocation
|
25
26
|
execution_point = nil
|
26
27
|
test_result = run_as_test do
|
27
|
-
mock = mock(
|
28
|
+
mock = mock('not expecting invocation')
|
28
29
|
execution_point = ExecutionPoint.current; mock.unexpected
|
29
30
|
end
|
30
31
|
assert_failed(test_result)
|
31
32
|
failure = test_result.failures.first
|
32
33
|
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
33
|
-
assert_equal [
|
34
|
+
assert_equal ['unexpected invocation: #<Mock:not expecting invocation>.unexpected()'], test_result.failure_message_lines
|
34
35
|
end
|
35
36
|
|
36
37
|
def test_mock_object_explicitly_unexpected_invocation
|
37
38
|
execution_point = nil
|
38
39
|
test_result = run_as_test do
|
39
|
-
mock = mock(
|
40
|
+
mock = mock('not expecting invocation')
|
40
41
|
mock.expects(:unexpected).never
|
41
42
|
execution_point = ExecutionPoint.current; mock.unexpected
|
42
43
|
end
|
@@ -44,25 +45,25 @@ module SharedTests
|
|
44
45
|
failure = test_result.failures.first
|
45
46
|
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
46
47
|
assert_equal [
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
'unexpected invocation: #<Mock:not expecting invocation>.unexpected()',
|
49
|
+
'unsatisfied expectations:',
|
50
|
+
'- expected never, invoked once: #<Mock:not expecting invocation>.unexpected(any_parameters)'
|
50
51
|
], test_result.failure_message_lines
|
51
52
|
end
|
52
53
|
|
53
54
|
def test_mock_object_unsatisfied_expectation
|
54
55
|
execution_point = nil
|
55
56
|
test_result = run_as_test do
|
56
|
-
mock = mock(
|
57
|
+
mock = mock('expecting invocation')
|
57
58
|
execution_point = ExecutionPoint.current; mock.expects(:expected)
|
58
59
|
end
|
59
60
|
assert_failed(test_result)
|
60
61
|
failure = test_result.failures.first
|
61
62
|
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
62
63
|
assert_equal [
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
'not all expectations were satisfied',
|
65
|
+
'unsatisfied expectations:',
|
66
|
+
'- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)'
|
66
67
|
], test_result.failure_message_lines
|
67
68
|
end
|
68
69
|
|
@@ -70,7 +71,7 @@ module SharedTests
|
|
70
71
|
execution_point = nil
|
71
72
|
test_result = run_as_tests(
|
72
73
|
:setup => lambda {
|
73
|
-
mock = mock(
|
74
|
+
mock = mock('not expecting invocation')
|
74
75
|
execution_point = ExecutionPoint.current; mock.unexpected
|
75
76
|
},
|
76
77
|
:test_me => lambda {
|
@@ -80,14 +81,14 @@ module SharedTests
|
|
80
81
|
assert_failed(test_result)
|
81
82
|
failure = test_result.failures.first
|
82
83
|
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
83
|
-
assert_equal [
|
84
|
+
assert_equal ['unexpected invocation: #<Mock:not expecting invocation>.unexpected()'], test_result.failure_message_lines
|
84
85
|
end
|
85
86
|
|
86
87
|
def test_mock_object_unsatisfied_expectation_in_setup
|
87
88
|
execution_point = nil
|
88
89
|
test_result = run_as_tests(
|
89
90
|
:setup => lambda {
|
90
|
-
mock = mock(
|
91
|
+
mock = mock('expecting invocation')
|
91
92
|
execution_point = ExecutionPoint.current; mock.expects(:expected)
|
92
93
|
},
|
93
94
|
:test_me => lambda {
|
@@ -98,9 +99,9 @@ module SharedTests
|
|
98
99
|
failure = test_result.failures.first
|
99
100
|
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
100
101
|
assert_equal [
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
'not all expectations were satisfied',
|
103
|
+
'unsatisfied expectations:',
|
104
|
+
'- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)'
|
104
105
|
], test_result.failure_message_lines
|
105
106
|
end
|
106
107
|
|
@@ -111,14 +112,14 @@ module SharedTests
|
|
111
112
|
assert true
|
112
113
|
},
|
113
114
|
:teardown => lambda {
|
114
|
-
mock = mock(
|
115
|
+
mock = mock('not expecting invocation')
|
115
116
|
execution_point = ExecutionPoint.current; mock.unexpected
|
116
117
|
}
|
117
118
|
)
|
118
119
|
assert_failed(test_result)
|
119
120
|
failure = test_result.failures.first
|
120
121
|
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
121
|
-
assert_equal [
|
122
|
+
assert_equal ['unexpected invocation: #<Mock:not expecting invocation>.unexpected()'], test_result.failure_message_lines
|
122
123
|
end
|
123
124
|
|
124
125
|
def test_real_object_explicitly_unexpected_invocation
|
@@ -133,7 +134,7 @@ module SharedTests
|
|
133
134
|
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
134
135
|
assert_equal [
|
135
136
|
"unexpected invocation: #{object.mocha_inspect}.unexpected()",
|
136
|
-
|
137
|
+
'unsatisfied expectations:',
|
137
138
|
"- expected never, invoked once: #{object.mocha_inspect}.unexpected(any_parameters)"
|
138
139
|
], test_result.failure_message_lines
|
139
140
|
end
|
@@ -148,8 +149,8 @@ module SharedTests
|
|
148
149
|
failure = test_result.failures.first
|
149
150
|
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
150
151
|
assert_equal [
|
151
|
-
|
152
|
-
|
152
|
+
'not all expectations were satisfied',
|
153
|
+
'unsatisfied expectations:',
|
153
154
|
"- expected exactly once, not yet invoked: #{object.mocha_inspect}.expected(any_parameters)"
|
154
155
|
], test_result.failure_message_lines
|
155
156
|
end
|
@@ -169,6 +170,7 @@ module SharedTests
|
|
169
170
|
assert_failed(test_result)
|
170
171
|
exception = test_result.errors.first.exception
|
171
172
|
assert_equal execution_point, ExecutionPoint.new(exception.backtrace)
|
172
|
-
assert_match
|
173
|
+
assert_match(/undefined method `foo'/, exception.message)
|
173
174
|
end
|
175
|
+
# rubocop:enable Style/Semicolon
|
174
176
|
end
|
data/test/method_definer.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'metaclass'
|
2
2
|
|
3
3
|
module Mocha
|
4
|
-
|
5
4
|
module ObjectMethods
|
6
5
|
def define_instance_method(method_symbol, &block)
|
7
6
|
__metaclass__.send(:define_method, method_symbol, block)
|
8
7
|
end
|
9
8
|
|
10
9
|
def replace_instance_method(method_symbol, &block)
|
11
|
-
raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless
|
10
|
+
raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless respond_to?(method_symbol)
|
12
11
|
define_instance_method(method_symbol, &block)
|
13
12
|
end
|
14
13
|
|
@@ -16,7 +15,6 @@ module Mocha
|
|
16
15
|
symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) }
|
17
16
|
end
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
|
22
20
|
class Object
|
data/test/mini_test_result.rb
CHANGED
@@ -2,16 +2,15 @@ require 'stringio'
|
|
2
2
|
require 'minitest/unit'
|
3
3
|
|
4
4
|
class MiniTestResult
|
5
|
-
|
6
5
|
minitest_version = Gem::Version.new(::MiniTest::Unit::VERSION)
|
7
6
|
if Gem::Requirement.new('<= 4.6.1').satisfied_by?(minitest_version)
|
8
|
-
FAILURE_PATTERN =
|
9
|
-
ERROR_PATTERN =
|
10
|
-
PATTERN_INDICES = { :method => 2, :testcase => 3 }
|
7
|
+
FAILURE_PATTERN = /(Failure)\:\n([^\(]+)\(([^\)]+)\) \[([^\]]+)\]\:\n(.*)\n/m
|
8
|
+
ERROR_PATTERN = /(Error)\:\n([^\(]+)\(([^\)]+)\)\:\n(.+?)\n/m
|
9
|
+
PATTERN_INDICES = { :method => 2, :testcase => 3 }.freeze
|
11
10
|
else
|
12
|
-
FAILURE_PATTERN =
|
13
|
-
ERROR_PATTERN =
|
14
|
-
PATTERN_INDICES = { :method => 3, :testcase => 2 }
|
11
|
+
FAILURE_PATTERN = /(Failure)\:\n.([^#]+)\#([^ ]+) \[([^\]]+)\]\:\n(.*)\n/m
|
12
|
+
ERROR_PATTERN = /(Error)\:\n.([^#]+)\#([^ ]+)\:\n(.+?)\n/m
|
13
|
+
PATTERN_INDICES = { :method => 3, :testcase => 2 }.freeze
|
15
14
|
end
|
16
15
|
|
17
16
|
def self.parse_failure(raw)
|
@@ -30,7 +29,10 @@ class MiniTestResult
|
|
30
29
|
class Failure
|
31
30
|
attr_reader :method, :test_case, :location, :message
|
32
31
|
def initialize(method, test_case, location, message)
|
33
|
-
@method
|
32
|
+
@method = method
|
33
|
+
@test_case = test_case
|
34
|
+
@location = location
|
35
|
+
@message = message
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
@@ -38,18 +40,22 @@ class MiniTestResult
|
|
38
40
|
class Exception
|
39
41
|
attr_reader :message, :backtrace
|
40
42
|
def initialize(message, location)
|
41
|
-
@message
|
43
|
+
@message = message
|
44
|
+
@backtrace = location
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
45
48
|
attr_reader :method, :test_case, :exception
|
46
49
|
def initialize(method, test_case, message, backtrace)
|
47
|
-
@method
|
50
|
+
@method = method
|
51
|
+
@test_case = test_case
|
52
|
+
@exception = Exception.new(message, backtrace)
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
56
|
def initialize(runner, tests)
|
52
|
-
@runner
|
57
|
+
@runner = runner
|
58
|
+
@tests = tests
|
53
59
|
end
|
54
60
|
|
55
61
|
def failure_count
|
data/test/minitest_result.rb
CHANGED
data/test/simple_counter.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -2,22 +2,26 @@ unless defined?(STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS)
|
|
2
2
|
STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS = Object.instance_methods + Object.private_instance_methods
|
3
3
|
end
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__)))
|
7
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit'))
|
8
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers'))
|
9
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance'))
|
10
10
|
|
11
11
|
require 'mocha/detection/mini_test'
|
12
12
|
|
13
13
|
begin
|
14
14
|
require 'minitest'
|
15
|
+
# rubocop:disable Lint/HandleExceptions
|
15
16
|
rescue LoadError
|
16
17
|
end
|
18
|
+
# rubocop:enable Lint/HandleExceptions
|
17
19
|
begin
|
18
20
|
require 'minitest/unit'
|
21
|
+
# rubocop:disable Lint/HandleExceptions
|
19
22
|
rescue LoadError
|
20
23
|
end
|
24
|
+
# rubocop:enable Lint/HandleExceptions
|
21
25
|
|
22
26
|
module Mocha; end
|
23
27
|
|
@@ -27,6 +31,7 @@ if (minitest_testcase = Mocha::Detection::MiniTest.testcase) && (ENV['MOCHA_RUN_
|
|
27
31
|
rescue LoadError
|
28
32
|
MiniTest::Unit.autorun
|
29
33
|
end
|
34
|
+
# rubocop:disable Style/ClassAndModuleChildren
|
30
35
|
class Mocha::TestCase < minitest_testcase
|
31
36
|
def assert_nothing_raised(exception = StandardError)
|
32
37
|
yield
|
@@ -39,12 +44,15 @@ if (minitest_testcase = Mocha::Detection::MiniTest.testcase) && (ENV['MOCHA_RUN_
|
|
39
44
|
alias_method :assert_not_same, :refute_same
|
40
45
|
alias_method :assert_no_match, :refute_match
|
41
46
|
end
|
47
|
+
# rubocop:enable Style/ClassAndModuleChildren
|
42
48
|
else
|
43
49
|
require 'test/unit'
|
50
|
+
# rubocop:disable Style/ClassAndModuleChildren
|
44
51
|
class Mocha::TestCase < Test::Unit::TestCase
|
45
52
|
def test_dummy
|
46
53
|
# Some versions (?) of Test::Unit try to run this base class as a test case
|
47
54
|
# and it fails because it has no test methods, so I'm adding a dummy test.
|
48
55
|
end
|
49
56
|
end
|
57
|
+
# rubocop:enable Style/ClassAndModuleChildren
|
50
58
|
end
|
data/test/test_runner.rb
CHANGED
@@ -23,9 +23,7 @@ module TestRunner
|
|
23
23
|
minitest_version = Gem::Version.new(Mocha::Detection::MiniTest.version)
|
24
24
|
if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version)
|
25
25
|
require File.expand_path('../minitest_result', __FILE__)
|
26
|
-
tests.each
|
27
|
-
test.run
|
28
|
-
end
|
26
|
+
tests.each(&:run)
|
29
27
|
Minitest::Runnable.runnables.delete(test_class)
|
30
28
|
test_result = MinitestResult.new(tests)
|
31
29
|
elsif Gem::Requirement.new('> 0.0.0', '< 5.0.0').satisfied_by?(minitest_version)
|
@@ -53,6 +51,6 @@ module TestRunner
|
|
53
51
|
end
|
54
52
|
|
55
53
|
def assert_failed(test_result)
|
56
|
-
flunk
|
54
|
+
flunk 'Test passed unexpectedly' unless test_result.failure_count + test_result.error_count > 0
|
57
55
|
end
|
58
56
|
end
|
data/test/test_unit_result.rb
CHANGED
@@ -6,13 +6,15 @@ class TestUnitResult
|
|
6
6
|
class << test_result
|
7
7
|
attr_reader :failures, :errors
|
8
8
|
def failure_messages
|
9
|
-
failures.map
|
9
|
+
failures.map(&:message)
|
10
10
|
end
|
11
|
+
|
11
12
|
def failure_message_lines
|
12
13
|
failure_messages.map { |message| message.split("\n") }.flatten
|
13
14
|
end
|
15
|
+
|
14
16
|
def error_messages
|
15
|
-
errors.map
|
17
|
+
errors.map(&:message)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
test_result
|
@@ -4,19 +4,18 @@ require 'mocha/mock'
|
|
4
4
|
require 'mocha/any_instance_method'
|
5
5
|
|
6
6
|
class AnyInstanceMethodTest < Mocha::TestCase
|
7
|
-
|
8
7
|
include Mocha
|
9
8
|
|
10
|
-
unless RUBY_V2_PLUS
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
unless RUBY_V2_PLUS
|
10
|
+
def test_should_hide_original_method
|
11
|
+
klass = Class.new { def method_x; end }
|
12
|
+
method = AnyInstanceMethod.new(klass, :method_x)
|
14
13
|
|
15
|
-
|
14
|
+
method.hide_original_method
|
16
15
|
|
17
|
-
|
16
|
+
assert_equal false, klass.method_defined?(:method_x)
|
17
|
+
end
|
18
18
|
end
|
19
|
-
end
|
20
19
|
|
21
20
|
def test_should_not_raise_error_hiding_method_that_isnt_defined
|
22
21
|
klass = Class.new
|
@@ -45,7 +44,11 @@ end
|
|
45
44
|
end
|
46
45
|
|
47
46
|
def test_should_restore_original_method
|
48
|
-
klass = Class.new
|
47
|
+
klass = Class.new do
|
48
|
+
def method_x
|
49
|
+
:original_result
|
50
|
+
end
|
51
|
+
end
|
49
52
|
method = AnyInstanceMethod.new(klass, :method_x)
|
50
53
|
|
51
54
|
method.hide_original_method
|
@@ -59,7 +62,11 @@ end
|
|
59
62
|
end
|
60
63
|
|
61
64
|
def test_should_not_restore_original_method_if_none_was_defined_in_first_place
|
62
|
-
klass = Class.new
|
65
|
+
klass = Class.new do
|
66
|
+
def method_x
|
67
|
+
:new_result
|
68
|
+
end
|
69
|
+
end
|
63
70
|
method = AnyInstanceMethod.new(klass, :method_x)
|
64
71
|
|
65
72
|
method.restore_original_method
|
@@ -75,8 +82,8 @@ end
|
|
75
82
|
any_instance.stubs(:mocha).returns(any_instance_mocha)
|
76
83
|
klass.define_instance_method(:any_instance) { any_instance }
|
77
84
|
method = AnyInstanceMethod.new(klass, :method_x)
|
78
|
-
method.replace_instance_method(:restore_original_method) {
|
79
|
-
method.replace_instance_method(:reset_mocha) {
|
85
|
+
method.replace_instance_method(:restore_original_method) {}
|
86
|
+
method.replace_instance_method(:reset_mocha) {}
|
80
87
|
method.define_instance_accessor(:remove_called)
|
81
88
|
method.replace_instance_method(:remove_new_method) { self.remove_called = true }
|
82
89
|
|
@@ -92,8 +99,8 @@ end
|
|
92
99
|
any_instance.stubs(:mocha).returns(any_instance_mocha)
|
93
100
|
klass.define_instance_method(:any_instance) { any_instance }
|
94
101
|
method = AnyInstanceMethod.new(klass, :method_x)
|
95
|
-
method.replace_instance_method(:remove_new_method) {
|
96
|
-
method.replace_instance_method(:reset_mocha) {
|
102
|
+
method.replace_instance_method(:remove_new_method) {}
|
103
|
+
method.replace_instance_method(:reset_mocha) {}
|
97
104
|
method.define_instance_accessor(:restore_called)
|
98
105
|
method.replace_instance_method(:restore_original_method) { self.restore_called = true }
|
99
106
|
|
@@ -107,9 +114,16 @@ end
|
|
107
114
|
|
108
115
|
method = AnyInstanceMethod.new(klass, :method_x)
|
109
116
|
|
110
|
-
method.replace_instance_method(:remove_new_method) {
|
111
|
-
method.replace_instance_method(:restore_original_method) {
|
112
|
-
mocha = Class.new
|
117
|
+
method.replace_instance_method(:remove_new_method) {}
|
118
|
+
method.replace_instance_method(:restore_original_method) {}
|
119
|
+
mocha = Class.new do
|
120
|
+
class << self
|
121
|
+
attr_accessor :unstub_method
|
122
|
+
end
|
123
|
+
def self.unstub(method)
|
124
|
+
self.unstub_method = method
|
125
|
+
end
|
126
|
+
end
|
113
127
|
mocha.define_instance_method(:any_expectations?) { true }
|
114
128
|
method.replace_instance_method(:mock) { mocha }
|
115
129
|
|