mocha 1.7.0 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +7 -30
- data/CONTRIBUTING.md +4 -9
- data/README.md +55 -27
- data/RELEASE.md +89 -0
- data/Rakefile +15 -16
- data/bin/build-matrix +15 -2
- data/docs/CNAME +1 -0
- data/docs/Mocha.html +254 -0
- data/docs/Mocha/API.html +1287 -0
- data/docs/Mocha/ClassMethods.html +264 -0
- data/docs/Mocha/Configuration.html +1525 -0
- data/docs/Mocha/Expectation.html +2654 -0
- data/docs/Mocha/ExpectationError.html +152 -0
- data/docs/Mocha/ExpectationErrorFactory.html +260 -0
- data/docs/Mocha/Hooks.html +370 -0
- data/docs/Mocha/Integration.html +125 -0
- data/docs/Mocha/Integration/MiniTest.html +123 -0
- data/docs/Mocha/Integration/MiniTest/Adapter.html +164 -0
- data/docs/Mocha/Integration/TestUnit.html +123 -0
- data/docs/Mocha/Integration/TestUnit/Adapter.html +164 -0
- data/docs/Mocha/Mock.html +1237 -0
- data/docs/Mocha/ObjectMethods.html +765 -0
- data/docs/Mocha/ParameterMatchers.html +2961 -0
- data/docs/Mocha/ParameterMatchers/AllOf.html +153 -0
- data/docs/Mocha/ParameterMatchers/AnyOf.html +153 -0
- data/docs/Mocha/ParameterMatchers/AnyParameters.html +153 -0
- data/docs/Mocha/ParameterMatchers/Anything.html +153 -0
- data/docs/Mocha/ParameterMatchers/Base.html +441 -0
- data/docs/Mocha/ParameterMatchers/Equals.html +153 -0
- data/docs/Mocha/ParameterMatchers/EquivalentUri.html +153 -0
- data/docs/Mocha/ParameterMatchers/HasEntries.html +153 -0
- data/docs/Mocha/ParameterMatchers/HasEntry.html +153 -0
- data/docs/Mocha/ParameterMatchers/HasKey.html +153 -0
- data/docs/Mocha/ParameterMatchers/HasValue.html +153 -0
- data/docs/Mocha/ParameterMatchers/Includes.html +153 -0
- data/docs/Mocha/ParameterMatchers/InstanceOf.html +153 -0
- data/docs/Mocha/ParameterMatchers/IsA.html +153 -0
- data/docs/Mocha/ParameterMatchers/KindOf.html +153 -0
- data/docs/Mocha/ParameterMatchers/Not.html +153 -0
- data/docs/Mocha/ParameterMatchers/Optionally.html +153 -0
- data/docs/Mocha/ParameterMatchers/RegexpMatches.html +153 -0
- data/docs/Mocha/ParameterMatchers/RespondsWith.html +153 -0
- data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +153 -0
- data/docs/Mocha/Sequence.html +149 -0
- data/docs/Mocha/StateMachine.html +527 -0
- data/docs/Mocha/StateMachine/State.html +140 -0
- data/docs/Mocha/StateMachine/StatePredicate.html +140 -0
- data/docs/Mocha/StubbingError.html +150 -0
- data/docs/_index.html +519 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +496 -0
- data/docs/file.COPYING.html +81 -0
- data/docs/file.MIT-LICENSE.html +85 -0
- data/docs/file.README.html +448 -0
- data/docs/file.RELEASE.html +974 -0
- data/docs/file_list.html +71 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +448 -0
- data/docs/js/app.js +303 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +635 -0
- data/docs/top-level-namespace.html +118 -0
- data/gemfiles/Gemfile.minitest.5.11.3 +7 -0
- data/init.rb +1 -3
- data/lib/mocha.rb +8 -0
- data/lib/mocha/any_instance_method.rb +11 -53
- data/lib/mocha/api.rb +120 -56
- data/lib/mocha/cardinality.rb +26 -11
- data/lib/mocha/class_methods.rb +17 -15
- data/lib/mocha/configuration.rb +351 -67
- data/lib/mocha/deprecation.rb +2 -1
- data/lib/mocha/detection/test_unit.rb +1 -3
- data/lib/mocha/exception_raiser.rb +2 -1
- data/lib/mocha/expectation.rb +56 -58
- data/lib/mocha/expectation_error.rb +1 -3
- data/lib/mocha/expectation_list.rb +6 -6
- data/lib/mocha/inspect.rb +28 -26
- data/lib/mocha/instance_method.rb +19 -2
- data/lib/mocha/integration.rb +1 -3
- data/lib/mocha/integration/mini_test.rb +7 -0
- data/lib/mocha/integration/test_unit.rb +7 -0
- data/lib/mocha/invocation.rb +73 -0
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/minitest.rb +6 -1
- data/lib/mocha/mock.rb +46 -31
- data/lib/mocha/mockery.rb +25 -61
- data/lib/mocha/names.rb +1 -1
- data/lib/mocha/object_methods.rb +13 -19
- data/lib/mocha/parameter_matchers.rb +1 -1
- data/lib/mocha/parameter_matchers/all_of.rb +1 -1
- data/lib/mocha/parameter_matchers/any_of.rb +1 -1
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -9
- data/lib/mocha/parameter_matchers/includes.rb +2 -0
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/return_values.rb +3 -3
- data/lib/mocha/setup.rb +5 -0
- data/lib/mocha/single_return_value.rb +2 -1
- data/lib/mocha/singleton_class.rb +9 -0
- data/lib/mocha/stubbed_method.rb +127 -0
- data/lib/mocha/test_unit.rb +6 -1
- data/lib/mocha/thrower.rb +2 -1
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/mocha.gemspec +3 -6
- data/test/acceptance/acceptance_test_helper.rb +6 -0
- data/test/acceptance/bug_18914_test.rb +0 -1
- data/test/acceptance/bug_21465_test.rb +0 -1
- data/test/acceptance/bug_21563_test.rb +0 -1
- data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +69 -0
- data/test/acceptance/exception_rescue_test.rb +1 -2
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -1
- data/test/acceptance/expected_invocation_count_test.rb +2 -3
- data/test/acceptance/failure_messages_test.rb +0 -1
- data/test/acceptance/issue_272_test.rb +1 -2
- data/test/acceptance/issue_65_test.rb +0 -1
- data/test/acceptance/issue_70_test.rb +0 -1
- data/test/acceptance/mocha_example_test.rb +0 -1
- data/test/acceptance/mocha_test_result_test.rb +0 -1
- data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +99 -0
- data/test/acceptance/mock_test.rb +47 -6
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -1
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -1
- data/test/acceptance/optional_parameters_test.rb +0 -1
- data/test/acceptance/parameter_matcher_test.rb +0 -1
- data/test/acceptance/partial_mocks_test.rb +0 -1
- data/test/acceptance/prepend_test.rb +0 -1
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -1
- data/test/acceptance/raise_exception_test.rb +0 -1
- data/test/acceptance/return_value_test.rb +0 -1
- data/test/acceptance/sequence_test.rb +0 -1
- data/test/acceptance/states_test.rb +0 -1
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +1 -2
- data/test/acceptance/stub_any_instance_method_test.rb +20 -1
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -1
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -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 +1 -2
- data/test/acceptance/stub_everything_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -1
- 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 +0 -1
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -1
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -1
- data/test/acceptance/stub_module_method_test.rb +0 -1
- data/test/acceptance/stub_test.rb +0 -1
- data/test/acceptance/stubba_example_test.rb +0 -1
- data/test/acceptance/stubba_test_result_test.rb +0 -1
- data/test/acceptance/stubbing_error_backtrace_test.rb +4 -5
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -1
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -1
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +5 -5
- data/test/acceptance/stubbing_nil_test.rb +5 -5
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +27 -11
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +11 -11
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +11 -11
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +8 -8
- data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -1
- data/test/acceptance/throw_test.rb +0 -1
- data/test/acceptance/unexpected_invocation_test.rb +0 -1
- data/test/acceptance/unstubbing_test.rb +0 -1
- data/test/integration/shared_tests.rb +5 -3
- data/test/method_definer.rb +11 -17
- data/test/test_runner.rb +2 -0
- data/test/unit/any_instance_method_test.rb +60 -35
- data/test/unit/cardinality_test.rb +41 -23
- data/test/unit/central_test.rb +0 -1
- data/test/unit/class_methods_test.rb +1 -1
- data/test/unit/configuration_test.rb +12 -12
- data/test/unit/exception_raiser_test.rb +10 -5
- data/test/unit/expectation_list_test.rb +13 -11
- data/test/unit/expectation_test.rb +103 -103
- data/test/unit/instance_method_test.rb +282 -0
- data/test/unit/mock_test.rb +28 -19
- data/test/unit/mockery_test.rb +8 -11
- data/test/unit/module_methods_test.rb +2 -3
- data/test/unit/object_inspect_test.rb +16 -4
- data/test/unit/object_methods_test.rb +3 -2
- data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -9
- data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
- data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
- data/test/unit/parameter_matchers/has_key_test.rb +1 -1
- data/test/unit/parameter_matchers/has_value_test.rb +1 -1
- data/test/unit/parameter_matchers/includes_test.rb +1 -1
- data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
- data/test/unit/return_values_test.rb +25 -20
- data/test/unit/single_return_value_test.rb +6 -1
- data/test/unit/thrower_test.rb +7 -2
- data/yard-templates/default/layout/html/google_analytics.erb +6 -9
- metadata +78 -61
- data/lib/mocha/class_method.rb +0 -113
- data/lib/mocha/mini_test.rb +0 -5
- data/lib/mocha/module_method.rb +0 -6
- data/lib/mocha/module_methods.rb +0 -10
- data/lib/mocha/parameter_matchers/object.rb +0 -15
- data/lib/mocha/standalone.rb +0 -4
- data/lib/mocha/unexpected_invocation.rb +0 -24
- data/lib/mocha_standalone.rb +0 -4
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -56
- data/test/unit/class_method_test.rb +0 -254
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/
|
2
|
+
require 'mocha/configuration'
|
3
3
|
|
4
4
|
class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
|
5
5
|
include AcceptanceTest
|
@@ -13,7 +13,7 @@ class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_should_allow_stubbing_private_any_instance_method
|
16
|
-
Mocha
|
16
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :allow }
|
17
17
|
klass = Class.new do
|
18
18
|
def private_method; end
|
19
19
|
private :private_method
|
@@ -26,7 +26,7 @@ class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_should_allow_stubbing_protected_any_instance_method
|
29
|
-
Mocha
|
29
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :allow }
|
30
30
|
klass = Class.new do
|
31
31
|
def protected_method; end
|
32
32
|
protected :protected_method
|
@@ -39,7 +39,7 @@ class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_should_warn_when_stubbing_private_any_instance_method
|
42
|
-
Mocha
|
42
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :warn }
|
43
43
|
klass = Class.new do
|
44
44
|
def private_method; end
|
45
45
|
private :private_method
|
@@ -52,7 +52,7 @@ class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_should_warn_when_stubbing_protected_any_instance_method
|
55
|
-
Mocha
|
55
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :warn }
|
56
56
|
klass = Class.new do
|
57
57
|
def protected_method; end
|
58
58
|
protected :protected_method
|
@@ -65,7 +65,7 @@ class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_should_prevent_stubbing_private_any_instance_method
|
68
|
-
Mocha
|
68
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
69
69
|
klass = Class.new do
|
70
70
|
def private_method; end
|
71
71
|
private :private_method
|
@@ -78,7 +78,7 @@ class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def test_should_prevent_stubbing_protected_any_instance_method
|
81
|
-
Mocha
|
81
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
82
82
|
klass = Class.new do
|
83
83
|
def protected_method; end
|
84
84
|
protected :protected_method
|
@@ -115,7 +115,7 @@ class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def test_should_allow_stubbing_public_any_instance_method
|
118
|
-
Mocha
|
118
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
119
119
|
klass = Class.new do
|
120
120
|
def public_method; end
|
121
121
|
public :public_method
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/
|
2
|
+
require 'mocha/configuration'
|
3
3
|
|
4
4
|
class StubbingNonPublicClassMethodTest < Mocha::TestCase
|
5
5
|
include AcceptanceTest
|
@@ -14,7 +14,7 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
|
|
14
14
|
|
15
15
|
# rubocop:disable Lint/DuplicateMethods
|
16
16
|
def test_should_allow_stubbing_private_class_method
|
17
|
-
Mocha
|
17
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :allow }
|
18
18
|
klass = Class.new do
|
19
19
|
class << self
|
20
20
|
def private_method; end
|
@@ -29,7 +29,7 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_should_allow_stubbing_protected_class_method
|
32
|
-
Mocha
|
32
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :allow }
|
33
33
|
klass = Class.new do
|
34
34
|
class << self
|
35
35
|
def protected_method; end
|
@@ -44,7 +44,7 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_should_warn_when_stubbing_private_class_method
|
47
|
-
Mocha
|
47
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :warn }
|
48
48
|
klass = Class.new do
|
49
49
|
class << self
|
50
50
|
def private_method; end
|
@@ -59,7 +59,7 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_should_warn_when_stubbing_protected_class_method
|
62
|
-
Mocha
|
62
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :warn }
|
63
63
|
klass = Class.new do
|
64
64
|
class << self
|
65
65
|
def protected_method; end
|
@@ -74,7 +74,7 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_should_prevent_stubbing_private_class_method
|
77
|
-
Mocha
|
77
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
78
78
|
klass = Class.new do
|
79
79
|
class << self
|
80
80
|
def private_method; end
|
@@ -89,7 +89,7 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_should_prevent_stubbing_protected_class_method
|
92
|
-
Mocha
|
92
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
93
93
|
klass = Class.new do
|
94
94
|
class << self
|
95
95
|
def protected_method; end
|
@@ -132,7 +132,7 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def test_should_allow_stubbing_public_class_method
|
135
|
-
Mocha
|
135
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
136
136
|
klass = Class.new do
|
137
137
|
class << self
|
138
138
|
def public_method; end
|
@@ -147,7 +147,7 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
|
|
147
147
|
# rubocop:enable Lint/DuplicateMethods
|
148
148
|
|
149
149
|
def test_should_allow_stubbing_method_to_which_class_responds
|
150
|
-
Mocha
|
150
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
151
151
|
klass = Class.new do
|
152
152
|
class << self
|
153
153
|
def respond_to?(method, _include_private_methods = false)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/
|
2
|
+
require 'mocha/configuration'
|
3
3
|
|
4
4
|
class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
|
5
5
|
include AcceptanceTest
|
@@ -13,7 +13,7 @@ class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_should_allow_stubbing_private_instance_method
|
16
|
-
Mocha
|
16
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :allow }
|
17
17
|
instance = Class.new do
|
18
18
|
def private_method; end
|
19
19
|
private :private_method
|
@@ -26,7 +26,7 @@ class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_should_allow_stubbing_protected_instance_method
|
29
|
-
Mocha
|
29
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :allow }
|
30
30
|
instance = Class.new do
|
31
31
|
def protected_method; end
|
32
32
|
protected :protected_method
|
@@ -39,7 +39,7 @@ class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_should_warn_when_stubbing_private_instance_method
|
42
|
-
Mocha
|
42
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :warn }
|
43
43
|
instance = Class.new do
|
44
44
|
def private_method; end
|
45
45
|
private :private_method
|
@@ -52,7 +52,7 @@ class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_should_warn_when_stubbing_protected_instance_method
|
55
|
-
Mocha
|
55
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :warn }
|
56
56
|
instance = Class.new do
|
57
57
|
def protected_method; end
|
58
58
|
protected :protected_method
|
@@ -65,7 +65,7 @@ class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_should_prevent_stubbing_private_instance_method
|
68
|
-
Mocha
|
68
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
69
69
|
instance = Class.new do
|
70
70
|
def private_method; end
|
71
71
|
private :private_method
|
@@ -78,7 +78,7 @@ class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def test_should_prevent_stubbing_protected_instance_method
|
81
|
-
Mocha
|
81
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
82
82
|
instance = Class.new do
|
83
83
|
def protected_method; end
|
84
84
|
protected :protected_method
|
@@ -115,7 +115,7 @@ class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def test_should_allow_stubbing_public_instance_method
|
118
|
-
Mocha
|
118
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
119
119
|
instance = Class.new do
|
120
120
|
def public_method; end
|
121
121
|
public :public_method
|
@@ -127,7 +127,7 @@ class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def test_should_allow_stubbing_method_to_which_instance_responds
|
130
|
-
Mocha
|
130
|
+
Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
|
131
131
|
instance = Class.new do
|
132
132
|
def respond_to?(method, _include_private_methods = false)
|
133
133
|
(method == :method_to_which_instance_responds)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/
|
2
|
+
require 'mocha/configuration'
|
3
3
|
|
4
4
|
class StubbingOnNonMockObjectTest < Mocha::TestCase
|
5
5
|
include AcceptanceTest
|
@@ -13,7 +13,7 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_should_allow_stubbing_method_on_non_mock_object
|
16
|
-
Mocha
|
16
|
+
Mocha.configure { |c| c.stubbing_method_on_non_mock_object = :allow }
|
17
17
|
non_mock_object = Class.new do
|
18
18
|
def existing_method; end
|
19
19
|
end
|
@@ -25,7 +25,7 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_should_warn_on_stubbing_method_on_non_mock_object
|
28
|
-
Mocha
|
28
|
+
Mocha.configure { |c| c.stubbing_method_on_non_mock_object = :warn }
|
29
29
|
non_mock_object = Class.new do
|
30
30
|
def existing_method; end
|
31
31
|
end
|
@@ -37,7 +37,7 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_should_prevent_stubbing_method_on_non_mock_object
|
40
|
-
Mocha
|
40
|
+
Mocha.configure { |c| c.stubbing_method_on_non_mock_object = :prevent }
|
41
41
|
non_mock_object = Class.new do
|
42
42
|
def existing_method; end
|
43
43
|
end
|
@@ -60,7 +60,7 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_should_allow_stubbing_method_on_mock_object
|
63
|
-
Mocha
|
63
|
+
Mocha.configure { |c| c.stubbing_method_on_non_mock_object = :prevent }
|
64
64
|
test_result = run_as_test do
|
65
65
|
mock = mock('mock')
|
66
66
|
mock.stubs(:any_method)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'test_runner'
|
2
2
|
require 'execution_point'
|
3
3
|
|
4
|
+
# rubocop:disable Metrics/ModuleLength
|
4
5
|
module SharedTests
|
5
6
|
include TestRunner
|
6
7
|
|
@@ -63,7 +64,7 @@ module SharedTests
|
|
63
64
|
assert_equal [
|
64
65
|
'not all expectations were satisfied',
|
65
66
|
'unsatisfied expectations:',
|
66
|
-
'- expected exactly once,
|
67
|
+
'- expected exactly once, invoked never: #<Mock:expecting invocation>.expected(any_parameters)'
|
67
68
|
], test_result.failure_message_lines
|
68
69
|
end
|
69
70
|
|
@@ -101,7 +102,7 @@ module SharedTests
|
|
101
102
|
assert_equal [
|
102
103
|
'not all expectations were satisfied',
|
103
104
|
'unsatisfied expectations:',
|
104
|
-
'- expected exactly once,
|
105
|
+
'- expected exactly once, invoked never: #<Mock:expecting invocation>.expected(any_parameters)'
|
105
106
|
], test_result.failure_message_lines
|
106
107
|
end
|
107
108
|
|
@@ -151,7 +152,7 @@ module SharedTests
|
|
151
152
|
assert_equal [
|
152
153
|
'not all expectations were satisfied',
|
153
154
|
'unsatisfied expectations:',
|
154
|
-
"- expected exactly once,
|
155
|
+
"- expected exactly once, invoked never: #{object.mocha_inspect}.expected(any_parameters)"
|
155
156
|
], test_result.failure_message_lines
|
156
157
|
end
|
157
158
|
|
@@ -174,3 +175,4 @@ module SharedTests
|
|
174
175
|
end
|
175
176
|
# rubocop:enable Style/Semicolon
|
176
177
|
end
|
178
|
+
# rubocop:enable Metrics/ModuleLength
|
data/test/method_definer.rb
CHANGED
@@ -1,22 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'mocha/singleton_class'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def replace_instance_method(method_symbol, &block)
|
10
|
-
raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless respond_to?(method_symbol)
|
11
|
-
define_instance_method(method_symbol, &block)
|
12
|
-
end
|
3
|
+
module MethodDefiner
|
4
|
+
def define_instance_method(object, method_symbol, &block)
|
5
|
+
object.singleton_class.send(:define_method, method_symbol, block)
|
6
|
+
end
|
13
7
|
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
def replace_instance_method(object, method_symbol, &block)
|
9
|
+
raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless object.respond_to?(method_symbol)
|
10
|
+
define_instance_method(object, method_symbol, &block)
|
17
11
|
end
|
18
|
-
end
|
19
12
|
|
20
|
-
|
21
|
-
|
13
|
+
def define_instance_accessor(object, *symbols)
|
14
|
+
symbols.each { |symbol| object.singleton_class.send(:attr_accessor, symbol) }
|
15
|
+
end
|
22
16
|
end
|
data/test/test_runner.rb
CHANGED
@@ -7,6 +7,7 @@ module TestRunner
|
|
7
7
|
run_as_tests(:test_me => block)
|
8
8
|
end
|
9
9
|
|
10
|
+
# rubocop:disable Metrics/AbcSize
|
10
11
|
def run_as_tests(methods = {})
|
11
12
|
base_class = Mocha::TestCase
|
12
13
|
test_class = Class.new(base_class) do
|
@@ -44,6 +45,7 @@ module TestRunner
|
|
44
45
|
|
45
46
|
test_result
|
46
47
|
end
|
48
|
+
# rubocop:enable Metrics/AbcSize
|
47
49
|
|
48
50
|
def assert_passed(test_result)
|
49
51
|
flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0
|
@@ -1,14 +1,23 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
require 'method_definer'
|
3
|
+
require 'mocha/class_methods'
|
3
4
|
require 'mocha/mock'
|
4
5
|
require 'mocha/any_instance_method'
|
5
6
|
|
6
7
|
class AnyInstanceMethodTest < Mocha::TestCase
|
8
|
+
include MethodDefiner
|
7
9
|
include Mocha
|
8
10
|
|
11
|
+
def class_with_method(method, result = nil)
|
12
|
+
Class.new do
|
13
|
+
extend ClassMethods
|
14
|
+
define_method(method) { result } if method
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
9
18
|
unless RUBY_V2_PLUS
|
10
19
|
def test_should_hide_original_method
|
11
|
-
klass =
|
20
|
+
klass = class_with_method(:method_x)
|
12
21
|
method = AnyInstanceMethod.new(klass, :method_x)
|
13
22
|
|
14
23
|
method.hide_original_method
|
@@ -18,20 +27,20 @@ class AnyInstanceMethodTest < Mocha::TestCase
|
|
18
27
|
end
|
19
28
|
|
20
29
|
def test_should_not_raise_error_hiding_method_that_isnt_defined
|
21
|
-
klass =
|
30
|
+
klass = class_with_method(:irrelevant)
|
22
31
|
method = AnyInstanceMethod.new(klass, :method_x)
|
23
32
|
|
24
33
|
assert_nothing_raised { method.hide_original_method }
|
25
34
|
end
|
26
35
|
|
27
36
|
def test_should_define_a_new_method
|
28
|
-
klass =
|
37
|
+
klass = class_with_method(:method_x)
|
29
38
|
method = AnyInstanceMethod.new(klass, :method_x)
|
30
39
|
mocha = build_mock
|
31
40
|
mocha.expects(:method_x).with(:param1, :param2).returns(:result)
|
32
41
|
any_instance = Object.new
|
33
|
-
|
34
|
-
|
42
|
+
define_instance_method(any_instance, :mocha) { mocha }
|
43
|
+
define_instance_method(klass, :any_instance) { any_instance }
|
35
44
|
|
36
45
|
method.hide_original_method
|
37
46
|
method.define_new_method
|
@@ -43,12 +52,32 @@ class AnyInstanceMethodTest < Mocha::TestCase
|
|
43
52
|
assert mocha.__verified__?
|
44
53
|
end
|
45
54
|
|
46
|
-
def
|
47
|
-
klass =
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
def test_should_include_the_filename_and_line_number_in_exceptions
|
56
|
+
klass = class_with_method(:method_x)
|
57
|
+
method = AnyInstanceMethod.new(klass, :method_x)
|
58
|
+
mocha = build_mock
|
59
|
+
mocha.stubs(:method_x).raises(Exception)
|
60
|
+
any_instance = Object.new
|
61
|
+
define_instance_method(any_instance, :mocha) { mocha }
|
62
|
+
define_instance_method(klass, :any_instance) { any_instance }
|
63
|
+
|
64
|
+
method.hide_original_method
|
65
|
+
method.define_new_method
|
66
|
+
|
67
|
+
expected_filename = 'stubbed_method.rb'
|
68
|
+
expected_line_number = 61
|
69
|
+
|
70
|
+
exception = assert_raises(Exception) { klass.new.method_x }
|
71
|
+
matching_line = exception.backtrace.find do |line|
|
72
|
+
filename, line_number, _context = line.split(':')
|
73
|
+
filename.include?(expected_filename) && line_number.to_i == expected_line_number
|
51
74
|
end
|
75
|
+
|
76
|
+
assert_not_nil matching_line, "Expected to find #{expected_filename}:#{expected_line_number} in the backtrace:\n #{exception.backtrace.join("\n")}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_should_restore_original_method
|
80
|
+
klass = class_with_method(:method_x, :original_result)
|
52
81
|
method = AnyInstanceMethod.new(klass, :method_x)
|
53
82
|
|
54
83
|
method.hide_original_method
|
@@ -62,11 +91,7 @@ class AnyInstanceMethodTest < Mocha::TestCase
|
|
62
91
|
end
|
63
92
|
|
64
93
|
def test_should_not_restore_original_method_if_none_was_defined_in_first_place
|
65
|
-
klass =
|
66
|
-
def method_x
|
67
|
-
:new_result
|
68
|
-
end
|
69
|
-
end
|
94
|
+
klass = class_with_method(:method_x, :new_result)
|
70
95
|
method = AnyInstanceMethod.new(klass, :method_x)
|
71
96
|
|
72
97
|
method.restore_original_method
|
@@ -76,16 +101,16 @@ class AnyInstanceMethodTest < Mocha::TestCase
|
|
76
101
|
end
|
77
102
|
|
78
103
|
def test_should_call_remove_new_method
|
79
|
-
klass =
|
104
|
+
klass = class_with_method(:method_x)
|
80
105
|
any_instance = build_mock
|
81
106
|
any_instance_mocha = build_mock
|
82
107
|
any_instance.stubs(:mocha).returns(any_instance_mocha)
|
83
|
-
|
108
|
+
define_instance_method(klass, :any_instance) { any_instance }
|
84
109
|
method = AnyInstanceMethod.new(klass, :method_x)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
110
|
+
replace_instance_method(method, :restore_original_method) {}
|
111
|
+
replace_instance_method(method, :reset_mocha) {}
|
112
|
+
define_instance_accessor(method, :remove_called)
|
113
|
+
replace_instance_method(method, :remove_new_method) { self.remove_called = true }
|
89
114
|
|
90
115
|
method.unstub
|
91
116
|
|
@@ -93,16 +118,16 @@ class AnyInstanceMethodTest < Mocha::TestCase
|
|
93
118
|
end
|
94
119
|
|
95
120
|
def test_should_call_restore_original_method
|
96
|
-
klass =
|
121
|
+
klass = class_with_method(:method_x)
|
97
122
|
any_instance = build_mock
|
98
123
|
any_instance_mocha = build_mock
|
99
124
|
any_instance.stubs(:mocha).returns(any_instance_mocha)
|
100
|
-
|
125
|
+
define_instance_method(klass, :any_instance) { any_instance }
|
101
126
|
method = AnyInstanceMethod.new(klass, :method_x)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
127
|
+
replace_instance_method(method, :remove_new_method) {}
|
128
|
+
replace_instance_method(method, :reset_mocha) {}
|
129
|
+
define_instance_accessor(method, :restore_called)
|
130
|
+
replace_instance_method(method, :restore_original_method) { self.restore_called = true }
|
106
131
|
|
107
132
|
method.unstub
|
108
133
|
|
@@ -110,12 +135,12 @@ class AnyInstanceMethodTest < Mocha::TestCase
|
|
110
135
|
end
|
111
136
|
|
112
137
|
def test_should_call_mock_unstub
|
113
|
-
klass =
|
138
|
+
klass = class_with_method(:method_x)
|
114
139
|
|
115
140
|
method = AnyInstanceMethod.new(klass, :method_x)
|
116
141
|
|
117
|
-
|
118
|
-
|
142
|
+
replace_instance_method(method, :remove_new_method) {}
|
143
|
+
replace_instance_method(method, :restore_original_method) {}
|
119
144
|
mocha = Class.new do
|
120
145
|
class << self
|
121
146
|
attr_accessor :unstub_method
|
@@ -124,8 +149,8 @@ class AnyInstanceMethodTest < Mocha::TestCase
|
|
124
149
|
self.unstub_method = method
|
125
150
|
end
|
126
151
|
end
|
127
|
-
|
128
|
-
|
152
|
+
define_instance_method(mocha, :any_expectations?) { true }
|
153
|
+
replace_instance_method(method, :mock) { mocha }
|
129
154
|
|
130
155
|
method.unstub
|
131
156
|
|
@@ -135,9 +160,9 @@ class AnyInstanceMethodTest < Mocha::TestCase
|
|
135
160
|
def test_should_return_any_instance_mocha_for_stubbee
|
136
161
|
mocha = Object.new
|
137
162
|
any_instance = Object.new
|
138
|
-
|
139
|
-
stubbee =
|
140
|
-
|
163
|
+
define_instance_method(any_instance, :mocha) { mocha }
|
164
|
+
stubbee = class_with_method(:method_x)
|
165
|
+
define_instance_method(stubbee, :any_instance) { any_instance }
|
141
166
|
method = AnyInstanceMethod.new(stubbee, :method_name)
|
142
167
|
assert_equal stubbee.any_instance.mocha, method.mock
|
143
168
|
end
|