mocha 1.11.2 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -1
  3. data/README.md +28 -30
  4. data/RELEASE.md +25 -0
  5. data/Rakefile +6 -1
  6. data/lib/mocha/cardinality.rb +30 -27
  7. data/lib/mocha/expectation.rb +24 -24
  8. data/lib/mocha/mock.rb +1 -1
  9. data/lib/mocha/mockery.rb +9 -22
  10. data/lib/mocha/state_machine.rb +30 -38
  11. data/lib/mocha/version.rb +1 -1
  12. data/mocha.gemspec +3 -1
  13. metadata +5 -192
  14. data/docs/CNAME +0 -1
  15. data/docs/Mocha.html +0 -254
  16. data/docs/Mocha/API.html +0 -1285
  17. data/docs/Mocha/ClassMethods.html +0 -264
  18. data/docs/Mocha/Configuration.html +0 -1525
  19. data/docs/Mocha/Expectation.html +0 -2862
  20. data/docs/Mocha/ExpectationError.html +0 -152
  21. data/docs/Mocha/ExpectationErrorFactory.html +0 -260
  22. data/docs/Mocha/Hooks.html +0 -370
  23. data/docs/Mocha/Integration.html +0 -125
  24. data/docs/Mocha/Integration/MiniTest.html +0 -123
  25. data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -164
  26. data/docs/Mocha/Integration/TestUnit.html +0 -123
  27. data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -164
  28. data/docs/Mocha/Mock.html +0 -1210
  29. data/docs/Mocha/ObjectMethods.html +0 -765
  30. data/docs/Mocha/ParameterMatchers.html +0 -2949
  31. data/docs/Mocha/ParameterMatchers/AllOf.html +0 -153
  32. data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -153
  33. data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
  34. data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
  35. data/docs/Mocha/ParameterMatchers/Base.html +0 -441
  36. data/docs/Mocha/ParameterMatchers/Equals.html +0 -153
  37. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
  38. data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -153
  39. data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -153
  40. data/docs/Mocha/ParameterMatchers/HasKey.html +0 -153
  41. data/docs/Mocha/ParameterMatchers/HasValue.html +0 -153
  42. data/docs/Mocha/ParameterMatchers/Includes.html +0 -153
  43. data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -153
  44. data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
  45. data/docs/Mocha/ParameterMatchers/KindOf.html +0 -153
  46. data/docs/Mocha/ParameterMatchers/Not.html +0 -153
  47. data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
  48. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -153
  49. data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -153
  50. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -153
  51. data/docs/Mocha/Sequence.html +0 -149
  52. data/docs/Mocha/StateMachine.html +0 -527
  53. data/docs/Mocha/StateMachine/State.html +0 -140
  54. data/docs/Mocha/StateMachine/StatePredicate.html +0 -140
  55. data/docs/Mocha/StubbingError.html +0 -150
  56. data/docs/_index.html +0 -519
  57. data/docs/class_list.html +0 -51
  58. data/docs/css/common.css +0 -1
  59. data/docs/css/full_list.css +0 -58
  60. data/docs/css/style.css +0 -496
  61. data/docs/file.COPYING.html +0 -81
  62. data/docs/file.MIT-LICENSE.html +0 -85
  63. data/docs/file.README.html +0 -448
  64. data/docs/file.RELEASE.html +0 -1028
  65. data/docs/file_list.html +0 -71
  66. data/docs/frames.html +0 -17
  67. data/docs/index.html +0 -448
  68. data/docs/js/app.js +0 -303
  69. data/docs/js/full_list.js +0 -216
  70. data/docs/js/jquery.js +0 -4
  71. data/docs/method_list.html +0 -651
  72. data/docs/top-level-namespace.html +0 -118
  73. data/test/acceptance/acceptance_test_helper.rb +0 -42
  74. data/test/acceptance/bug_18914_test.rb +0 -37
  75. data/test/acceptance/bug_21465_test.rb +0 -31
  76. data/test/acceptance/bug_21563_test.rb +0 -22
  77. data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +0 -69
  78. data/test/acceptance/exception_rescue_test.rb +0 -53
  79. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
  80. data/test/acceptance/expected_invocation_count_test.rb +0 -229
  81. data/test/acceptance/failure_messages_test.rb +0 -77
  82. data/test/acceptance/issue_272_test.rb +0 -50
  83. data/test/acceptance/issue_457_test.rb +0 -31
  84. data/test/acceptance/issue_65_test.rb +0 -64
  85. data/test/acceptance/issue_70_test.rb +0 -53
  86. data/test/acceptance/mocha_example_test.rb +0 -106
  87. data/test/acceptance/mocha_test_result_test.rb +0 -83
  88. data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -98
  89. data/test/acceptance/mock_test.rb +0 -191
  90. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
  91. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
  92. data/test/acceptance/multiple_yielding_test.rb +0 -59
  93. data/test/acceptance/optional_parameters_test.rb +0 -67
  94. data/test/acceptance/parameter_matcher_test.rb +0 -299
  95. data/test/acceptance/partial_mocks_test.rb +0 -44
  96. data/test/acceptance/prepend_test.rb +0 -86
  97. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -76
  98. data/test/acceptance/raise_exception_test.rb +0 -36
  99. data/test/acceptance/return_value_test.rb +0 -49
  100. data/test/acceptance/sequence_test.rb +0 -189
  101. data/test/acceptance/states_test.rb +0 -71
  102. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -64
  103. data/test/acceptance/stub_any_instance_method_test.rb +0 -301
  104. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -105
  105. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
  106. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -73
  107. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -144
  108. data/test/acceptance/stub_everything_test.rb +0 -53
  109. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -91
  110. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -67
  111. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -67
  112. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -136
  113. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -76
  114. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
  115. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -67
  116. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -70
  117. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -38
  118. data/test/acceptance/stub_module_method_test.rb +0 -200
  119. data/test/acceptance/stub_test.rb +0 -49
  120. data/test/acceptance/stubba_example_test.rb +0 -103
  121. data/test/acceptance/stubba_test_result_test.rb +0 -71
  122. data/test/acceptance/stubbing_error_backtrace_test.rb +0 -63
  123. data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
  124. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -52
  125. data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
  126. data/test/acceptance/stubbing_nil_test.rb +0 -60
  127. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -157
  128. data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
  129. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
  130. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
  131. data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
  132. data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
  133. data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
  134. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -33
  135. data/test/acceptance/throw_test.rb +0 -42
  136. data/test/acceptance/unexpected_invocation_test.rb +0 -23
  137. data/test/acceptance/unstubbing_test.rb +0 -194
  138. data/test/acceptance/yielding_test.rb +0 -80
  139. data/test/assertions.rb +0 -8
  140. data/test/deprecation_disabler.rb +0 -15
  141. data/test/execution_point.rb +0 -36
  142. data/test/integration/mini_test_test.rb +0 -8
  143. data/test/integration/shared_tests.rb +0 -178
  144. data/test/integration/test_unit_test.rb +0 -8
  145. data/test/method_definer.rb +0 -16
  146. data/test/mini_test_result.rb +0 -96
  147. data/test/minitest_result.rb +0 -48
  148. data/test/simple_counter.rb +0 -11
  149. data/test/test_helper.rb +0 -58
  150. data/test/test_runner.rb +0 -58
  151. data/test/test_unit_result.rb +0 -22
  152. data/test/unit/any_instance_method_test.rb +0 -175
  153. data/test/unit/array_inspect_test.rb +0 -14
  154. data/test/unit/backtrace_filter_test.rb +0 -17
  155. data/test/unit/cardinality_test.rb +0 -72
  156. data/test/unit/central_test.rb +0 -98
  157. data/test/unit/change_state_side_effect_test.rb +0 -37
  158. data/test/unit/class_methods_test.rb +0 -69
  159. data/test/unit/configuration_test.rb +0 -37
  160. data/test/unit/date_time_inspect_test.rb +0 -19
  161. data/test/unit/exception_raiser_test.rb +0 -45
  162. data/test/unit/expectation_list_test.rb +0 -82
  163. data/test/unit/expectation_test.rb +0 -504
  164. data/test/unit/hash_inspect_test.rb +0 -14
  165. data/test/unit/hooks_test.rb +0 -35
  166. data/test/unit/in_state_ordering_constraint_test.rb +0 -39
  167. data/test/unit/instance_method_test.rb +0 -282
  168. data/test/unit/method_matcher_test.rb +0 -26
  169. data/test/unit/mock_test.rb +0 -372
  170. data/test/unit/mockery_test.rb +0 -171
  171. data/test/unit/module_methods_test.rb +0 -16
  172. data/test/unit/object_inspect_test.rb +0 -60
  173. data/test/unit/object_methods_test.rb +0 -63
  174. data/test/unit/parameter_matchers/all_of_test.rb +0 -24
  175. data/test/unit/parameter_matchers/any_of_test.rb +0 -24
  176. data/test/unit/parameter_matchers/anything_test.rb +0 -19
  177. data/test/unit/parameter_matchers/equals_test.rb +0 -23
  178. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -41
  179. data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
  180. data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
  181. data/test/unit/parameter_matchers/has_key_test.rb +0 -54
  182. data/test/unit/parameter_matchers/has_value_test.rb +0 -55
  183. data/test/unit/parameter_matchers/includes_test.rb +0 -106
  184. data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
  185. data/test/unit/parameter_matchers/is_a_test.rb +0 -23
  186. data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
  187. data/test/unit/parameter_matchers/not_test.rb +0 -24
  188. data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
  189. data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
  190. data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
  191. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
  192. data/test/unit/parameters_matcher_test.rb +0 -119
  193. data/test/unit/receivers_test.rb +0 -96
  194. data/test/unit/return_values_test.rb +0 -66
  195. data/test/unit/sequence_test.rb +0 -100
  196. data/test/unit/single_return_value_test.rb +0 -17
  197. data/test/unit/state_machine_test.rb +0 -96
  198. data/test/unit/string_inspect_test.rb +0 -9
  199. data/test/unit/thrower_test.rb +0 -23
  200. data/test/unit/yield_parameters_test.rb +0 -73
