mocha 1.2.1 → 1.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +61 -0
- data/.rubocop_todo.yml +27 -0
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +4 -9
- data/Gemfile +29 -0
- data/README.md +104 -106
- data/RELEASE.md +277 -1
- data/Rakefile +46 -44
- data/gemfiles/Gemfile.minitest.latest +1 -0
- data/gemfiles/Gemfile.test-unit.latest +2 -5
- data/init.rb +1 -3
- data/lib/mocha/any_instance_method.rb +9 -62
- data/lib/mocha/api.rb +144 -68
- data/lib/mocha/argument_iterator.rb +4 -8
- data/lib/mocha/backtrace_filter.rb +1 -5
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +60 -49
- data/lib/mocha/central.rb +21 -12
- data/lib/mocha/change_state_side_effect.rb +0 -4
- data/lib/mocha/class_methods.rb +19 -21
- data/lib/mocha/configuration.rb +372 -18
- data/lib/mocha/debug.rb +3 -2
- data/lib/mocha/deprecation.rb +8 -11
- data/lib/mocha/detection/mini_test.rb +0 -2
- data/lib/mocha/detection/test_unit.rb +3 -5
- data/lib/mocha/error_with_filtered_backtrace.rb +13 -0
- data/lib/mocha/exception_raiser.rb +4 -6
- data/lib/mocha/expectation.rb +125 -89
- data/lib/mocha/expectation_error.rb +1 -1
- data/lib/mocha/expectation_error_factory.rb +0 -1
- data/lib/mocha/expectation_list.rb +7 -11
- data/lib/mocha/hooks.rb +1 -3
- data/lib/mocha/in_state_ordering_constraint.rb +0 -4
- data/lib/mocha/inspect.rb +30 -38
- data/lib/mocha/instance_method.rb +11 -8
- 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 +4 -1
- data/lib/mocha/integration/mini_test/version_140.rb +4 -1
- data/lib/mocha/integration/mini_test/version_141.rb +4 -1
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +4 -1
- data/lib/mocha/integration/mini_test/version_200.rb +4 -1
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +4 -1
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +4 -1
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +4 -1
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +4 -1
- data/lib/mocha/integration/mini_test.rb +7 -0
- 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 +5 -2
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +5 -2
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +5 -2
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +5 -2
- data/lib/mocha/integration/test_unit/nothing.rb +4 -4
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +4 -1
- data/lib/mocha/integration/test_unit.rb +7 -2
- data/lib/mocha/integration.rb +2 -5
- data/lib/mocha/invocation.rb +86 -0
- data/lib/mocha/is_a.rb +0 -2
- data/lib/mocha/logger.rb +0 -4
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/method_matcher.rb +1 -5
- data/lib/mocha/minitest.rb +9 -0
- data/lib/mocha/mock.rb +102 -58
- data/lib/mocha/mockery.rb +70 -99
- data/lib/mocha/names.rb +2 -12
- data/lib/mocha/not_initialized_error.rb +7 -0
- data/lib/mocha/object_methods.rb +25 -31
- data/lib/mocha/parameter_matchers/all_of.rb +2 -8
- data/lib/mocha/parameter_matchers/any_of.rb +2 -8
- 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/{query_string.rb → equivalent_uri.rb} +15 -15
- data/lib/mocha/parameter_matchers/has_entries.rb +2 -7
- data/lib/mocha/parameter_matchers/has_entry.rb +26 -21
- data/lib/mocha/parameter_matchers/has_key.rb +2 -7
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/has_value.rb +2 -7
- data/lib/mocha/parameter_matchers/includes.rb +6 -7
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- data/lib/mocha/parameter_matchers/instance_of.rb +0 -6
- data/lib/mocha/parameter_matchers/is_a.rb +2 -7
- data/lib/mocha/parameter_matchers/kind_of.rb +2 -6
- data/lib/mocha/parameter_matchers/not.rb +2 -7
- 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/parameter_matchers.rb +3 -4
- data/lib/mocha/parameters_matcher.rb +6 -9
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/receivers.rb +10 -14
- data/lib/mocha/return_values.rb +4 -8
- data/lib/mocha/ruby_version.rb +8 -1
- data/lib/mocha/sequence.rb +4 -9
- data/lib/mocha/setup.rb +5 -0
- data/lib/mocha/single_return_value.rb +2 -5
- data/lib/mocha/state_machine.rb +33 -46
- data/lib/mocha/stubbed_method.rb +124 -0
- data/lib/mocha/stubbing_error.rb +2 -13
- data/lib/mocha/test_unit.rb +8 -2
- data/lib/mocha/thrower.rb +4 -6
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +7 -17
- data/mocha.gemspec +14 -65
- data/yard-templates/default/layout/html/google_analytics.erb +6 -9
- data/yard-templates/default/layout/html/setup.rb +2 -3
- metadata +25 -247
- data/bin/build-matrix +0 -70
- data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
- data/lib/mocha/class_method.rb +0 -119
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +0 -58
- data/lib/mocha/mini_test.rb +0 -3
- data/lib/mocha/module_method.rb +0 -16
- data/lib/mocha/module_methods.rb +0 -14
- data/lib/mocha/multiple_yields.rb +0 -20
- data/lib/mocha/no_yields.rb +0 -11
- data/lib/mocha/parameter_matchers/object.rb +0 -17
- data/lib/mocha/pretty_parameters.rb +0 -28
- data/lib/mocha/single_yield.rb +0 -18
- data/lib/mocha/standalone.rb +0 -4
- data/lib/mocha/unexpected_invocation.rb +0 -26
- data/lib/mocha_standalone.rb +0 -4
- data/test/acceptance/acceptance_test_helper.rb +0 -41
- data/test/acceptance/bug_18914_test.rb +0 -43
- data/test/acceptance/bug_21465_test.rb +0 -34
- data/test/acceptance/bug_21563_test.rb +0 -25
- data/test/acceptance/exception_rescue_test.rb +0 -55
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
- data/test/acceptance/expected_invocation_count_test.rb +0 -232
- data/test/acceptance/failure_messages_test.rb +0 -64
- data/test/acceptance/issue_272_test.rb +0 -52
- data/test/acceptance/issue_65_test.rb +0 -63
- data/test/acceptance/issue_70_test.rb +0 -55
- data/test/acceptance/mocha_example_test.rb +0 -98
- data/test/acceptance/mocha_test_result_test.rb +0 -84
- data/test/acceptance/mock_test.rb +0 -100
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -51
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -78
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -68
- data/test/acceptance/optional_parameters_test.rb +0 -70
- data/test/acceptance/parameter_matcher_test.rb +0 -337
- data/test/acceptance/partial_mocks_test.rb +0 -47
- data/test/acceptance/prepend_test.rb +0 -89
- data/test/acceptance/raise_exception_test.rb +0 -39
- data/test/acceptance/return_value_test.rb +0 -52
- data/test/acceptance/sequence_test.rb +0 -192
- data/test/acceptance/states_test.rb +0 -70
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -34
- data/test/acceptance/stub_any_instance_method_test.rb +0 -280
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -106
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -75
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -112
- data/test/acceptance/stub_everything_test.rb +0 -56
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -93
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -69
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -69
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -78
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -70
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -72
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -39
- data/test/acceptance/stub_module_method_test.rb +0 -163
- data/test/acceptance/stub_test.rb +0 -52
- data/test/acceptance/stubba_example_test.rb +0 -102
- data/test/acceptance/stubba_test_result_test.rb +0 -66
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -48
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -65
- data/test/acceptance/stubbing_nil_test.rb +0 -61
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -143
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -147
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -130
- data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -143
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -64
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -35
- data/test/acceptance/throw_test.rb +0 -45
- data/test/acceptance/unexpected_invocation_test.rb +0 -25
- data/test/acceptance/unstubbing_test.rb +0 -168
- data/test/assertions.rb +0 -8
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -36
- data/test/integration/mini_test_test.rb +0 -8
- data/test/integration/shared_tests.rb +0 -174
- data/test/integration/test_unit_test.rb +0 -8
- data/test/method_definer.rb +0 -24
- data/test/mini_test_result.rb +0 -90
- data/test/minitest_result.rb +0 -49
- data/test/simple_counter.rb +0 -13
- data/test/test_helper.rb +0 -50
- data/test/test_runner.rb +0 -58
- data/test/test_unit_result.rb +0 -20
- data/test/unit/any_instance_method_test.rb +0 -134
- data/test/unit/array_inspect_test.rb +0 -16
- data/test/unit/backtrace_filter_test.rb +0 -19
- data/test/unit/cardinality_test.rb +0 -56
- data/test/unit/central_test.rb +0 -100
- data/test/unit/change_state_side_effect_test.rb +0 -41
- data/test/unit/class_method_test.rb +0 -225
- data/test/unit/class_methods_test.rb +0 -40
- data/test/unit/configuration_test.rb +0 -38
- data/test/unit/date_time_inspect_test.rb +0 -21
- data/test/unit/exception_raiser_test.rb +0 -42
- data/test/unit/expectation_list_test.rb +0 -82
- data/test/unit/expectation_test.rb +0 -497
- data/test/unit/hash_inspect_test.rb +0 -16
- data/test/unit/hooks_test.rb +0 -29
- data/test/unit/in_state_ordering_constraint_test.rb +0 -43
- data/test/unit/method_matcher_test.rb +0 -28
- data/test/unit/mock_test.rb +0 -342
- data/test/unit/mockery_test.rb +0 -151
- data/test/unit/module_methods_test.rb +0 -19
- data/test/unit/multiple_yields_test.rb +0 -18
- data/test/unit/no_yields_test.rb +0 -18
- data/test/unit/object_inspect_test.rb +0 -39
- data/test/unit/object_methods_test.rb +0 -46
- data/test/unit/parameter_matchers/all_of_test.rb +0 -26
- data/test/unit/parameter_matchers/any_of_test.rb +0 -26
- data/test/unit/parameter_matchers/anything_test.rb +0 -21
- data/test/unit/parameter_matchers/equals_test.rb +0 -25
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -129
- data/test/unit/parameter_matchers/has_key_test.rb +0 -55
- data/test/unit/parameter_matchers/has_value_test.rb +0 -57
- data/test/unit/parameter_matchers/includes_test.rb +0 -102
- data/test/unit/parameter_matchers/instance_of_test.rb +0 -25
- data/test/unit/parameter_matchers/is_a_test.rb +0 -25
- data/test/unit/parameter_matchers/kind_of_test.rb +0 -25
- data/test/unit/parameter_matchers/not_test.rb +0 -26
- data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -46
- data/test/unit/parameter_matchers/responds_with_test.rb +0 -32
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -27
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -25
- data/test/unit/parameters_matcher_test.rb +0 -121
- data/test/unit/receivers_test.rb +0 -66
- data/test/unit/return_values_test.rb +0 -63
- data/test/unit/sequence_test.rb +0 -104
- data/test/unit/single_return_value_test.rb +0 -14
- data/test/unit/single_yield_test.rb +0 -18
- data/test/unit/state_machine_test.rb +0 -98
- data/test/unit/string_inspect_test.rb +0 -11
- data/test/unit/thrower_test.rb +0 -20
- data/test/unit/yield_parameters_test.rb +0 -93
data/test/execution_point.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
class ExecutionPoint
|
2
|
-
|
3
|
-
attr_reader :backtrace
|
4
|
-
|
5
|
-
def self.current
|
6
|
-
new(caller)
|
7
|
-
end
|
8
|
-
|
9
|
-
def initialize(backtrace)
|
10
|
-
@backtrace = backtrace
|
11
|
-
end
|
12
|
-
|
13
|
-
def file_name
|
14
|
-
return "unknown" unless @backtrace && @backtrace.first
|
15
|
-
/\A(.*?):\d+/.match(@backtrace.first)[1]
|
16
|
-
end
|
17
|
-
|
18
|
-
def line_number
|
19
|
-
return "unknown" unless @backtrace && @backtrace.first
|
20
|
-
Integer(/\A.*?:(\d+)/.match(@backtrace.first)[1])
|
21
|
-
end
|
22
|
-
|
23
|
-
def ==(other)
|
24
|
-
return false unless other.is_a?(ExecutionPoint)
|
25
|
-
(file_name == other.file_name) and (line_number == other.line_number)
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_s
|
29
|
-
"file: #{file_name}; line: #{line_number}"
|
30
|
-
end
|
31
|
-
|
32
|
-
def inspect
|
33
|
-
to_s
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
@@ -1,174 +0,0 @@
|
|
1
|
-
require 'test_runner'
|
2
|
-
require 'execution_point'
|
3
|
-
|
4
|
-
module SharedTests
|
5
|
-
include TestRunner
|
6
|
-
|
7
|
-
def test_assertion_satisfied
|
8
|
-
test_result = run_as_test do
|
9
|
-
assert true
|
10
|
-
end
|
11
|
-
assert_passed(test_result)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_assertion_unsatisfied
|
15
|
-
execution_point = nil
|
16
|
-
test_result = run_as_test do
|
17
|
-
execution_point = ExecutionPoint.current; flunk
|
18
|
-
end
|
19
|
-
assert_failed(test_result)
|
20
|
-
failure = test_result.failures.first
|
21
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_mock_object_unexpected_invocation
|
25
|
-
execution_point = nil
|
26
|
-
test_result = run_as_test do
|
27
|
-
mock = mock("not expecting invocation")
|
28
|
-
execution_point = ExecutionPoint.current; mock.unexpected
|
29
|
-
end
|
30
|
-
assert_failed(test_result)
|
31
|
-
failure = test_result.failures.first
|
32
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
33
|
-
assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_mock_object_explicitly_unexpected_invocation
|
37
|
-
execution_point = nil
|
38
|
-
test_result = run_as_test do
|
39
|
-
mock = mock("not expecting invocation")
|
40
|
-
mock.expects(:unexpected).never
|
41
|
-
execution_point = ExecutionPoint.current; mock.unexpected
|
42
|
-
end
|
43
|
-
assert_failed(test_result)
|
44
|
-
failure = test_result.failures.first
|
45
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
46
|
-
assert_equal [
|
47
|
-
"unexpected invocation: #<Mock:not expecting invocation>.unexpected()",
|
48
|
-
"unsatisfied expectations:",
|
49
|
-
"- expected never, invoked once: #<Mock:not expecting invocation>.unexpected(any_parameters)"
|
50
|
-
], test_result.failure_message_lines
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_mock_object_unsatisfied_expectation
|
54
|
-
execution_point = nil
|
55
|
-
test_result = run_as_test do
|
56
|
-
mock = mock("expecting invocation")
|
57
|
-
execution_point = ExecutionPoint.current; mock.expects(:expected)
|
58
|
-
end
|
59
|
-
assert_failed(test_result)
|
60
|
-
failure = test_result.failures.first
|
61
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
62
|
-
assert_equal [
|
63
|
-
"not all expectations were satisfied",
|
64
|
-
"unsatisfied expectations:",
|
65
|
-
"- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)"
|
66
|
-
], test_result.failure_message_lines
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_mock_object_unexpected_invocation_in_setup
|
70
|
-
execution_point = nil
|
71
|
-
test_result = run_as_tests(
|
72
|
-
:setup => lambda {
|
73
|
-
mock = mock("not expecting invocation")
|
74
|
-
execution_point = ExecutionPoint.current; mock.unexpected
|
75
|
-
},
|
76
|
-
:test_me => lambda {
|
77
|
-
assert true
|
78
|
-
}
|
79
|
-
)
|
80
|
-
assert_failed(test_result)
|
81
|
-
failure = test_result.failures.first
|
82
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
83
|
-
assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_mock_object_unsatisfied_expectation_in_setup
|
87
|
-
execution_point = nil
|
88
|
-
test_result = run_as_tests(
|
89
|
-
:setup => lambda {
|
90
|
-
mock = mock("expecting invocation")
|
91
|
-
execution_point = ExecutionPoint.current; mock.expects(:expected)
|
92
|
-
},
|
93
|
-
:test_me => lambda {
|
94
|
-
assert true
|
95
|
-
}
|
96
|
-
)
|
97
|
-
assert_failed(test_result)
|
98
|
-
failure = test_result.failures.first
|
99
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
100
|
-
assert_equal [
|
101
|
-
"not all expectations were satisfied",
|
102
|
-
"unsatisfied expectations:",
|
103
|
-
"- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)"
|
104
|
-
], test_result.failure_message_lines
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_mock_object_unexpected_invocation_in_teardown
|
108
|
-
execution_point = nil
|
109
|
-
test_result = run_as_tests(
|
110
|
-
:test_me => lambda {
|
111
|
-
assert true
|
112
|
-
},
|
113
|
-
:teardown => lambda {
|
114
|
-
mock = mock("not expecting invocation")
|
115
|
-
execution_point = ExecutionPoint.current; mock.unexpected
|
116
|
-
}
|
117
|
-
)
|
118
|
-
assert_failed(test_result)
|
119
|
-
failure = test_result.failures.first
|
120
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
121
|
-
assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_real_object_explicitly_unexpected_invocation
|
125
|
-
execution_point = nil
|
126
|
-
object = Object.new
|
127
|
-
test_result = run_as_test do
|
128
|
-
object.expects(:unexpected).never
|
129
|
-
execution_point = ExecutionPoint.current; object.unexpected
|
130
|
-
end
|
131
|
-
assert_failed(test_result)
|
132
|
-
failure = test_result.failures.first
|
133
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
134
|
-
assert_equal [
|
135
|
-
"unexpected invocation: #{object.mocha_inspect}.unexpected()",
|
136
|
-
"unsatisfied expectations:",
|
137
|
-
"- expected never, invoked once: #{object.mocha_inspect}.unexpected(any_parameters)"
|
138
|
-
], test_result.failure_message_lines
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_real_object_unsatisfied_expectation
|
142
|
-
execution_point = nil
|
143
|
-
object = Object.new
|
144
|
-
test_result = run_as_test do
|
145
|
-
execution_point = ExecutionPoint.current; object.expects(:expected)
|
146
|
-
end
|
147
|
-
assert_failed(test_result)
|
148
|
-
failure = test_result.failures.first
|
149
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
150
|
-
assert_equal [
|
151
|
-
"not all expectations were satisfied",
|
152
|
-
"unsatisfied expectations:",
|
153
|
-
"- expected exactly once, not yet invoked: #{object.mocha_inspect}.expected(any_parameters)"
|
154
|
-
], test_result.failure_message_lines
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_real_object_expectation_does_not_leak_into_subsequent_test
|
158
|
-
execution_point = nil
|
159
|
-
klass = Class.new
|
160
|
-
test_result = run_as_tests(
|
161
|
-
:test_1 => lambda {
|
162
|
-
klass.expects(:foo)
|
163
|
-
klass.foo
|
164
|
-
},
|
165
|
-
:test_2 => lambda {
|
166
|
-
execution_point = ExecutionPoint.current; klass.foo
|
167
|
-
}
|
168
|
-
)
|
169
|
-
assert_failed(test_result)
|
170
|
-
exception = test_result.errors.first.exception
|
171
|
-
assert_equal execution_point, ExecutionPoint.new(exception.backtrace)
|
172
|
-
assert_match %r{undefined method `foo'}, exception.message
|
173
|
-
end
|
174
|
-
end
|
data/test/method_definer.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'metaclass'
|
2
|
-
|
3
|
-
module Mocha
|
4
|
-
|
5
|
-
module ObjectMethods
|
6
|
-
def define_instance_method(method_symbol, &block)
|
7
|
-
__metaclass__.send(:define_method, method_symbol, block)
|
8
|
-
end
|
9
|
-
|
10
|
-
def replace_instance_method(method_symbol, &block)
|
11
|
-
raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless self.respond_to?(method_symbol)
|
12
|
-
define_instance_method(method_symbol, &block)
|
13
|
-
end
|
14
|
-
|
15
|
-
def define_instance_accessor(*symbols)
|
16
|
-
symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
class Object
|
23
|
-
include Mocha::ObjectMethods
|
24
|
-
end
|
data/test/mini_test_result.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
require 'minitest/unit'
|
3
|
-
|
4
|
-
class MiniTestResult
|
5
|
-
|
6
|
-
minitest_version = Gem::Version.new(::MiniTest::Unit::VERSION)
|
7
|
-
if Gem::Requirement.new('<= 4.6.1').satisfied_by?(minitest_version)
|
8
|
-
FAILURE_PATTERN = %r{(Failure)\:\n([^\(]+)\(([^\)]+)\) \[([^\]]+)\]\:\n(.*)\n}m
|
9
|
-
ERROR_PATTERN = %r{(Error)\:\n([^\(]+)\(([^\)]+)\)\:\n(.+?)\n}m
|
10
|
-
PATTERN_INDICES = { :method => 2, :testcase => 3 }
|
11
|
-
else
|
12
|
-
FAILURE_PATTERN = %r{(Failure)\:\n.([^#]+)\#([^ ]+) \[([^\]]+)\]\:\n(.*)\n}m
|
13
|
-
ERROR_PATTERN = %r{(Error)\:\n.([^#]+)\#([^ ]+)\:\n(.+?)\n}m
|
14
|
-
PATTERN_INDICES = { :method => 3, :testcase => 2 }
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.parse_failure(raw)
|
18
|
-
matches = FAILURE_PATTERN.match(raw)
|
19
|
-
return nil unless matches
|
20
|
-
Failure.new(matches[PATTERN_INDICES[:method]], matches[PATTERN_INDICES[:testcase]], [matches[4]], matches[5])
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.parse_error(raw)
|
24
|
-
matches = ERROR_PATTERN.match(raw)
|
25
|
-
return nil unless matches
|
26
|
-
backtrace = raw.gsub(ERROR_PATTERN, '').split("\n").map(&:strip)
|
27
|
-
Error.new(matches[PATTERN_INDICES[:method]], matches[PATTERN_INDICES[:testcase]], matches[4], backtrace)
|
28
|
-
end
|
29
|
-
|
30
|
-
class Failure
|
31
|
-
attr_reader :method, :test_case, :location, :message
|
32
|
-
def initialize(method, test_case, location, message)
|
33
|
-
@method, @test_case, @location, @message = method, test_case, location, message
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class Error
|
38
|
-
class Exception
|
39
|
-
attr_reader :message, :backtrace
|
40
|
-
def initialize(message, location)
|
41
|
-
@message, @backtrace = message, location
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
attr_reader :method, :test_case, :exception
|
46
|
-
def initialize(method, test_case, message, backtrace)
|
47
|
-
@method, @test_case, @exception = method, test_case, Exception.new(message, backtrace)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def initialize(runner, tests)
|
52
|
-
@runner, @tests = runner, tests
|
53
|
-
end
|
54
|
-
|
55
|
-
def failure_count
|
56
|
-
@runner.failures
|
57
|
-
end
|
58
|
-
|
59
|
-
def assertion_count
|
60
|
-
@tests.inject(0) { |total, test| total + test._assertions }
|
61
|
-
end
|
62
|
-
|
63
|
-
def error_count
|
64
|
-
@runner.errors
|
65
|
-
end
|
66
|
-
|
67
|
-
def passed?
|
68
|
-
@tests.all?(&:passed?)
|
69
|
-
end
|
70
|
-
|
71
|
-
def failures
|
72
|
-
@runner.report.map { |puked| MiniTestResult.parse_failure(puked) }.compact
|
73
|
-
end
|
74
|
-
|
75
|
-
def errors
|
76
|
-
@runner.report.map { |puked| MiniTestResult.parse_error(puked) }.compact
|
77
|
-
end
|
78
|
-
|
79
|
-
def failure_messages
|
80
|
-
failures.map(&:message)
|
81
|
-
end
|
82
|
-
|
83
|
-
def failure_message_lines
|
84
|
-
failure_messages.map { |message| message.split("\n") }.flatten
|
85
|
-
end
|
86
|
-
|
87
|
-
def error_messages
|
88
|
-
errors.map { |e| e.exception.message }
|
89
|
-
end
|
90
|
-
end
|
data/test/minitest_result.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
class MinitestResult
|
4
|
-
|
5
|
-
class Failure
|
6
|
-
extend Forwardable
|
7
|
-
def_delegators :@failure, :message, :backtrace
|
8
|
-
|
9
|
-
def initialize(failure)
|
10
|
-
@failure = failure
|
11
|
-
end
|
12
|
-
|
13
|
-
def location
|
14
|
-
Minitest.filter_backtrace(backtrace)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(tests)
|
19
|
-
@tests = tests
|
20
|
-
end
|
21
|
-
|
22
|
-
def failures
|
23
|
-
@tests.map(&:failures).flatten.select { |r| r.instance_of?(Minitest::Assertion) }.map { |f| Failure.new(f) }
|
24
|
-
end
|
25
|
-
|
26
|
-
def failure_count
|
27
|
-
failures.length
|
28
|
-
end
|
29
|
-
|
30
|
-
def failure_message_lines
|
31
|
-
failures.map { |f| f.message.split("\n") }.flatten
|
32
|
-
end
|
33
|
-
|
34
|
-
def errors
|
35
|
-
@tests.map(&:failures).flatten.select { |r| r.instance_of?(Minitest::UnexpectedError) }
|
36
|
-
end
|
37
|
-
|
38
|
-
def error_count
|
39
|
-
errors.length
|
40
|
-
end
|
41
|
-
|
42
|
-
def error_messages
|
43
|
-
errors.map { |e| e.message.split("\n") }.flatten
|
44
|
-
end
|
45
|
-
|
46
|
-
def assertion_count
|
47
|
-
@tests.inject(0) { |total, test| total + test.assertions }
|
48
|
-
end
|
49
|
-
end
|
data/test/simple_counter.rb
DELETED
data/test/test_helper.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
unless defined?(STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS)
|
2
|
-
STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS = Object.instance_methods + Object.private_instance_methods
|
3
|
-
end
|
4
|
-
|
5
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
6
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
|
7
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit'))
|
8
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers'))
|
9
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance'))
|
10
|
-
|
11
|
-
require 'mocha/detection/mini_test'
|
12
|
-
|
13
|
-
begin
|
14
|
-
require 'minitest'
|
15
|
-
rescue LoadError
|
16
|
-
end
|
17
|
-
begin
|
18
|
-
require 'minitest/unit'
|
19
|
-
rescue LoadError
|
20
|
-
end
|
21
|
-
|
22
|
-
module Mocha; end
|
23
|
-
|
24
|
-
if (minitest_testcase = Mocha::Detection::MiniTest.testcase) && (ENV['MOCHA_RUN_INTEGRATION_TESTS'] != 'test-unit')
|
25
|
-
begin
|
26
|
-
require 'minitest/autorun'
|
27
|
-
rescue LoadError
|
28
|
-
MiniTest::Unit.autorun
|
29
|
-
end
|
30
|
-
class Mocha::TestCase < minitest_testcase
|
31
|
-
def assert_nothing_raised(exception = StandardError)
|
32
|
-
yield
|
33
|
-
rescue exception => e
|
34
|
-
flunk "Unexpected exception raised: #{e}"
|
35
|
-
end
|
36
|
-
|
37
|
-
alias_method :assert_not_nil, :refute_nil
|
38
|
-
alias_method :assert_raise, :assert_raises
|
39
|
-
alias_method :assert_not_same, :refute_same
|
40
|
-
alias_method :assert_no_match, :refute_match
|
41
|
-
end
|
42
|
-
else
|
43
|
-
require 'test/unit'
|
44
|
-
class Mocha::TestCase < Test::Unit::TestCase
|
45
|
-
def test_dummy
|
46
|
-
# Some versions (?) of Test::Unit try to run this base class as a test case
|
47
|
-
# and it fails because it has no test methods, so I'm adding a dummy test.
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/test/test_runner.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'assertions'
|
2
|
-
|
3
|
-
require 'mocha/detection/mini_test'
|
4
|
-
|
5
|
-
module TestRunner
|
6
|
-
def run_as_test(&block)
|
7
|
-
run_as_tests(:test_me => block)
|
8
|
-
end
|
9
|
-
|
10
|
-
def run_as_tests(methods = {})
|
11
|
-
base_class = Mocha::TestCase
|
12
|
-
test_class = Class.new(base_class) do
|
13
|
-
include Assertions
|
14
|
-
|
15
|
-
methods.each do |(method_name, proc)|
|
16
|
-
define_method(method_name, proc)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
tests = methods.keys.select { |m| m.to_s[/^test/] }.map { |m| test_class.new(m) }
|
21
|
-
|
22
|
-
if Mocha::Detection::MiniTest.testcase && (ENV['MOCHA_RUN_INTEGRATION_TESTS'] != 'test-unit')
|
23
|
-
minitest_version = Gem::Version.new(Mocha::Detection::MiniTest.version)
|
24
|
-
if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version)
|
25
|
-
require File.expand_path('../minitest_result', __FILE__)
|
26
|
-
tests.each do |test|
|
27
|
-
test.run
|
28
|
-
end
|
29
|
-
Minitest::Runnable.runnables.delete(test_class)
|
30
|
-
test_result = MinitestResult.new(tests)
|
31
|
-
elsif Gem::Requirement.new('> 0.0.0', '< 5.0.0').satisfied_by?(minitest_version)
|
32
|
-
require File.expand_path('../mini_test_result', __FILE__)
|
33
|
-
runner = MiniTest::Unit.new
|
34
|
-
tests.each do |test|
|
35
|
-
test.run(runner)
|
36
|
-
end
|
37
|
-
test_result = MiniTestResult.new(runner, tests)
|
38
|
-
end
|
39
|
-
else
|
40
|
-
require File.expand_path('../test_unit_result', __FILE__)
|
41
|
-
test_result = TestUnitResult.build_test_result
|
42
|
-
tests.each do |test|
|
43
|
-
test.run(test_result) {}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
test_result
|
48
|
-
end
|
49
|
-
|
50
|
-
def assert_passed(test_result)
|
51
|
-
flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0
|
52
|
-
flunk "Test failed unexpectedly with message: #{test_result.errors.map(&:exception)}" if test_result.error_count > 0
|
53
|
-
end
|
54
|
-
|
55
|
-
def assert_failed(test_result)
|
56
|
-
flunk "Test passed unexpectedly" unless test_result.failure_count + test_result.error_count > 0
|
57
|
-
end
|
58
|
-
end
|
data/test/test_unit_result.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'test/unit/testresult'
|
2
|
-
|
3
|
-
class TestUnitResult
|
4
|
-
def self.build_test_result
|
5
|
-
test_result = Test::Unit::TestResult.new
|
6
|
-
class << test_result
|
7
|
-
attr_reader :failures, :errors
|
8
|
-
def failure_messages
|
9
|
-
failures.map { |failure| failure.message }
|
10
|
-
end
|
11
|
-
def failure_message_lines
|
12
|
-
failure_messages.map { |message| message.split("\n") }.flatten
|
13
|
-
end
|
14
|
-
def error_messages
|
15
|
-
errors.map { |error| error.message }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
test_result
|
19
|
-
end
|
20
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'method_definer'
|
3
|
-
require 'mocha/mock'
|
4
|
-
require 'mocha/any_instance_method'
|
5
|
-
|
6
|
-
class AnyInstanceMethodTest < Mocha::TestCase
|
7
|
-
|
8
|
-
include Mocha
|
9
|
-
|
10
|
-
unless RUBY_V2_PLUS
|
11
|
-
def test_should_hide_original_method
|
12
|
-
klass = Class.new { def method_x; end }
|
13
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
14
|
-
|
15
|
-
method.hide_original_method
|
16
|
-
|
17
|
-
assert_equal false, klass.method_defined?(:method_x)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_not_raise_error_hiding_method_that_isnt_defined
|
22
|
-
klass = Class.new
|
23
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
24
|
-
|
25
|
-
assert_nothing_raised { method.hide_original_method }
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_should_define_a_new_method
|
29
|
-
klass = Class.new { def method_x; end }
|
30
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
31
|
-
mocha = build_mock
|
32
|
-
mocha.expects(:method_x).with(:param1, :param2).returns(:result)
|
33
|
-
any_instance = Object.new
|
34
|
-
any_instance.define_instance_method(:mocha) { mocha }
|
35
|
-
klass.define_instance_method(:any_instance) { any_instance }
|
36
|
-
|
37
|
-
method.hide_original_method
|
38
|
-
method.define_new_method
|
39
|
-
|
40
|
-
instance = klass.new
|
41
|
-
result = instance.method_x(:param1, :param2)
|
42
|
-
|
43
|
-
assert_equal :result, result
|
44
|
-
assert mocha.__verified__?
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_should_restore_original_method
|
48
|
-
klass = Class.new { def method_x; :original_result; end }
|
49
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
50
|
-
|
51
|
-
method.hide_original_method
|
52
|
-
method.define_new_method
|
53
|
-
method.remove_new_method
|
54
|
-
method.restore_original_method
|
55
|
-
|
56
|
-
instance = klass.new
|
57
|
-
assert instance.respond_to?(:method_x)
|
58
|
-
assert_equal :original_result, instance.method_x
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_should_not_restore_original_method_if_none_was_defined_in_first_place
|
62
|
-
klass = Class.new { def method_x; :new_result; end }
|
63
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
64
|
-
|
65
|
-
method.restore_original_method
|
66
|
-
|
67
|
-
instance = klass.new
|
68
|
-
assert_equal :new_result, instance.method_x
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_should_call_remove_new_method
|
72
|
-
klass = Class.new { def method_x; end }
|
73
|
-
any_instance = build_mock
|
74
|
-
any_instance_mocha = build_mock
|
75
|
-
any_instance.stubs(:mocha).returns(any_instance_mocha)
|
76
|
-
klass.define_instance_method(:any_instance) { any_instance }
|
77
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
78
|
-
method.replace_instance_method(:restore_original_method) { }
|
79
|
-
method.define_instance_accessor(:remove_called)
|
80
|
-
method.replace_instance_method(:remove_new_method) { self.remove_called = true }
|
81
|
-
|
82
|
-
method.unstub
|
83
|
-
|
84
|
-
assert method.remove_called
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_should_call_restore_original_method
|
88
|
-
klass = Class.new { def method_x; end }
|
89
|
-
any_instance = build_mock
|
90
|
-
any_instance_mocha = build_mock
|
91
|
-
any_instance.stubs(:mocha).returns(any_instance_mocha)
|
92
|
-
klass.define_instance_method(:any_instance) { any_instance }
|
93
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
94
|
-
method.replace_instance_method(:remove_new_method) { }
|
95
|
-
method.define_instance_accessor(:restore_called)
|
96
|
-
method.replace_instance_method(:restore_original_method) { self.restore_called = true }
|
97
|
-
|
98
|
-
method.unstub
|
99
|
-
|
100
|
-
assert method.restore_called
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_should_call_mock_unstub
|
104
|
-
klass = Class.new { def method_x; end }
|
105
|
-
|
106
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
107
|
-
|
108
|
-
method.replace_instance_method(:remove_new_method) { }
|
109
|
-
method.replace_instance_method(:restore_original_method) { }
|
110
|
-
mocha = Class.new { class << self; attr_accessor :unstub_method; end; def self.unstub(method); self.unstub_method = method; end; }
|
111
|
-
mocha.define_instance_method(:any_expectations?) { true }
|
112
|
-
method.replace_instance_method(:mock) { mocha }
|
113
|
-
|
114
|
-
method.unstub
|
115
|
-
|
116
|
-
assert_equal mocha.unstub_method, :method_x
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_should_return_any_instance_mocha_for_stubbee
|
120
|
-
mocha = Object.new
|
121
|
-
any_instance = Object.new
|
122
|
-
any_instance.define_instance_method(:mocha) { mocha }
|
123
|
-
stubbee = Class.new
|
124
|
-
stubbee.define_instance_method(:any_instance) { any_instance }
|
125
|
-
method = AnyInstanceMethod.new(stubbee, :method_name)
|
126
|
-
assert_equal stubbee.any_instance.mocha, method.mock
|
127
|
-
end
|
128
|
-
|
129
|
-
private
|
130
|
-
|
131
|
-
def build_mock
|
132
|
-
Mock.new(nil)
|
133
|
-
end
|
134
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/inspect'
|
3
|
-
|
4
|
-
class ArrayInspectTest < Mocha::TestCase
|
5
|
-
|
6
|
-
def test_should_use_inspect
|
7
|
-
array = [1, 2]
|
8
|
-
assert_equal array.inspect, array.mocha_inspect
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_should_use_mocha_inspect_on_each_item
|
12
|
-
array = [1, 2, "chris"]
|
13
|
-
assert_equal "[1, 2, 'chris']", array.mocha_inspect
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|