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
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubEverythingTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -15,7 +14,7 @@ class StubEverythingTest < Mocha::TestCase
|
|
15
14
|
|
16
15
|
def test_should_build_stub_and_explicitly_add_an_expectation
|
17
16
|
test_result = run_as_test do
|
18
|
-
foo = stub_everything
|
17
|
+
foo = stub_everything
|
19
18
|
foo.stubs(:bar)
|
20
19
|
foo.bar
|
21
20
|
foo.unexpected_invocation
|
@@ -52,5 +51,4 @@ class StubEverythingTest < Mocha::TestCase
|
|
52
51
|
end
|
53
52
|
assert_passed(test_result)
|
54
53
|
end
|
55
|
-
|
56
54
|
end
|
data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb
CHANGED
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -15,7 +14,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
|
|
15
14
|
|
16
15
|
def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_exist
|
17
16
|
ruby18_instance = Class.new do
|
18
|
-
def public_methods(
|
17
|
+
def public_methods(_include_superclass = true)
|
19
18
|
['my_instance_method']
|
20
19
|
end
|
21
20
|
end.new
|
@@ -28,7 +27,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
|
|
28
27
|
|
29
28
|
def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_exist
|
30
29
|
ruby19_instance = Class.new do
|
31
|
-
def public_methods(
|
30
|
+
def public_methods(_include_superclass = true)
|
32
31
|
[:my_instance_method]
|
33
32
|
end
|
34
33
|
end.new
|
@@ -41,7 +40,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
|
|
41
40
|
|
42
41
|
def test_should_be_able_to_stub_method_if_ruby18_protected_methods_include_method_but_method_does_not_exist
|
43
42
|
ruby18_instance = Class.new do
|
44
|
-
def protected_methods(
|
43
|
+
def protected_methods(_include_superclass = true)
|
45
44
|
['my_instance_method']
|
46
45
|
end
|
47
46
|
end.new
|
@@ -54,7 +53,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
|
|
54
53
|
|
55
54
|
def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_exist
|
56
55
|
ruby19_instance = Class.new do
|
57
|
-
def protected_methods(
|
56
|
+
def protected_methods(_include_superclass = true)
|
58
57
|
[:my_instance_method]
|
59
58
|
end
|
60
59
|
end.new
|
@@ -67,7 +66,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
|
|
67
66
|
|
68
67
|
def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_exist
|
69
68
|
ruby18_instance = Class.new do
|
70
|
-
def private_methods(
|
69
|
+
def private_methods(_include_superclass = true)
|
71
70
|
['my_instance_method']
|
72
71
|
end
|
73
72
|
end.new
|
@@ -80,7 +79,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
|
|
80
79
|
|
81
80
|
def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_exist
|
82
81
|
ruby19_instance = Class.new do
|
83
|
-
def private_methods(
|
82
|
+
def private_methods(_include_superclass = true)
|
84
83
|
[:my_instance_method]
|
85
84
|
end
|
86
85
|
end.new
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubInstanceMethodDefinedOnObjectClassTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -13,6 +12,7 @@ class StubInstanceMethodDefinedOnObjectClassTest < 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
|
Object.class_eval do
|
18
18
|
def my_instance_method
|
@@ -72,4 +72,5 @@ class StubInstanceMethodDefinedOnObjectClassTest < Mocha::TestCase
|
|
72
72
|
ensure
|
73
73
|
Object.class_eval { remove_method :my_instance_method }
|
74
74
|
end
|
75
|
+
# rubocop:enable Lint/DuplicateMethods
|
75
76
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubInstanceMethodDefinedOnSingletonClassTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -66,5 +65,4 @@ class StubInstanceMethodDefinedOnSingletonClassTest < Mocha::TestCase
|
|
66
65
|
end
|
67
66
|
assert_equal :original_return_value, instance.send(:my_singleton_method)
|
68
67
|
end
|
69
|
-
|
70
68
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubModuleMethodTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -13,6 +12,7 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
13
12
|
teardown_acceptance_test
|
14
13
|
end
|
15
14
|
|
15
|
+
# rubocop:disable Lint/DuplicateMethods
|
16
16
|
def test_should_stub_method_within_test
|
17
17
|
mod = Module.new do
|
18
18
|
def self.my_module_method
|
@@ -38,7 +38,7 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
38
38
|
run_as_test do
|
39
39
|
mod.stubs(:my_module_method).returns(:new_return_value)
|
40
40
|
end
|
41
|
-
assert
|
41
|
+
assert(mod.public_methods(false).any? { |m| m.to_s == 'my_module_method' })
|
42
42
|
assert_equal :original_return_value, mod.my_module_method
|
43
43
|
end
|
44
44
|
|
@@ -57,7 +57,7 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
57
57
|
run_as_test do
|
58
58
|
mod.stubs(:my_module_method).returns(:new_return_value)
|
59
59
|
end
|
60
|
-
assert
|
60
|
+
assert(mod.protected_methods(false).any? { |m| m.to_s == 'my_module_method' })
|
61
61
|
assert_equal :original_return_value, mod.my_unprotected_module_method
|
62
62
|
end
|
63
63
|
|
@@ -73,7 +73,7 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
73
73
|
run_as_test do
|
74
74
|
mod.stubs(:my_module_method).returns(:new_return_value)
|
75
75
|
end
|
76
|
-
assert
|
76
|
+
assert(mod.private_methods(false).any? { |m| m.to_s == 'my_module_method' })
|
77
77
|
assert_equal :original_return_value, mod.send(:my_module_method)
|
78
78
|
end
|
79
79
|
|
@@ -103,15 +103,15 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
103
103
|
assert_equal :new_return_value, mod.my_superclass_method
|
104
104
|
end
|
105
105
|
assert_passed(test_result)
|
106
|
-
assert
|
107
|
-
assert
|
106
|
+
assert(supermod.public_methods.any? { |m| m.to_s == 'my_superclass_method' })
|
107
|
+
assert(mod.public_methods(false).none? { |m| m.to_s == 'my_superclass_method' })
|
108
108
|
assert_equal :original_return_value, supermod.my_superclass_method
|
109
109
|
end
|
110
110
|
|
111
111
|
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
|
112
112
|
ruby18_mod = Module.new do
|
113
113
|
class << self
|
114
|
-
def public_methods(
|
114
|
+
def public_methods(_include_superclass = true)
|
115
115
|
['my_module_method']
|
116
116
|
end
|
117
117
|
end
|
@@ -126,7 +126,7 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
126
126
|
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
|
127
127
|
ruby19_mod = Module.new do
|
128
128
|
class << self
|
129
|
-
def public_methods(
|
129
|
+
def public_methods(_include_superclass = true)
|
130
130
|
[:my_module_method]
|
131
131
|
end
|
132
132
|
end
|
@@ -141,7 +141,7 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
141
141
|
def test_should_be_able_to_stub_method_if_ruby_18_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
142
142
|
ruby18_mod = Module.new do
|
143
143
|
class << self
|
144
|
-
def protected_methods(
|
144
|
+
def protected_methods(_include_superclass = true)
|
145
145
|
['my_module_method']
|
146
146
|
end
|
147
147
|
end
|
@@ -156,7 +156,7 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
156
156
|
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
|
157
157
|
ruby19_mod = Module.new do
|
158
158
|
class << self
|
159
|
-
def protected_methods(
|
159
|
+
def protected_methods(_include_superclass = true)
|
160
160
|
[:my_module_method]
|
161
161
|
end
|
162
162
|
end
|
@@ -171,7 +171,7 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
171
171
|
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
|
172
172
|
ruby18_mod = Module.new do
|
173
173
|
class << self
|
174
|
-
def private_methods(
|
174
|
+
def private_methods(_include_superclass = true)
|
175
175
|
['my_module_method']
|
176
176
|
end
|
177
177
|
end
|
@@ -186,7 +186,7 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
186
186
|
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
|
187
187
|
ruby19_mod = Module.new do
|
188
188
|
class << self
|
189
|
-
def private_methods(
|
189
|
+
def private_methods(_include_superclass = true)
|
190
190
|
[:my_module_method]
|
191
191
|
end
|
192
192
|
end
|
@@ -197,5 +197,5 @@ class StubModuleMethodTest < Mocha::TestCase
|
|
197
197
|
end
|
198
198
|
assert_passed(test_result)
|
199
199
|
end
|
200
|
-
|
200
|
+
# rubocop:enable Lint/DuplicateMethods
|
201
201
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -15,7 +14,7 @@ class StubTest < Mocha::TestCase
|
|
15
14
|
|
16
15
|
def test_should_build_stub_and_explicitly_add_an_expectation
|
17
16
|
test_result = run_as_test do
|
18
|
-
foo = stub
|
17
|
+
foo = stub
|
19
18
|
foo.stubs(:bar)
|
20
19
|
foo.bar
|
21
20
|
end
|
@@ -48,5 +47,4 @@ class StubTest < Mocha::TestCase
|
|
48
47
|
end
|
49
48
|
assert_passed(test_result)
|
50
49
|
end
|
51
|
-
|
52
50
|
end
|
@@ -2,35 +2,28 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class Widget
|
5
|
-
|
6
5
|
def model
|
7
6
|
'original_model'
|
8
7
|
end
|
9
8
|
|
10
9
|
class << self
|
11
|
-
|
12
|
-
def find(options)
|
10
|
+
def find(_options)
|
13
11
|
[]
|
14
12
|
end
|
15
13
|
|
16
|
-
def create(
|
14
|
+
def create(_attributes)
|
17
15
|
Widget.new
|
18
16
|
end
|
19
|
-
|
20
17
|
end
|
21
|
-
|
22
18
|
end
|
23
19
|
|
24
20
|
module Thingy
|
25
|
-
|
26
21
|
def self.wotsit
|
27
22
|
:hoojamaflip
|
28
23
|
end
|
29
|
-
|
30
24
|
end
|
31
25
|
|
32
26
|
class StubbaExampleTest < Mocha::TestCase
|
33
|
-
|
34
27
|
def test_should_stub_instance_method
|
35
28
|
widget = Widget.new
|
36
29
|
widget.expects(:model).returns('different_model')
|
@@ -93,10 +86,9 @@ class StubbaExampleTest < Mocha::TestCase
|
|
93
86
|
|
94
87
|
def should_stub_instance_method_on_any_instance_of_a_class
|
95
88
|
Widget.any_instance.expects(:model).at_least_once.returns('another_model')
|
96
|
-
|
97
|
-
|
98
|
-
assert_equal 'another_model',
|
99
|
-
assert_equal 'another_model',
|
89
|
+
widget1 = Widget.new
|
90
|
+
widget2 = Widget.new
|
91
|
+
assert_equal 'another_model', widget1.model
|
92
|
+
assert_equal 'another_model', widget2.model
|
100
93
|
end
|
101
|
-
|
102
94
|
end
|
@@ -3,7 +3,6 @@ require 'mocha/setup'
|
|
3
3
|
require 'execution_point'
|
4
4
|
|
5
5
|
class StubbaTestResultTest < Mocha::TestCase
|
6
|
-
|
7
6
|
include AcceptanceTest
|
8
7
|
|
9
8
|
def setup
|
@@ -17,8 +16,7 @@ class StubbaTestResultTest < Mocha::TestCase
|
|
17
16
|
def test_should_include_expectation_verification_in_assertion_count
|
18
17
|
test_result = run_as_test do
|
19
18
|
object = Class.new do
|
20
|
-
def message
|
21
|
-
end
|
19
|
+
def message; end
|
22
20
|
end.new
|
23
21
|
object.expects(:message)
|
24
22
|
object.message
|
@@ -36,8 +34,7 @@ class StubbaTestResultTest < Mocha::TestCase
|
|
36
34
|
def test_should_not_include_stubbing_expectation_verification_in_assertion_count
|
37
35
|
test_result = run_as_test do
|
38
36
|
object = Class.new do
|
39
|
-
def message
|
40
|
-
end
|
37
|
+
def message; end
|
41
38
|
end.new
|
42
39
|
object.stubs(:message)
|
43
40
|
object.message
|
@@ -48,8 +45,7 @@ class StubbaTestResultTest < Mocha::TestCase
|
|
48
45
|
def test_should_include_expectation_verification_failure_in_failure_count
|
49
46
|
test_result = run_as_test do
|
50
47
|
object = Class.new do
|
51
|
-
def message
|
52
|
-
end
|
48
|
+
def message; end
|
53
49
|
end.new
|
54
50
|
object.expects(:message)
|
55
51
|
end
|
@@ -63,6 +59,7 @@ class StubbaTestResultTest < Mocha::TestCase
|
|
63
59
|
assert_equal 1, test_result.failure_count
|
64
60
|
end
|
65
61
|
|
62
|
+
# rubocop:disable Style/Semicolon
|
66
63
|
def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called
|
67
64
|
execution_point = nil
|
68
65
|
test_result = run_as_test do
|
@@ -71,5 +68,5 @@ class StubbaTestResultTest < Mocha::TestCase
|
|
71
68
|
assert_equal 1, test_result.failure_count
|
72
69
|
assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
|
73
70
|
end
|
74
|
-
|
71
|
+
# rubocop:enable Style/Semicolon
|
75
72
|
end
|
@@ -3,7 +3,6 @@ require 'mocha/setup'
|
|
3
3
|
require 'execution_point'
|
4
4
|
|
5
5
|
class StubbingErrorBacktraceTest < Mocha::TestCase
|
6
|
-
|
7
6
|
include AcceptanceTest
|
8
7
|
|
9
8
|
def setup
|
@@ -14,6 +13,7 @@ class StubbingErrorBacktraceTest < Mocha::TestCase
|
|
14
13
|
teardown_acceptance_test
|
15
14
|
end
|
16
15
|
|
16
|
+
# rubocop:disable Style/Semicolon
|
17
17
|
def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_existent_method_was_made
|
18
18
|
execution_point = nil
|
19
19
|
object = Object.new
|
@@ -60,5 +60,5 @@ class StubbingErrorBacktraceTest < Mocha::TestCase
|
|
60
60
|
assert_equal 1, test_result.error_count
|
61
61
|
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
|
62
62
|
end
|
63
|
-
|
63
|
+
# rubocop:enable Style/Semicolon
|
64
64
|
end
|
@@ -3,7 +3,6 @@ require 'mocha/setup'
|
|
3
3
|
require 'execution_point'
|
4
4
|
|
5
5
|
class StubbingFrozenObjectTest < Mocha::TestCase
|
6
|
-
|
7
6
|
include AcceptanceTest
|
8
7
|
|
9
8
|
def setup
|
@@ -14,6 +13,7 @@ class StubbingFrozenObjectTest < Mocha::TestCase
|
|
14
13
|
teardown_acceptance_test
|
15
14
|
end
|
16
15
|
|
16
|
+
# rubocop:disable Style/Semicolon
|
17
17
|
def test_should_fail_fast_if_attempting_to_stub_method_on_frozen_object
|
18
18
|
object = Object.new
|
19
19
|
object.freeze
|
@@ -85,4 +85,5 @@ class StubbingFrozenObjectTest < Mocha::TestCase
|
|
85
85
|
assert_equal 1, test_result.error_count
|
86
86
|
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
|
87
87
|
end
|
88
|
+
# rubocop:enable Style/Semicolon
|
88
89
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
4
|
class StubbingMethodAcceptingBlockParameterTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include AcceptanceTest
|
7
6
|
|
8
7
|
def setup
|
@@ -15,34 +14,40 @@ class StubbingMethodAcceptingBlockParameterTest < Mocha::TestCase
|
|
15
14
|
|
16
15
|
def test_stubbing_class_method_accepting_block_parameter_should_restore_original_method
|
17
16
|
klass = Class.new do
|
18
|
-
def self.my_class_method(&block)
|
17
|
+
def self.my_class_method(&block)
|
18
|
+
block.call
|
19
|
+
end
|
19
20
|
end
|
20
21
|
test_result = run_as_test do
|
21
22
|
klass.stubs(:my_class_method)
|
22
23
|
end
|
23
24
|
assert_passed(test_result)
|
24
|
-
assert_equal :return_value, klass.my_class_method { :return_value }
|
25
|
+
assert_equal :return_value, (klass.my_class_method { :return_value })
|
25
26
|
end
|
26
27
|
|
27
28
|
def test_stubbing_instance_method_accepting_block_parameter_should_restore_original_method
|
28
29
|
instance = Class.new do
|
29
|
-
def my_instance_method
|
30
|
+
def my_instance_method
|
31
|
+
yield
|
32
|
+
end
|
30
33
|
end.new
|
31
34
|
test_result = run_as_test do
|
32
35
|
instance.stubs(:my_instance_method)
|
33
36
|
end
|
34
37
|
assert_passed(test_result)
|
35
|
-
assert_equal :return_value, instance.my_instance_method { :return_value }
|
38
|
+
assert_equal :return_value, (instance.my_instance_method { :return_value })
|
36
39
|
end
|
37
40
|
|
38
41
|
def test_stubbing_any_instance_method_accepting_block_parameter_should_restore_original_method
|
39
42
|
klass = Class.new do
|
40
|
-
def my_instance_method
|
43
|
+
def my_instance_method
|
44
|
+
yield
|
45
|
+
end
|
41
46
|
end
|
42
47
|
test_result = run_as_test do
|
43
48
|
klass.any_instance.stubs(:my_instance_method)
|
44
49
|
end
|
45
50
|
assert_passed(test_result)
|
46
|
-
assert_equal :return_value, klass.new.my_instance_method { :return_value }
|
51
|
+
assert_equal :return_value, (klass.new.my_instance_method { :return_value })
|
47
52
|
end
|
48
53
|
end
|