@@ -1,301 +0,0 @@
1
- require File.expand_path('../acceptance_test_helper', __FILE__)
2
-
3
- class StubAnyInstanceMethodTest < Mocha::TestCase
4
- include AcceptanceTest
5
-
6
- def setup
7
- setup_acceptance_test
8
- end
9
-
10
- def teardown
11
- teardown_acceptance_test
12
- end
13
-
14
- def test_should_stub_public_method_within_test
15
- klass = Class.new do
16
- def my_instance_method
17
- :original_return_value
18
- end
19
- end
20
- instance = klass.new
21
- test_result = run_as_test do
22
- klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
23
- assert_method_visibility instance, :my_instance_method, :public
24
- assert_equal :new_return_value, instance.my_instance_method
25
- end
26
- assert_passed(test_result)
27
- end
28
-
29
- def test_should_leave_stubbed_public_method_unchanged_after_test
30
- klass = Class.new do
31
- def my_instance_method
32
- :original_return_value
33
- end
34
- public :my_instance_method
35
- def self.public(*args); end
36
- end
37
- instance = klass.new
38
- run_as_test do
39
- klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
40
- end
41
- assert(instance.public_methods(false).any? { |m| m.to_s == 'my_instance_method' })
42
- assert_equal :original_return_value, instance.my_instance_method
43
- end
44
-
45
- def test_should_leave_stubbed_public_method_unchanged_after_test_when_it_was_originally_private_in_owning_module
46
- module_with_private_method = Module.new do
47
- def my_included_method
48
- :original_return_value
49
- end
50
- private :my_included_method
51
- end
52
- klass = Class.new do
53
- include module_with_private_method
54
- public :my_included_method
55
- end
56
- instance = klass.new
57
- test_result = run_as_test do
58
- klass.any_instance.stubs(:my_included_method).returns(:new_return_value)
59
- assert_equal :new_return_value, instance.my_included_method
60
- end
61
- assert_passed(test_result)
62
- assert_equal :original_return_value, instance.my_included_method
63
- end
64
-
65
- def test_should_leave_stubbed_protected_method_unchanged_after_test
66
- klass = Class.new do
67
- def my_instance_method
68
- :original_return_value
69
- end
70
- protected :my_instance_method
71
- def self.protected(*args); end
72
-
73
- def my_unprotected_instance_method
74
- my_instance_method
75
- end
76
- end
77
- instance = klass.new
78
- run_as_test do
79
- klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
80
- end
81
- assert(instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' })
82
- assert_equal :original_return_value, instance.my_unprotected_instance_method
83
- end
84
-
85
- def test_should_stub_protected_method_within_test
86
- klass = Class.new do
87
- def my_instance_method
88
- :original_return_value
89
- end
90
- protected :my_instance_method
91
- def self.protected(*args); end
92
-
93
- def my_unprotected_instance_method
94
- my_instance_method
95
- end
96
- end
97
- instance = klass.new
98
- test_result = run_as_test do
99
- klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
100
- assert_method_visibility instance, :my_instance_method, :protected
101
- end
102
- assert_passed(test_result)
103
- end
104
-
105
- def test_should_leave_stubbed_private_method_unchanged_after_test
106
- klass = Class.new do
107
- def my_instance_method
108
- :original_return_value
109
- end
110
- private :my_instance_method
111
- def self.private(*args); end
112
- end
113
- instance = klass.new
114
- run_as_test do
115
- klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
116
- end
117
- assert(instance.private_methods(false).any? { |m| m.to_s == 'my_instance_method' })
118
- assert_equal :original_return_value, instance.send(:my_instance_method)
119
- end
120
-
121
- def test_should_stub_private_method_within_test
122
- klass = Class.new do
123
- def my_instance_method
124
- :original_return_value
125
- end
126
- private :my_instance_method
127
- def self.private(*args); end
128
- end
129
- instance = klass.new
130
- test_result = run_as_test do
131
- klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
132
- assert_method_visibility instance, :my_instance_method, :private
133
- end
134
- assert_passed(test_result)
135
- end
136
-
137
- def test_should_reset_expectations_after_test
138
- klass = Class.new do
139
- def my_instance_method
140
- :original_return_value
141
- end
142
- end
143
- run_as_test do
144
- klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
145
- end
146
-
147
- assert_equal 0, klass.any_instance.mocha.__expectations__.length
148
- end
149
-
150
- def test_should_be_able_to_stub_a_public_superclass_method
151
- superklass = Class.new do
152
- def my_superclass_method
153
- :original_return_value
154
- end
155
- public :my_superclass_method
156
- end
157
- klass = Class.new(superklass)
158
- instance = klass.new
159
- test_result = run_as_test do
160
- klass.any_instance.stubs(:my_superclass_method).returns(:new_return_value)
161
- assert_method_visibility instance, :my_superclass_method, :public
162
- assert_equal :new_return_value, instance.my_superclass_method
163
- end
164
- assert_passed(test_result)
165
- assert(instance.public_methods(true).any? { |m| m.to_s == 'my_superclass_method' })
166
- assert(klass.public_methods(false).none? { |m| m.to_s == 'my_superclass_method' })
167
- assert_equal :original_return_value, instance.my_superclass_method
168
- end
169
-
170
- def test_should_be_able_to_stub_a_protected_superclass_method
171
- superklass = Class.new do
172
- def my_superclass_method
173
- :original_return_value
174
- end
175
- protected :my_superclass_method
176
- end
177
- klass = Class.new(superklass)
178
- instance = klass.new
179
- test_result = run_as_test do
180
- klass.any_instance.stubs(:my_superclass_method).returns(:new_return_value)
181
- assert_method_visibility instance, :my_superclass_method, :protected
182
- assert_equal :new_return_value, instance.send(:my_superclass_method)
183
- end
184
- assert_passed(test_result)
185
- assert(instance.protected_methods(true).any? { |m| m.to_s == 'my_superclass_method' })
186
- assert(klass.protected_methods(false).none? { |m| m.to_s == 'my_superclass_method' })
187
- assert_equal :original_return_value, instance.send(:my_superclass_method)
188
- end
189
-
190
- def test_should_be_able_to_stub_a_private_superclass_method
191
- superklass = Class.new do
192
- def my_superclass_method
193
- :original_return_value
194
- end
195
- private :my_superclass_method
196
- end
197
- klass = Class.new(superklass)
198
- instance = klass.new
199
- test_result = run_as_test do
200
- klass.any_instance.stubs(:my_superclass_method).returns(:new_return_value)
201
- assert_method_visibility instance, :my_superclass_method, :private
202
- assert_equal :new_return_value, instance.send(:my_superclass_method)
203
- end
204
- assert_passed(test_result)
205
- assert(instance.private_methods(true).any? { |m| m.to_s == 'my_superclass_method' })
206
- assert(klass.private_methods(false).none? { |m| m.to_s == 'my_superclass_method' })
207
- assert_equal :original_return_value, instance.send(:my_superclass_method)
208
- end
209
-
210
- # rubocop:disable Lint/DuplicateMethods
211
- 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
212
- ruby18_klass = Class.new do
213
- class << self
214
- def public_instance_methods(_include_superclass = true)
215
- ['my_instance_method']
216
- end
217
- end
218
- end
219
- test_result = run_as_test do
220
- ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
221
- assert_equal :new_return_value, ruby18_klass.new.my_instance_method
222
- end
223
- assert_passed(test_result)
224
- end
225
-
226
- 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
227
- ruby19_klass = Class.new do
228
- class << self
229
- def public_instance_methods(_include_superclass = true)
230
- [:my_instance_method]
231
- end
232
- end
233
- end
234
- test_result = run_as_test do
235
- ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
236
- assert_equal :new_return_value, ruby19_klass.new.my_instance_method
237
- end
238
- assert_passed(test_result)
239
- end
240
-
241
- 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
242
- ruby18_klass = Class.new do
243
- class << self
244
- def protected_instance_methods(_include_superclass = true)
245
- ['my_instance_method']
246
- end
247
- end
248
- end
249
- test_result = run_as_test do
250
- ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
251
- assert_equal :new_return_value, ruby18_klass.new.send(:my_instance_method)
252
- end
253
- assert_passed(test_result)
254
- end
255
-
256
- 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
257
- ruby19_klass = Class.new do
258
- class << self
259
- def protected_instance_methods(_include_superclass = true)
260
- [:my_instance_method]
261
- end
262
- end
263
- end
264
- test_result = run_as_test do
265
- ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
266
- assert_equal :new_return_value, ruby19_klass.new.send(:my_instance_method)
267
- end
268
- assert_passed(test_result)
269
- end
270
-
271
- 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
272
- ruby18_klass = Class.new do
273
- class << self
274
- def private_instance_methods(_include_superclass = true)
275
- ['my_instance_method']
276
- end
277
- end
278
- end
279
- test_result = run_as_test do
280
- ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
281
- assert_equal :new_return_value, ruby18_klass.new.send(:my_instance_method)
282
- end
283
- assert_passed(test_result)
284
- end
285
-
286
- 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
287
- ruby19_klass = Class.new do
288
- class << self
289
- def private_instance_methods(_include_superclass = true)
290
- [:my_instance_method]
291
- end
292
- end
293
- end
294
- test_result = run_as_test do
295
- ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
296
- assert_equal :new_return_value, ruby19_klass.new.send(:my_instance_method)
297
- end
298
- assert_passed(test_result)
299
- end
300
- # rubocop:enable Lint/DuplicateMethods
301
- end
@@ -1,105 +0,0 @@
1
- require File.expand_path('../acceptance_test_helper', __FILE__)
2
-
3
- class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
4
- include AcceptanceTest
5
-
6
- def setup
7
- setup_acceptance_test
8
- end
9
-
10
- def teardown
11
- teardown_acceptance_test
12
- end
13
-
14
- # rubocop:disable Lint/DuplicateMethods
15
- 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
16
- ruby18_klass = Class.new do
17
- class << self
18
- def public_methods(_include_superclass = true)
19
- ['my_class_method']
20
- end
21
- end
22
- end
23
- test_result = run_as_test do
24
- ruby18_klass.stubs(:my_class_method).returns(:new_return_value)
25
- assert_equal :new_return_value, ruby18_klass.my_class_method
26
- end
27
- assert_passed(test_result)
28
- end
29
-
30
- 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
31
- ruby19_klass = Class.new do
32
- class << self
33
- def public_methods(_include_superclass = true)
34
- [:my_class_method]
35
- end
36
- end
37
- end
38
- test_result = run_as_test do
39
- ruby19_klass.stubs(:my_class_method).returns(:new_return_value)
40
- assert_equal :new_return_value, ruby19_klass.my_class_method
41
- end
42
- assert_passed(test_result)
43
- end
44
-
45
- 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
46
- ruby18_klass = Class.new do
47
- class << self
48
- def protected_methods(_include_superclass = true)
49
- ['my_class_method']
50
- end
51
- end
52
- end
53
- test_result = run_as_test do
54
- ruby18_klass.stubs(:my_class_method).returns(:new_return_value)
55
- assert_equal :new_return_value, ruby18_klass.my_class_method
56
- end
57
- assert_passed(test_result)
58
- end
59
-
60
- 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
61
- ruby19_klass = Class.new do
62
- class << self
63
- def protected_methods(_include_superclass = true)
64
- [:my_class_method]
65
- end
66
- end
67
- end
68
- test_result = run_as_test do
69
- ruby19_klass.stubs(:my_class_method).returns(:new_return_value)
70
- assert_equal :new_return_value, ruby19_klass.my_class_method
71
- end
72
- assert_passed(test_result)
73
- end
74
-
75
- 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
76
- ruby18_klass = Class.new do
77
- class << self
78
- def private_methods(_include_superclass = true)
79
- ['my_class_method']
80
- end
81
- end
82
- end
83
- test_result = run_as_test do
84
- ruby18_klass.stubs(:my_class_method).returns(:new_return_value)
85
- assert_equal :new_return_value, ruby18_klass.my_class_method
86
- end
87
- assert_passed(test_result)
88
- end
89
-
90
- 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
91
- ruby19_klass = Class.new do
92
- class << self
93
- def private_methods(_include_superclass = true)
94
- [:my_class_method]
95
- end
96
- end
97
- end
98
- test_result = run_as_test do
99
- ruby19_klass.stubs(:my_class_method).returns(:new_return_value)
100
- assert_equal :new_return_value, ruby19_klass.my_class_method
101
- end
102
- assert_passed(test_result)
103
- end
104
- # rubocop:enable Lint/DuplicateMethods
105
- end
@@ -1,78 +0,0 @@
1
- require File.expand_path('../acceptance_test_helper', __FILE__)
2
-
3
- class StubClassMethodDefinedOnClassTest < Mocha::TestCase
4
- include AcceptanceTest
5
-
6
- def setup
7
- setup_acceptance_test
8
- end
9
-
10
- def teardown
11
- teardown_acceptance_test
12
- end
13
-
14
- # rubocop:disable Lint/DuplicateMethods
15
- def test_should_stub_public_method_and_leave_it_unchanged_after_test
16
- klass = Class.new do
17
- class << self
18
- def my_class_method
19
- :original_return_value
20
- end
21
- public :my_class_method
22
- def self.public(*args); end
23
- end
24
- end
25
- assert_snapshot_unchanged(klass) do
26
- test_result = run_as_test do
27
- klass.stubs(:my_class_method).returns(:new_return_value)
28
- assert_method_visibility klass, :my_class_method, :public
29
- assert_equal :new_return_value, klass.my_class_method
30
- end
31
- assert_passed(test_result)
32
- end
33
- assert_equal :original_return_value, klass.my_class_method
34
- end
35
-
36
- def test_should_stub_protected_method_and_leave_it_unchanged_after_test
37
- klass = Class.new do
38
- class << self
39
- def my_class_method
40
- :original_return_value
41
- end
42
- protected :my_class_method
43
- def self.protected(*args); end
44
- end
45
- end
46
- assert_snapshot_unchanged(klass) do
47
- test_result = run_as_test do
48
- klass.stubs(:my_class_method).returns(:new_return_value)
49
- assert_method_visibility klass, :my_class_method, :protected
50
- assert_equal :new_return_value, klass.send(:my_class_method)
51
- end
52
- assert_passed(test_result)
53
- end
54
- assert_equal :original_return_value, klass.send(:my_class_method)
55
- end
56
-
57
- def test_should_stub_private_method_and_leave_it_unchanged_after_test
58
- klass = Class.new do
59
- class << self
60
- def my_class_method
61
- :original_return_value
62
- end
63
- private :my_class_method
64
- def self.private(*args); end
65
- end
66
- end
67
- assert_snapshot_unchanged(klass) do
68
- test_result = run_as_test do
69
- klass.stubs(:my_class_method).returns(:new_return_value)
70
- assert_method_visibility klass, :my_class_method, :private
71
- assert_equal :new_return_value, klass.send(:my_class_method)
72
- end
73
- assert_passed(test_result)
74
- end
75
- assert_equal :original_return_value, klass.send(:my_class_method)
76
- end
77
- # rubocop:enable Lint/DuplicateMethods
78
- end