mocha 1.6.0 → 1.7.0
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/.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
@@ -3,7 +3,6 @@ require 'mocha/setup'
|
|
3
3
|
require 'mocha/not_initialized_error'
|
4
4
|
|
5
5
|
class PreventUseOfMochaOutsideTestTest < Mocha::TestCase
|
6
|
-
|
7
6
|
include AcceptanceTest
|
8
7
|
|
9
8
|
def setup
|
@@ -75,5 +74,4 @@ class PreventUseOfMochaOutsideTestTest < Mocha::TestCase
|
|
75
74
|
klass = Class.new
|
76
75
|
assert_raises(Mocha::NotInitializedError) { klass.any_instance.unstub(:expected_method) }
|
77
76
|
end
|
78
|
-
|
79
77
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class RaiseExceptionTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -17,9 +16,9 @@ class RaiseExceptionTest < Mocha::TestCase
|
|
17
16
|
exception_class = Class.new(StandardError)
|
18
17
|
test_result = run_as_test do
|
19
18
|
foo = stub('foo')
|
20
|
-
foo.stubs(:bar).raises(exception_class,
|
19
|
+
foo.stubs(:bar).raises(exception_class, 'my-message')
|
21
20
|
exception = assert_raises(exception_class) { foo.bar }
|
22
|
-
assert_equal
|
21
|
+
assert_equal 'my-message', exception.message
|
23
22
|
end
|
24
23
|
assert_passed(test_result)
|
25
24
|
end
|
@@ -35,5 +34,4 @@ class RaiseExceptionTest < Mocha::TestCase
|
|
35
34
|
end
|
36
35
|
assert_passed(test_result)
|
37
36
|
end
|
38
|
-
|
39
37
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class ReturnValueTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -48,5 +47,4 @@ class ReturnValueTest < Mocha::TestCase
|
|
48
47
|
end
|
49
48
|
assert_passed(test_result)
|
50
49
|
end
|
51
|
-
|
52
50
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class SequenceTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -73,8 +72,8 @@ class SequenceTest < Mocha::TestCase
|
|
73
72
|
|
74
73
|
def test_should_constrain_invocations_to_occur_in_expected_order_even_if_expected_on_partial_mocks
|
75
74
|
test_result = run_as_test do
|
76
|
-
partial_mock_one =
|
77
|
-
partial_mock_two =
|
75
|
+
partial_mock_one = '1'
|
76
|
+
partial_mock_two = '2'
|
78
77
|
sequence = sequence('one')
|
79
78
|
|
80
79
|
partial_mock_one.expects(:first).in_sequence(sequence)
|
@@ -88,8 +87,8 @@ class SequenceTest < Mocha::TestCase
|
|
88
87
|
|
89
88
|
def test_should_allow_invocations_in_sequence_even_if_expected_on_partial_mocks
|
90
89
|
test_result = run_as_test do
|
91
|
-
partial_mock_one =
|
92
|
-
partial_mock_two =
|
90
|
+
partial_mock_one = '1'
|
91
|
+
partial_mock_two = '2'
|
93
92
|
sequence = sequence('one')
|
94
93
|
|
95
94
|
partial_mock_one.expects(:first).in_sequence(sequence)
|
@@ -148,7 +147,7 @@ class SequenceTest < Mocha::TestCase
|
|
148
147
|
mock.first
|
149
148
|
end
|
150
149
|
assert_failed(test_result)
|
151
|
-
assert_match Regexp.new(%
|
150
|
+
assert_match Regexp.new(%(in sequence "one")), test_result.failures.first.message
|
152
151
|
end
|
153
152
|
|
154
153
|
def test_should_allow_expectations_to_be_in_more_than_one_sequence
|
@@ -166,8 +165,8 @@ class SequenceTest < Mocha::TestCase
|
|
166
165
|
mock.second
|
167
166
|
end
|
168
167
|
assert_failed(test_result)
|
169
|
-
assert_match Regexp.new(%
|
170
|
-
assert_match Regexp.new(%
|
168
|
+
assert_match Regexp.new(%(in sequence "one")), test_result.failures.first.message
|
169
|
+
assert_match Regexp.new(%(in sequence "two")), test_result.failures.first.message
|
171
170
|
end
|
172
171
|
|
173
172
|
def test_should_have_shortcut_for_expectations_to_be_in_more_than_one_sequence
|
@@ -185,8 +184,7 @@ class SequenceTest < Mocha::TestCase
|
|
185
184
|
mock.second
|
186
185
|
end
|
187
186
|
assert_failed(test_result)
|
188
|
-
assert_match Regexp.new(%
|
189
|
-
assert_match Regexp.new(%
|
187
|
+
assert_match Regexp.new(%(in sequence "one")), test_result.failures.first.message
|
188
|
+
assert_match Regexp.new(%(in sequence "two")), test_result.failures.first.message
|
190
189
|
end
|
191
|
-
|
192
190
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StatesTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -58,13 +57,16 @@ class StatesTest < Mocha::TestCase
|
|
58
57
|
mock = mock()
|
59
58
|
readiness = states('readiness')
|
60
59
|
|
61
|
-
mock.expects(:first).raises
|
60
|
+
mock.expects(:first).raises.then(readiness.is('ready'))
|
62
61
|
mock.expects(:second).when(readiness.is('ready'))
|
63
62
|
|
64
|
-
|
63
|
+
begin
|
64
|
+
mock.first
|
65
|
+
rescue StandardError
|
66
|
+
nil
|
67
|
+
end
|
65
68
|
mock.second
|
66
69
|
end
|
67
70
|
assert_passed(test_result)
|
68
71
|
end
|
69
|
-
|
70
72
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubAnyInstanceMethodDefinedOnSuperclassTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -37,12 +36,14 @@ class StubAnyInstanceMethodDefinedOnSuperclassTest < Mocha::TestCase
|
|
37
36
|
def self.inspect
|
38
37
|
'superklass'
|
39
38
|
end
|
39
|
+
|
40
40
|
def my_instance_method; end
|
41
41
|
end
|
42
42
|
klass = Class.new(superklass) do
|
43
43
|
def self.inspect
|
44
44
|
'klass'
|
45
45
|
end
|
46
|
+
|
46
47
|
def my_instance_method; end
|
47
48
|
end
|
48
49
|
test_result = run_as_tests(
|
@@ -56,9 +57,9 @@ class StubAnyInstanceMethodDefinedOnSuperclassTest < Mocha::TestCase
|
|
56
57
|
)
|
57
58
|
assert_failed(test_result)
|
58
59
|
assert_equal [
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
'not all expectations were satisfied',
|
61
|
+
'unsatisfied expectations:',
|
62
|
+
'- expected exactly once, not yet invoked: #<AnyInstance:superklass>.my_instance_method(any_parameters)'
|
62
63
|
], test_result.failure_message_lines
|
63
64
|
end
|
64
65
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubAnyInstanceMethodTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -40,7 +39,7 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
40
39
|
run_as_test do
|
41
40
|
klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
|
42
41
|
end
|
43
|
-
assert
|
42
|
+
assert(instance.public_methods(false).any? { |m| m.to_s == 'my_instance_method' })
|
44
43
|
assert_equal :original_return_value, instance.my_instance_method
|
45
44
|
end
|
46
45
|
|
@@ -51,6 +50,7 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
51
50
|
end
|
52
51
|
protected :my_instance_method
|
53
52
|
def self.protected(*args); end
|
53
|
+
|
54
54
|
def my_unprotected_instance_method
|
55
55
|
my_instance_method
|
56
56
|
end
|
@@ -59,7 +59,7 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
59
59
|
run_as_test do
|
60
60
|
klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
|
61
61
|
end
|
62
|
-
assert
|
62
|
+
assert(instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' })
|
63
63
|
assert_equal :original_return_value, instance.my_unprotected_instance_method
|
64
64
|
end
|
65
65
|
|
@@ -70,6 +70,7 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
70
70
|
end
|
71
71
|
protected :my_instance_method
|
72
72
|
def self.protected(*args); end
|
73
|
+
|
73
74
|
def my_unprotected_instance_method
|
74
75
|
my_instance_method
|
75
76
|
end
|
@@ -94,7 +95,7 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
94
95
|
run_as_test do
|
95
96
|
klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
|
96
97
|
end
|
97
|
-
assert
|
98
|
+
assert(instance.private_methods(false).any? { |m| m.to_s == 'my_instance_method' })
|
98
99
|
assert_equal :original_return_value, instance.send(:my_instance_method)
|
99
100
|
end
|
100
101
|
|
@@ -142,8 +143,8 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
142
143
|
assert_equal :new_return_value, instance.my_superclass_method
|
143
144
|
end
|
144
145
|
assert_passed(test_result)
|
145
|
-
assert
|
146
|
-
assert
|
146
|
+
assert(instance.public_methods(true).any? { |m| m.to_s == 'my_superclass_method' })
|
147
|
+
assert(klass.public_methods(false).none? { |m| m.to_s == 'my_superclass_method' })
|
147
148
|
assert_equal :original_return_value, instance.my_superclass_method
|
148
149
|
end
|
149
150
|
|
@@ -162,8 +163,8 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
162
163
|
assert_equal :new_return_value, instance.send(:my_superclass_method)
|
163
164
|
end
|
164
165
|
assert_passed(test_result)
|
165
|
-
assert
|
166
|
-
assert
|
166
|
+
assert(instance.protected_methods(true).any? { |m| m.to_s == 'my_superclass_method' })
|
167
|
+
assert(klass.protected_methods(false).none? { |m| m.to_s == 'my_superclass_method' })
|
167
168
|
assert_equal :original_return_value, instance.send(:my_superclass_method)
|
168
169
|
end
|
169
170
|
|
@@ -182,15 +183,16 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
182
183
|
assert_equal :new_return_value, instance.send(:my_superclass_method)
|
183
184
|
end
|
184
185
|
assert_passed(test_result)
|
185
|
-
assert
|
186
|
-
assert
|
186
|
+
assert(instance.private_methods(true).any? { |m| m.to_s == 'my_superclass_method' })
|
187
|
+
assert(klass.private_methods(false).none? { |m| m.to_s == 'my_superclass_method' })
|
187
188
|
assert_equal :original_return_value, instance.send(:my_superclass_method)
|
188
189
|
end
|
189
190
|
|
191
|
+
# rubocop:disable Lint/DuplicateMethods
|
190
192
|
def test_should_be_able_to_stub_method_if_ruby18_public_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
191
193
|
ruby18_klass = Class.new do
|
192
194
|
class << self
|
193
|
-
def public_instance_methods(
|
195
|
+
def public_instance_methods(_include_superclass = true)
|
194
196
|
['my_instance_method']
|
195
197
|
end
|
196
198
|
end
|
@@ -205,7 +207,7 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
205
207
|
def test_should_be_able_to_stub_method_if_ruby19_public_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
206
208
|
ruby19_klass = Class.new do
|
207
209
|
class << self
|
208
|
-
def public_instance_methods(
|
210
|
+
def public_instance_methods(_include_superclass = true)
|
209
211
|
[:my_instance_method]
|
210
212
|
end
|
211
213
|
end
|
@@ -220,7 +222,7 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
220
222
|
def test_should_be_able_to_stub_method_if_ruby18_protected_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
221
223
|
ruby18_klass = Class.new do
|
222
224
|
class << self
|
223
|
-
def protected_instance_methods(
|
225
|
+
def protected_instance_methods(_include_superclass = true)
|
224
226
|
['my_instance_method']
|
225
227
|
end
|
226
228
|
end
|
@@ -235,7 +237,7 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
235
237
|
def test_should_be_able_to_stub_method_if_ruby19_protected_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
236
238
|
ruby19_klass = Class.new do
|
237
239
|
class << self
|
238
|
-
def protected_instance_methods(
|
240
|
+
def protected_instance_methods(_include_superclass = true)
|
239
241
|
[:my_instance_method]
|
240
242
|
end
|
241
243
|
end
|
@@ -250,7 +252,7 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
250
252
|
def test_should_be_able_to_stub_method_if_ruby18_private_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
251
253
|
ruby18_klass = Class.new do
|
252
254
|
class << self
|
253
|
-
def private_instance_methods(
|
255
|
+
def private_instance_methods(_include_superclass = true)
|
254
256
|
['my_instance_method']
|
255
257
|
end
|
256
258
|
end
|
@@ -265,7 +267,7 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
265
267
|
def test_should_be_able_to_stub_method_if_ruby19_private_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
266
268
|
ruby19_klass = Class.new do
|
267
269
|
class << self
|
268
|
-
def private_instance_methods(
|
270
|
+
def private_instance_methods(_include_superclass = true)
|
269
271
|
[:my_instance_method]
|
270
272
|
end
|
271
273
|
end
|
@@ -276,5 +278,5 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
|
|
276
278
|
end
|
277
279
|
assert_passed(test_result)
|
278
280
|
end
|
279
|
-
|
281
|
+
# rubocop:enable Lint/DuplicateMethods
|
280
282
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -13,10 +12,11 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
|
|
13
12
|
teardown_acceptance_test
|
14
13
|
end
|
15
14
|
|
15
|
+
# rubocop:disable Lint/DuplicateMethods
|
16
16
|
def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
17
17
|
ruby18_klass = Class.new do
|
18
18
|
class << self
|
19
|
-
def public_methods(
|
19
|
+
def public_methods(_include_superclass = true)
|
20
20
|
['my_class_method']
|
21
21
|
end
|
22
22
|
end
|
@@ -31,7 +31,7 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
|
|
31
31
|
def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
32
32
|
ruby19_klass = Class.new do
|
33
33
|
class << self
|
34
|
-
def public_methods(
|
34
|
+
def public_methods(_include_superclass = true)
|
35
35
|
[:my_class_method]
|
36
36
|
end
|
37
37
|
end
|
@@ -46,7 +46,7 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
|
|
46
46
|
def test_should_be_able_to_stub_method_if_ruby18_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
47
47
|
ruby18_klass = Class.new do
|
48
48
|
class << self
|
49
|
-
def protected_methods(
|
49
|
+
def protected_methods(_include_superclass = true)
|
50
50
|
['my_class_method']
|
51
51
|
end
|
52
52
|
end
|
@@ -61,7 +61,7 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
|
|
61
61
|
def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
62
62
|
ruby19_klass = Class.new do
|
63
63
|
class << self
|
64
|
-
def protected_methods(
|
64
|
+
def protected_methods(_include_superclass = true)
|
65
65
|
[:my_class_method]
|
66
66
|
end
|
67
67
|
end
|
@@ -76,7 +76,7 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
|
|
76
76
|
def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
77
77
|
ruby18_klass = Class.new do
|
78
78
|
class << self
|
79
|
-
def private_methods(
|
79
|
+
def private_methods(_include_superclass = true)
|
80
80
|
['my_class_method']
|
81
81
|
end
|
82
82
|
end
|
@@ -91,7 +91,7 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
|
|
91
91
|
def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
92
92
|
ruby19_klass = Class.new do
|
93
93
|
class << self
|
94
|
-
def private_methods(
|
94
|
+
def private_methods(_include_superclass = true)
|
95
95
|
[:my_class_method]
|
96
96
|
end
|
97
97
|
end
|
@@ -102,5 +102,5 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
|
|
102
102
|
end
|
103
103
|
assert_passed(test_result)
|
104
104
|
end
|
105
|
-
|
105
|
+
# rubocop:enable Lint/DuplicateMethods
|
106
106
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubClassMethodDefinedOnClassTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -13,6 +12,7 @@ class StubClassMethodDefinedOnClassTest < Mocha::TestCase
|
|
13
12
|
teardown_acceptance_test
|
14
13
|
end
|
15
14
|
|
15
|
+
# rubocop:disable Lint/DuplicateMethods
|
16
16
|
def test_should_stub_public_method_and_leave_it_unchanged_after_test
|
17
17
|
klass = Class.new do
|
18
18
|
class << self
|
@@ -75,4 +75,5 @@ class StubClassMethodDefinedOnClassTest < Mocha::TestCase
|
|
75
75
|
end
|
76
76
|
assert_equal :original_return_value, klass.send(:my_class_method)
|
77
77
|
end
|
78
|
+
# rubocop:enable Lint/DuplicateMethods
|
78
79
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -13,6 +12,7 @@ class StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
|
|
13
12
|
teardown_acceptance_test
|
14
13
|
end
|
15
14
|
|
15
|
+
# rubocop:disable Lint/DuplicateMethods
|
16
16
|
def test_should_stub_public_method_on_child_class_and_leave_it_unchanged_after_test
|
17
17
|
superklass = Class.new do
|
18
18
|
class << self
|
@@ -115,12 +115,14 @@ class StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
|
|
115
115
|
def self.inspect
|
116
116
|
'superklass'
|
117
117
|
end
|
118
|
+
|
118
119
|
def self.my_class_method; end
|
119
120
|
end
|
120
121
|
klass = Class.new(superklass) do
|
121
122
|
def self.inspect
|
122
123
|
'klass'
|
123
124
|
end
|
125
|
+
|
124
126
|
def self.my_class_method; end
|
125
127
|
end
|
126
128
|
test_result = run_as_tests(
|
@@ -134,9 +136,10 @@ class StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
|
|
134
136
|
)
|
135
137
|
assert_failed(test_result)
|
136
138
|
assert_equal [
|
137
|
-
|
138
|
-
|
139
|
-
|
139
|
+
'not all expectations were satisfied',
|
140
|
+
'unsatisfied expectations:',
|
141
|
+
'- expected exactly once, not yet invoked: superklass.my_class_method(any_parameters)'
|
140
142
|
], test_result.failure_message_lines
|
141
143
|
end
|
144
|
+
# rubocop:enable Lint/DuplicateMethods
|
142
145
|
end
|