mocha 1.2.1 → 1.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +1 -0
  3. data/.rubocop.yml +61 -0
  4. data/.rubocop_todo.yml +27 -0
  5. data/.yardopts +1 -0
  6. data/CONTRIBUTING.md +4 -9
  7. data/Gemfile +29 -0
  8. data/README.md +104 -106
  9. data/RELEASE.md +277 -1
  10. data/Rakefile +46 -44
  11. data/gemfiles/Gemfile.minitest.latest +1 -0
  12. data/gemfiles/Gemfile.test-unit.latest +2 -5
  13. data/init.rb +1 -3
  14. data/lib/mocha/any_instance_method.rb +9 -62
  15. data/lib/mocha/api.rb +144 -68
  16. data/lib/mocha/argument_iterator.rb +4 -8
  17. data/lib/mocha/backtrace_filter.rb +1 -5
  18. data/lib/mocha/block_matcher.rb +31 -0
  19. data/lib/mocha/cardinality.rb +60 -49
  20. data/lib/mocha/central.rb +21 -12
  21. data/lib/mocha/change_state_side_effect.rb +0 -4
  22. data/lib/mocha/class_methods.rb +19 -21
  23. data/lib/mocha/configuration.rb +372 -18
  24. data/lib/mocha/debug.rb +3 -2
  25. data/lib/mocha/deprecation.rb +8 -11
  26. data/lib/mocha/detection/mini_test.rb +0 -2
  27. data/lib/mocha/detection/test_unit.rb +3 -5
  28. data/lib/mocha/error_with_filtered_backtrace.rb +13 -0
  29. data/lib/mocha/exception_raiser.rb +4 -6
  30. data/lib/mocha/expectation.rb +125 -89
  31. data/lib/mocha/expectation_error.rb +1 -1
  32. data/lib/mocha/expectation_error_factory.rb +0 -1
  33. data/lib/mocha/expectation_list.rb +7 -11
  34. data/lib/mocha/hooks.rb +1 -3
  35. data/lib/mocha/in_state_ordering_constraint.rb +0 -4
  36. data/lib/mocha/inspect.rb +30 -38
  37. data/lib/mocha/instance_method.rb +11 -8
  38. data/lib/mocha/integration/mini_test/adapter.rb +2 -4
  39. data/lib/mocha/integration/mini_test/exception_translation.rb +1 -1
  40. data/lib/mocha/integration/mini_test/nothing.rb +4 -4
  41. data/lib/mocha/integration/mini_test/version_13.rb +4 -1
  42. data/lib/mocha/integration/mini_test/version_140.rb +4 -1
  43. data/lib/mocha/integration/mini_test/version_141.rb +4 -1
  44. data/lib/mocha/integration/mini_test/version_142_to_172.rb +4 -1
  45. data/lib/mocha/integration/mini_test/version_200.rb +4 -1
  46. data/lib/mocha/integration/mini_test/version_201_to_222.rb +4 -1
  47. data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +4 -1
  48. data/lib/mocha/integration/mini_test/version_2112_to_320.rb +4 -1
  49. data/lib/mocha/integration/mini_test/version_230_to_2101.rb +4 -1
  50. data/lib/mocha/integration/mini_test.rb +7 -0
  51. data/lib/mocha/integration/monkey_patcher.rb +5 -7
  52. data/lib/mocha/integration/test_unit/adapter.rb +5 -6
  53. data/lib/mocha/integration/test_unit/gem_version_200.rb +5 -2
  54. data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +5 -2
  55. data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +5 -2
  56. data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +5 -2
  57. data/lib/mocha/integration/test_unit/nothing.rb +4 -4
  58. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +4 -1
  59. data/lib/mocha/integration/test_unit.rb +7 -2
  60. data/lib/mocha/integration.rb +2 -5
  61. data/lib/mocha/invocation.rb +86 -0
  62. data/lib/mocha/is_a.rb +0 -2
  63. data/lib/mocha/logger.rb +0 -4
  64. data/lib/mocha/macos_version.rb +5 -0
  65. data/lib/mocha/method_matcher.rb +1 -5
  66. data/lib/mocha/minitest.rb +9 -0
  67. data/lib/mocha/mock.rb +102 -58
  68. data/lib/mocha/mockery.rb +70 -99
  69. data/lib/mocha/names.rb +2 -12
  70. data/lib/mocha/not_initialized_error.rb +7 -0
  71. data/lib/mocha/object_methods.rb +25 -31
  72. data/lib/mocha/parameter_matchers/all_of.rb +2 -8
  73. data/lib/mocha/parameter_matchers/any_of.rb +2 -8
  74. data/lib/mocha/parameter_matchers/any_parameters.rb +3 -9
  75. data/lib/mocha/parameter_matchers/anything.rb +2 -8
  76. data/lib/mocha/parameter_matchers/base.rb +6 -12
  77. data/lib/mocha/parameter_matchers/equals.rb +0 -6
  78. data/lib/mocha/parameter_matchers/{query_string.rb → equivalent_uri.rb} +15 -15
  79. data/lib/mocha/parameter_matchers/has_entries.rb +2 -7
  80. data/lib/mocha/parameter_matchers/has_entry.rb +26 -21
  81. data/lib/mocha/parameter_matchers/has_key.rb +2 -7
  82. data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
  83. data/lib/mocha/parameter_matchers/has_value.rb +2 -7
  84. data/lib/mocha/parameter_matchers/includes.rb +6 -7
  85. data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
  86. data/lib/mocha/parameter_matchers/instance_of.rb +0 -6
  87. data/lib/mocha/parameter_matchers/is_a.rb +2 -7
  88. data/lib/mocha/parameter_matchers/kind_of.rb +2 -6
  89. data/lib/mocha/parameter_matchers/not.rb +2 -7
  90. data/lib/mocha/parameter_matchers/optionally.rb +4 -10
  91. data/lib/mocha/parameter_matchers/regexp_matches.rb +0 -6
  92. data/lib/mocha/parameter_matchers/responds_with.rb +3 -8
  93. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +2 -6
  94. data/lib/mocha/parameter_matchers.rb +3 -4
  95. data/lib/mocha/parameters_matcher.rb +6 -9
  96. data/lib/mocha/raised_exception.rb +11 -0
  97. data/lib/mocha/receivers.rb +10 -14
  98. data/lib/mocha/return_values.rb +4 -8
  99. data/lib/mocha/ruby_version.rb +8 -1
  100. data/lib/mocha/sequence.rb +4 -9
  101. data/lib/mocha/setup.rb +5 -0
  102. data/lib/mocha/single_return_value.rb +2 -5
  103. data/lib/mocha/state_machine.rb +33 -46
  104. data/lib/mocha/stubbed_method.rb +124 -0
  105. data/lib/mocha/stubbing_error.rb +2 -13
  106. data/lib/mocha/test_unit.rb +8 -2
  107. data/lib/mocha/thrower.rb +4 -6
  108. data/lib/mocha/thrown_object.rb +12 -0
  109. data/lib/mocha/version.rb +1 -1
  110. data/lib/mocha/yield_parameters.rb +7 -17
  111. data/mocha.gemspec +14 -65
  112. data/yard-templates/default/layout/html/google_analytics.erb +6 -9
  113. data/yard-templates/default/layout/html/setup.rb +2 -3
  114. metadata +25 -247
  115. data/bin/build-matrix +0 -70
  116. data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
  117. data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
  118. data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
  119. data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
  120. data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
  121. data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
  122. data/gemfiles/Gemfile.minitest.2.11.0 +0 -7
  123. data/gemfiles/Gemfile.minitest.2.11.2 +0 -7
  124. data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
  125. data/gemfiles/Gemfile.test-unit.2.0.0 +0 -7
  126. data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
  127. data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
  128. data/lib/mocha/class_method.rb +0 -119
  129. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +0 -58
  130. data/lib/mocha/mini_test.rb +0 -3
  131. data/lib/mocha/module_method.rb +0 -16
  132. data/lib/mocha/module_methods.rb +0 -14
  133. data/lib/mocha/multiple_yields.rb +0 -20
  134. data/lib/mocha/no_yields.rb +0 -11
  135. data/lib/mocha/parameter_matchers/object.rb +0 -17
  136. data/lib/mocha/pretty_parameters.rb +0 -28
  137. data/lib/mocha/single_yield.rb +0 -18
  138. data/lib/mocha/standalone.rb +0 -4
  139. data/lib/mocha/unexpected_invocation.rb +0 -26
  140. data/lib/mocha_standalone.rb +0 -4
  141. data/test/acceptance/acceptance_test_helper.rb +0 -41
  142. data/test/acceptance/bug_18914_test.rb +0 -43
  143. data/test/acceptance/bug_21465_test.rb +0 -34
  144. data/test/acceptance/bug_21563_test.rb +0 -25
  145. data/test/acceptance/exception_rescue_test.rb +0 -55
  146. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
  147. data/test/acceptance/expected_invocation_count_test.rb +0 -232
  148. data/test/acceptance/failure_messages_test.rb +0 -64
  149. data/test/acceptance/issue_272_test.rb +0 -52
  150. data/test/acceptance/issue_65_test.rb +0 -63
  151. data/test/acceptance/issue_70_test.rb +0 -55
  152. data/test/acceptance/mocha_example_test.rb +0 -98
  153. data/test/acceptance/mocha_test_result_test.rb +0 -84
  154. data/test/acceptance/mock_test.rb +0 -100
  155. data/test/acceptance/mock_with_initializer_block_test.rb +0 -51
  156. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -78
  157. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -68
  158. data/test/acceptance/optional_parameters_test.rb +0 -70
  159. data/test/acceptance/parameter_matcher_test.rb +0 -337
  160. data/test/acceptance/partial_mocks_test.rb +0 -47
  161. data/test/acceptance/prepend_test.rb +0 -89
  162. data/test/acceptance/raise_exception_test.rb +0 -39
  163. data/test/acceptance/return_value_test.rb +0 -52
  164. data/test/acceptance/sequence_test.rb +0 -192
  165. data/test/acceptance/states_test.rb +0 -70
  166. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -34
  167. data/test/acceptance/stub_any_instance_method_test.rb +0 -280
  168. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -106
  169. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
  170. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -75
  171. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -112
  172. data/test/acceptance/stub_everything_test.rb +0 -56
  173. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -93
  174. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -69
  175. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -69
  176. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -75
  177. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -78
  178. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
  179. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -70
  180. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -72
  181. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -39
  182. data/test/acceptance/stub_module_method_test.rb +0 -163
  183. data/test/acceptance/stub_test.rb +0 -52
  184. data/test/acceptance/stubba_example_test.rb +0 -102
  185. data/test/acceptance/stubba_test_result_test.rb +0 -66
  186. data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
  187. data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
  188. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -48
  189. data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -65
  190. data/test/acceptance/stubbing_nil_test.rb +0 -61
  191. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -143
  192. data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
  193. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -147
  194. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -130
  195. data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
  196. data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -143
  197. data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -64
  198. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -35
  199. data/test/acceptance/throw_test.rb +0 -45
  200. data/test/acceptance/unexpected_invocation_test.rb +0 -25
  201. data/test/acceptance/unstubbing_test.rb +0 -168
  202. data/test/assertions.rb +0 -8
  203. data/test/deprecation_disabler.rb +0 -15
  204. data/test/execution_point.rb +0 -36
  205. data/test/integration/mini_test_test.rb +0 -8
  206. data/test/integration/shared_tests.rb +0 -174
  207. data/test/integration/test_unit_test.rb +0 -8
  208. data/test/method_definer.rb +0 -24
  209. data/test/mini_test_result.rb +0 -90
  210. data/test/minitest_result.rb +0 -49
  211. data/test/simple_counter.rb +0 -13
  212. data/test/test_helper.rb +0 -50
  213. data/test/test_runner.rb +0 -58
  214. data/test/test_unit_result.rb +0 -20
  215. data/test/unit/any_instance_method_test.rb +0 -134
  216. data/test/unit/array_inspect_test.rb +0 -16
  217. data/test/unit/backtrace_filter_test.rb +0 -19
  218. data/test/unit/cardinality_test.rb +0 -56
  219. data/test/unit/central_test.rb +0 -100
  220. data/test/unit/change_state_side_effect_test.rb +0 -41
  221. data/test/unit/class_method_test.rb +0 -225
  222. data/test/unit/class_methods_test.rb +0 -40
  223. data/test/unit/configuration_test.rb +0 -38
  224. data/test/unit/date_time_inspect_test.rb +0 -21
  225. data/test/unit/exception_raiser_test.rb +0 -42
  226. data/test/unit/expectation_list_test.rb +0 -82
  227. data/test/unit/expectation_test.rb +0 -497
  228. data/test/unit/hash_inspect_test.rb +0 -16
  229. data/test/unit/hooks_test.rb +0 -29
  230. data/test/unit/in_state_ordering_constraint_test.rb +0 -43
  231. data/test/unit/method_matcher_test.rb +0 -28
  232. data/test/unit/mock_test.rb +0 -342
  233. data/test/unit/mockery_test.rb +0 -151
  234. data/test/unit/module_methods_test.rb +0 -19
  235. data/test/unit/multiple_yields_test.rb +0 -18
  236. data/test/unit/no_yields_test.rb +0 -18
  237. data/test/unit/object_inspect_test.rb +0 -39
  238. data/test/unit/object_methods_test.rb +0 -46
  239. data/test/unit/parameter_matchers/all_of_test.rb +0 -26
  240. data/test/unit/parameter_matchers/any_of_test.rb +0 -26
  241. data/test/unit/parameter_matchers/anything_test.rb +0 -21
  242. data/test/unit/parameter_matchers/equals_test.rb +0 -25
  243. data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
  244. data/test/unit/parameter_matchers/has_entry_test.rb +0 -129
  245. data/test/unit/parameter_matchers/has_key_test.rb +0 -55
  246. data/test/unit/parameter_matchers/has_value_test.rb +0 -57
  247. data/test/unit/parameter_matchers/includes_test.rb +0 -102
  248. data/test/unit/parameter_matchers/instance_of_test.rb +0 -25
  249. data/test/unit/parameter_matchers/is_a_test.rb +0 -25
  250. data/test/unit/parameter_matchers/kind_of_test.rb +0 -25
  251. data/test/unit/parameter_matchers/not_test.rb +0 -26
  252. data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -46
  253. data/test/unit/parameter_matchers/responds_with_test.rb +0 -32
  254. data/test/unit/parameter_matchers/stub_matcher.rb +0 -27
  255. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -25
  256. data/test/unit/parameters_matcher_test.rb +0 -121
  257. data/test/unit/receivers_test.rb +0 -66
  258. data/test/unit/return_values_test.rb +0 -63
  259. data/test/unit/sequence_test.rb +0 -104
  260. data/test/unit/single_return_value_test.rb +0 -14
  261. data/test/unit/single_yield_test.rb +0 -18
  262. data/test/unit/state_machine_test.rb +0 -98
  263. data/test/unit/string_inspect_test.rb +0 -11
  264. data/test/unit/thrower_test.rb +0 -20
  265. data/test/unit/yield_parameters_test.rb +0 -93
data/RELEASE.md CHANGED
@@ -1,5 +1,281 @@
1
1
  # Release Notes
2
2
 
3
+ ## 1.16.1
4
+
5
+ ### External changes
6
+
7
+ * Fix regression in `Mock#responds_like` behaviour - thanks to @adrianna-chang-shopify for reporting (#580,#583,77af2af1)
8
+
9
+ ## 1.16.0
10
+
11
+ ### External changes
12
+
13
+ * Default `Configuration#reinstate_undocumented_behaviour_from_v1_9=` to `false` (6fcaf947)
14
+ * Deprecate `Configuration#reinstate_undocumented_behaviour_from_v1_9=` (a797c5fd)
15
+
16
+ ### Internal changes
17
+
18
+ * Remove redundant deprecation disabling in MockTest (dc8ca969)
19
+
20
+ ## 1.15.0
21
+
22
+ ### External changes
23
+
24
+ * Fix examples using mock constructor with block (1cc17667)
25
+ * Add another example for `API#sequence` (b7a7d233, #59)
26
+ * Remove support for Ruby v1.8 (ddb5d672)
27
+ * Deprecate support for Ruby versions earlier than v2.0 - thanks to @wasabigeek (#553, #555)
28
+
29
+ ### Internal changes
30
+
31
+ * Update instructions for obtaining Rubygems API key (ed9c040a)
32
+ * Consistent definitions for `respond_to?` methods (#533)
33
+ * Run test tasks before release tasks (92a1bc6e, #447)
34
+ * Fix test:performance Rake task (#538, #539)
35
+ * Tidying following removal of support for Ruby v1.8 - thanks to @nitishr (#542)
36
+ * Remove `ParametersMatcher` from `Invocation#call_description` - thanks to @wasabigeek (#543)
37
+ * Remove unnecessary splatting in Invocation - thanks to @wasabigeek (#549)
38
+ * Extract `handle_method_call` from `method_missing` - thanks to @wasabigeek (#550)
39
+
40
+ ## 1.14.0
41
+
42
+ ### External changes
43
+
44
+ * Mock#expects,#stubs should return last expectation - thanks to @vlad-pisanov for #524 (b6b637db)
45
+
46
+ ### Internal changes
47
+
48
+ * Avoid breaking change in psych v4 in ruby v3.1 (08b9f4ca)
49
+ * Remove broken Dependabot badge from README (d446657a)
50
+ * Add Ruby 3.0 to the CI matrix - thanks to @mishina2228 for #526 (65bc626e)
51
+ * Move development dependencies from gemspec to Gemfile - thanks to @mishina2228 for #527 (dd127f7b)
52
+
53
+ ## 1.13.0
54
+
55
+ ### External changes
56
+
57
+ * Add `ParameterMatchers#has_keys` - thanks to @cstyles for #512 (18d8104)
58
+ * Fix misleading exception message in `ParameterMatchers#has_entry` - thanks to @cstyles for #513 (9c4ef13)
59
+ * Only add dependency on rubocop if we're actually going to use it (f2f879f)
60
+ * Fix rake dependency constraints for older Ruby versions (7ce5f29)
61
+
62
+ ### Internal changes
63
+
64
+ * Check documentation can be generated as part of CircleCI build (b30d9a9)
65
+ * Add --fail-on-warning option to yard rake task (53a6ee3)
66
+ * Add a weekly scheduled build to the CircleCI build (fd2a4c6)
67
+ * Add Ruby v1.8 to the CircleCI build matrix (818ca03)
68
+ * Add API token to fix CircleCI badge in README (607c5aa)
69
+ * Provide wrapped option for #mocha_inspect on hashes & arrays (d8f44bc)
70
+ * Use CircleCI instead of TravisCI for automated builds (c98c6ec)
71
+ * Switch to newer default Travis CI build env (c78f75c)
72
+ * Use latest Ruby versions in Travis CI builds (9e0043a)
73
+ * Use latest JRuby v9.2.18 in Travis CI builds (8c99a1b)
74
+ * Use consistent JRuby versions in Travis CI builds (0f849aa)
75
+ * Use more recent version of JRuby in Travis CI build matrix (58653db)
76
+
77
+ ## 1.12.0
78
+
79
+ ### External changes
80
+
81
+ * Various improvements to README inspired by #207 and #390 - thanks to @nitishr for his work on #390 (fed0eee6)
82
+ * Improve documentation related to `StateMachine` classes - thanks to @nitishr (#425 & #427)
83
+ * Fix regression in cardinality introduced in v1.10.0 (59454a8) and reported in #473 - thanks to @srvance for reporting and @nitishr for fixing (#474)
84
+ * Fix documentation for `Mocha::Expectation#when` - thanks to @olleolleolle (b4f59daa & #477)
85
+ * Remove `Mocha::Mock#respond_to?` from documentation - thanks to @nitishr (#480)
86
+ * Improvements to documentation for `Expectation#yields` & `#multiple_yields` - thanks to @andyw8 for reporting in #495 (1b6571c)
87
+ * Remove documentation & tests from gem to reduce its size by over 50% - thanks to @gabetax (#500)
88
+ * Update documentation to point to travis-ci.com instead of travis-ci.org
89
+
90
+ ### Internal changes
91
+
92
+ * Refactor `StateMachine`-related classes - thanks to @nitishr (#425 & #427)
93
+ * Remove redundant test - thanks to @nitishr (8e4f1a7c)
94
+ * Add Ruby 2.7 to Travis CI matrix - thanks to @bastelfreak (fc5ea2f2)
95
+ * Simplify `Mockery` - thanks to @nitishr (#449)
96
+ * Update Travis CI badge to point to main vs master branch (bd8028f8)
97
+ * Generate docs using newer version of yard (v0.9.25) (c619afac)
98
+ * Manually upgrade jquery in docs from v1.7.1 -> v1.9.0 to fix CVE-2017-16011 (211098a5, dd5eeedb & 1b76e4d5; also see #492)
99
+ * Remove reference to non-existent jquery source map to fix error in Chrome developer tools (20156555)
100
+ * Temporarily ignore Ruby v1.8.7 build failures (e5b9feef)
101
+
102
+ ## 1.11.2
103
+
104
+ ### External changes
105
+
106
+ * Fix regression introduced in v1.10.0 that meant `Object#inspect` was called unnecessarily (368abd98)
107
+ * Warn when mock object receives invocations in another test - thanks to @nitishr (#442)
108
+ * Avoid rubocop comments appearing in YARD-generated docs (d8019eed)
109
+
110
+ ### Internal changes
111
+
112
+ * Replace `StubbedMethod#original_method` & `#original_visibility` attribute reader methods with instance variables - thanks to @nitishr (d917f332)
113
+ * Set up `MochaExampleTest` & `StubbaExampleTest` as acceptance tests - thanks to @nitishr (4881cc58)
114
+ * Delete unused `PrettyParameters` class - thanks to @nitishr (314ea922)
115
+
116
+ ## 1.11.1
117
+
118
+ ### External changes
119
+
120
+ * The `reinstate_undocumented_behaviour_from_v1_9` configuration option is now enabled by default to give people a chance to see and fix the relevant deprecation warnings before the behaviour is removed in a future release (b91b1c9e)
121
+
122
+ ## 1.11.0
123
+
124
+ ### External changes
125
+
126
+ * Add `Expectation#with_block_given` & `Expectation#with_no_block_given` (#441).
127
+ * Allows non-deprecated solution for #382. Thanks to @yemartin for reporting and to @techbelly & @nitishr for feedback.
128
+ * Fix issue with non-Array arguments passed to `Expectation#multiple_yields` (#444).
129
+ * The undocumented behaviour is now properly supported and documented.
130
+
131
+ ### Internal changes
132
+
133
+ * Move static YARD options from Rake task to `.yardopts` file - thanks to @nitishr (#429)
134
+ * Simplify implementation of yielding functionality - thanks to @nitishr (#439)
135
+ * Add missing require statement to `acceptance_test_helper.rb` (1070fc02)
136
+ * Add some baseline acceptance tests for yielding behaviour (c2cac911)
137
+ * Display a sponsor button on GitHub repo page (9fc5911b)
138
+ * Use new Deprecation.warning behaviour in `Invocation#call` (932d1166)
139
+
140
+ ## 1.10.2
141
+
142
+ * Optionally reinstate undocumented behaviour from v1.9. This introduces a new configuration option (`reinstate_undocumented_behaviour_from_v1_9`) to reinstate a couple of bits of undocumented behaviour from v1.9 which were changed in v1.10 without any prior deprecation warning (#438):
143
+ * The behaviour of `API#mock`, `API#stub` and `API#stub_everything` when called with a symbol as the first argument.
144
+ * The behaviour of `Expectation#yields` and `Expectation#multiple_yields` when the stubbed method is called without a block.
145
+
146
+ ## 1.10.1
147
+
148
+ * Ensure ObjectMethods & ClassMethods included when API extended (43778756)
149
+ * Fix regression in `any_instance` stubbing of methods on object which has an implementation of `#respond_to?` that depends on the object's internal state - thanks to @rafaelfranca for reporting & @nitishr for fixing (#432, #434, 469d4b17)
150
+
151
+ ## 1.10.0
152
+
153
+ * Improve deprecation warning when requiring 'mocha/setup' (388f44d7)
154
+ * Add documentation for Cucumber integration (13ab797b)
155
+ * Add documentation about an undocumented feature of `API#mock`, `API#stub` & `API#stub_everything` being changed (7ed2e4e7, d30c1717)
156
+
157
+ ## 1.10.0.beta.1
158
+
159
+ * Hide `ClassMethods#method_visibility` & `#method_exists?` methods to avoid clash with Rails (#428)
160
+
161
+ ## 1.10.0.alpha
162
+
163
+ ### External changes
164
+
165
+ * Remove dependency on metaclass gem (#49, #365)
166
+ * Accept symbol (as well as a string) as mock/stub name - thanks to @nitishr (#347, #353, #377)
167
+ * More realistic examples in documentation for `Expectation#yields` and `#multiple_yields` - thanks to @nitishr (#352, #383)
168
+ * Improve documentation for `Mock#responds_like` & `#responds_like_instance_of` - thanks to @nitishr (#337, #384)
169
+ * Make `Expectation#yields` & `Expectation#multiple_yields` fail when the caller of the stubbed method does not provide a block. This is a change to an undocumented aspect of the public API's behaviour. If this causes your tests to fail, then fix it by removing the unnecessary call to `Expectation#yields` or `Expectation#multiple_yields` - thanks to @nitishr (#382)
170
+ * Document `MOCHA_OPTIONS` in README - thanks to @nitishr (#311, #386)
171
+ * Add documentation to explain how Mocha is intended to be used - thanks to @nitishr (#330, #385)
172
+ * Deprecation warning if integration using 'mocha/test_unit' or 'mocha/minitest' fails - thanks to @nitishr (#229, #389, c6032d0b)
173
+ * Require at least one specified sequence for `Expectation#in_sequence` - thanks to @nitishr (#79, #396, 9020248a)
174
+ * Make signatures of `Mock#unstub` & `ObjectMethods#unstub` consistent - thanks to @nitishr (#397, f04d437)
175
+ * Deprecate requiring 'mocha/setup' (36adf880)
176
+ * Optionally display matching invocations alongside expectations - thanks to @nitishr (#178, #394, 00f0540, #410)
177
+ * Put deprecations into effect (#400, #418):
178
+ * Remove deprecated 'mocha_standalone.rb' & 'mocha/standalone.rb'
179
+ * Fail fast if no test library loaded
180
+ * Removed optional block for `Mocha::API#mock`, `#stub` & `#stub_everything`
181
+ * Remove deprecated `ParameterMatchers#has_equivalent_query_string` method
182
+ * Remove deprecated 'mocha/mini_test.rb'
183
+ * Fix typo in docs for `Mocha::Configuration.prevent` (266ce71c)
184
+ * New-style configuration (see documentation for `Mocha::Configuration`) (#407, #421)
185
+ * Deprecate support for Ruby versions earlier than v1.9 (#325, c5f8496d)
186
+ * Deprecate support for versions of test-unit & minitest which need monkey-patching (a34e1a88)
187
+ * Deprecate old-style Rails plugin (#403, 2df77134)
188
+ * Documentation fixes & improvements which also fix YARD warnings (472d5416, a2c0d64a)
189
+
190
+ ### Internal changes
191
+
192
+ * Pin minitest to v5.11.3 for Ruby v1.8.7 to fix build; minitest no longer supports Ruby v1.8.7 (4a0a580)
193
+ * Upgrade JRuby to v9.2.8.0 in Travis CI builds (aa29b3f)
194
+ * Only run rubocop for MRI Ruby versions & non-integration test builds (8f1c6af)
195
+ * Reduce duplication in any instance method class - thanks to @nitishr (#378)
196
+ * Simplify `AnyInstanceMethod`, `ClassMethod`, `InstanceMethod`, `ModuleMethod` class hierarchy - thanks to @nitishr (#381)
197
+ * Simplify `ClassMethods#method_exists?` & `ObjectMethods#method_exists?` making them consistent - thanks to @nitishr (#270, #362, #370)
198
+ * Don't override definition of `singleton_class` in `ClassMethods` - thanks to @nitishr (#391, #392)
199
+ * Do not include 'method_definer' methods into all objects (#268, #402)
200
+ * Distinguish different `ObjectMethods` modules (#268, #404)
201
+ * Pass invocation to expectation list methods - thanks to @nitishr (#408, #409, #411)
202
+ * Consistently use `assert_raises` - thanks to @nitishr (#405, #412, a66b7bed)
203
+ * Update Ruby & JRuby versions in Travis CI config (18cb1a93, eb061c53)
204
+ * Rubocop improvements (aa16ea67...6f4db70b, 2a1240e6...e95716ae)
205
+ * Fix inconsistency in CardinalityTest (aa10e0a8)
206
+ * Fix test failures on Mac OSX Catalina - thanks to @nitishr (#413, #417, #419, 8a0f2535)
207
+ * Remove default argument in `Expectation#invoke` - thanks to @nitishr (#414, #420)
208
+
209
+ ## 1.9.0
210
+
211
+ * Add TruffleRuby to Travis CI build matrix - thanks to @deepj (#354)
212
+ * Explicitly set Travis CI OS to Ubuntu Trusty 14.04 (ded1fa45)
213
+ * Expand explanation of thread-safety concerns - thanks to @techbelly (#357)
214
+ * Refactor class method and any instance method - thanks to @chrisroos (#358)
215
+ * Rely on default bundler version in Travis CI builds (3352e9c5)
216
+ * Fix local build-matrix script (11abe231)
217
+ * No need to install latest bundler in build-matrix script (8247a894)
218
+
219
+ ## 1.8.0
220
+
221
+ * Constrain rubocop version to avoid breaking Travis CI builds (05e507f5)
222
+ * Avoid calling Kernel#format from ObjectMethods#mocha_inspect - thanks to @hoffmanilya (#345)
223
+ * Fix build matrix script (#346)
224
+ * Avoid deprecation warning in gemspec (4976e0bc)
225
+ * Removed link to documentation translation (ef428ea2)
226
+ * Don't use the new bundler v2 in builds (683ded9b)
227
+ * Moved documentation from https://gofreerange.com/mocha/docs to https://mocha.jamesmead.org/ [683ded...a17fde](https://github.com/freerange/mocha/compare/683ded...a17fde)
228
+
229
+ ## 1.7.0
230
+
231
+ * Update Ruby & JRuby versions in Travis CI config (9bf55631 & 3883af7e)
232
+ * Simplify gemspec (63744f86)
233
+ * Add rubocop and fix most cop violations (#341)
234
+ * Use Kernel#warn for deprecations - thanks to @etiennebarrie (#333, 196970a)
235
+
236
+ ## 1.6.0
237
+
238
+ * Fix subtle bug in setting correct visibility of stubbed module methods on `Kernel` or `Object` - thanks to @chrisroos (#295)
239
+ * Avoid mocks for partial mocking leaking into subsequent tests - thanks to @skliew for reporting (#331)
240
+ * Remove OpenCollective badge, backers & sponsors (a283a079)
241
+ * Change gem version badge to SVG format and add SemVer stability badge - thanks to @greysteil (#335)
242
+ * Improve documentation for Configuration (#236)
243
+
244
+ ## 1.5.0
245
+
246
+ * Prevent use of Mocha outside the context of a test/example - thanks to @andyw8 & @lzap (#327)
247
+
248
+ ## 1.4.0
249
+
250
+ * Fix deprecation warning for `assert_nil` in `ClassMethodTest` (#308 & #309)
251
+ * Display file and line number in deprecation warning - thanks to @chrisarcand (#310, #312 & #313)
252
+ * Rename `mocha/mini_test.rb` to `mocha/minitest.rb` - thanks to @grosser (#320 & #322)
253
+ * Fix warning when delegating to mock in Ruby 2.4 - thanks to @tjvc (#321 & #323)
254
+ * Updates to Travis CI configuration ([73af600..9732726](https://github.com/freerange/mocha/compare/73af600...9732726) & 0426e5e)
255
+
256
+ ## 1.3.0
257
+
258
+ * Ensure all tests run individually - thanks to @chrisroos (#267)
259
+ * Update Travis CI build status badge to show master branch status (#264)
260
+ * Correct RSpec section of the README - thanks to @myronmarston (0cc039c8)
261
+ * Fix pretty printing of quotes in `String#mocha_inspect` (#215 & #223)
262
+ * Add release instructions to README - thanks to @chrisroos (70a5febd & 3c664df7)
263
+ * Require at least Ruby v1.8.7 in gemspec - thanks to @knappe (3e20be8e)
264
+ * Remove redundant InstanceMethod#method_exists? - thanks to @chrisroos (8f58eddf)
265
+ * Reduce risk of hitting bug 12832 in Ruby v2.3 - thanks to @chrisroos (#277 & eca7560c)
266
+ * Fix JRuby build - thanks to @headius (jruby/jruby#4250) & @chrisroos (#274)
267
+ * Add latest stable version of JRuby to Travis CI build matrix (#288)
268
+ * Fix Ruby v1.8.7 builds on Travis CI (928b5a40 & 460dce5b)
269
+ * Deprecate passing block to mock object constructor (#290)
270
+ * Add a known issue to README for Ruby bug 12876 (#276)
271
+ * Add Ruby 2.4 and ruby-head to Travis CI build matrix - thanks to @junaruga (#297)
272
+ * Fix `Mocha::ParameterMatchers#includes` for `Array` values - thanks to @timcraft (#302)
273
+ * Use faster container-based virtual environments for Travis CI builds (#305)
274
+ * Rename `Mocha::ParameterMatchers::QueryStringMatches` to `QueryString` (#306)
275
+ * Handle blank parameter value for query string matcher - thanks to @weynsee (#303 & #304)
276
+ * Rename `Mocha::ParameterMatchers::QueryString` -> `EquivalentUri` (#307)
277
+ * Use `do ... end` instead of `{ ... }` in acceptance tests - thanks to @chrisroos (#294)
278
+
3
279
  ## 1.2.1
4
280
 
5
281
  * Fixed #272. Workaround Ruby bug 12832 which caused interpreter to hang. See https://bugs.ruby-lang.org/issues/12832. Thanks to @chrisroos & @petems (6f1c8b9b, #273).
@@ -395,7 +671,7 @@ Hash with wrong number of entries.
395
671
 
396
672
  ## 0.5.0
397
673
 
398
- - Parameter Matchers - Ive added a few Hamcrest-style parameter matchers which are designed to be used inside Expectation#with. The following matchers are currently available: anything(), includes(), has_key(), has_value(), has_entry(), all_of() & any_of(). More to follow soon. The idea is eventually to get rid of the nasty parameter_block option on Expectation#with.
674
+ - Parameter Matchers - I've added a few Hamcrest-style parameter matchers which are designed to be used inside Expectation#with. The following matchers are currently available: anything(), includes(), has_key(), has_value(), has_entry(), all_of() & any_of(). More to follow soon. The idea is eventually to get rid of the nasty parameter_block option on Expectation#with.
399
675
 
400
676
  object = mock()
401
677
  object.expects(:method).with(has_key('key_1'))
data/Rakefile CHANGED
@@ -1,17 +1,17 @@
1
- require "bundler"
2
- Bundler::GemHelper.install_tasks
3
- require "bundler/setup"
4
-
5
- MOCHA_DOCS_HOST = ENV['MOCHA_DOCS_HOST'] || 'gofreerange.com'
1
+ require 'bundler'
2
+ namespace 'rubygems' do
3
+ Bundler::GemHelper.install_tasks
4
+ end
5
+ require 'bundler/setup'
6
6
 
7
7
  require 'rake/testtask'
8
8
 
9
- desc "Run all tests"
9
+ desc 'Run all tests'
10
10
  task 'default' => ['test', 'test:performance']
11
11
 
12
- desc "Run tests"
12
+ desc 'Run tests'
13
13
  task 'test' do
14
- if test_library = ENV['MOCHA_RUN_INTEGRATION_TESTS']
14
+ if (test_library = ENV['MOCHA_RUN_INTEGRATION_TESTS'])
15
15
  Rake::Task["test:integration:#{test_library}"].invoke
16
16
  else
17
17
  Rake::Task['test:units'].invoke
@@ -19,35 +19,25 @@ task 'test' do
19
19
  end
20
20
  end
21
21
 
22
- namespace 'test' do
23
-
24
- unit_tests = FileList['test/unit/**/*_test.rb']
25
- all_acceptance_tests = FileList['test/acceptance/*_test.rb']
26
- ruby186_incompatible_acceptance_tests = FileList['test/acceptance/stub_class_method_defined_on_*_test.rb'] + FileList['test/acceptance/stub_instance_method_defined_on_*_test.rb']
27
- ruby186_compatible_acceptance_tests = all_acceptance_tests - ruby186_incompatible_acceptance_tests
28
-
29
- desc "Run unit tests"
22
+ namespace 'test' do # rubocop:disable Metrics/BlockLength
23
+ desc 'Run unit tests'
30
24
  Rake::TestTask.new('units') do |t|
31
25
  t.libs << 'test'
32
- t.test_files = unit_tests
26
+ t.test_files = FileList['test/unit/**/*_test.rb']
33
27
  t.verbose = true
34
28
  t.warning = true
35
29
  end
36
30
 
37
- desc "Run acceptance tests"
31
+ desc 'Run acceptance tests'
38
32
  Rake::TestTask.new('acceptance') do |t|
39
33
  t.libs << 'test'
40
- if defined?(RUBY_VERSION) && (RUBY_VERSION >= "1.8.7")
41
- t.test_files = all_acceptance_tests
42
- else
43
- t.test_files = ruby186_compatible_acceptance_tests
44
- end
34
+ t.test_files = FileList['test/acceptance/*_test.rb']
45
35
  t.verbose = true
46
36
  t.warning = true
47
37
  end
48
38
 
49
39
  namespace 'integration' do
50
- desc "Run MiniTest integration tests (intended to be run in its own process)"
40
+ desc 'Run MiniTest integration tests (intended to be run in its own process)'
51
41
  Rake::TestTask.new('minitest') do |t|
52
42
  t.libs << 'test'
53
43
  t.test_files = FileList['test/integration/mini_test_test.rb']
@@ -55,7 +45,7 @@ namespace 'test' do
55
45
  t.warning = true
56
46
  end
57
47
 
58
- desc "Run Test::Unit integration tests (intended to be run in its own process)"
48
+ desc 'Run Test::Unit integration tests (intended to be run in its own process)'
59
49
  Rake::TestTask.new('test-unit') do |t|
60
50
  t.libs << 'test'
61
51
  t.test_files = FileList['test/integration/test_unit_test.rb']
@@ -74,7 +64,7 @@ namespace 'test' do
74
64
  # t.rcov_opts << '--xref'
75
65
  # end
76
66
 
77
- desc "Run performance tests"
67
+ desc 'Run performance tests'
78
68
  task 'performance' do
79
69
  require File.join(File.dirname(__FILE__), 'test', 'acceptance', 'stubba_example_test')
80
70
  require File.join(File.dirname(__FILE__), 'test', 'acceptance', 'mocha_example_test')
@@ -84,9 +74,18 @@ namespace 'test' do
84
74
  puts "#{test_case}: #{benchmark_test_case(test_case, iterations)} seconds."
85
75
  end
86
76
  end
77
+ end
87
78
 
79
+ begin
80
+ require 'rubocop/rake_task'
81
+ if RUBY_VERSION >= '2.2.0' && (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby') && ENV['MOCHA_RUN_INTEGRATION_TESTS'].nil?
82
+ RuboCop::RakeTask.new
83
+ task 'test' => 'rubocop'
84
+ end
85
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
88
86
  end
89
87
 
88
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
90
89
  def benchmark_test_case(klass, iterations)
91
90
  require 'benchmark'
92
91
  require 'mocha/detection/mini_test'
@@ -94,33 +93,35 @@ def benchmark_test_case(klass, iterations)
94
93
  if defined?(MiniTest)
95
94
  minitest_version = Gem::Version.new(Mocha::Detection::MiniTest.version)
96
95
  if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version)
97
- result = Benchmark.realtime { iterations.times { |i| klass.run(MiniTest::CompositeReporter.new) } }
96
+ Minitest.seed = 1
97
+ result = Benchmark.realtime { iterations.times { |_i| klass.run(MiniTest::CompositeReporter.new) } }
98
98
  MiniTest::Runnable.runnables.delete(klass)
99
99
  result
100
100
  else
101
101
  MiniTest::Unit.output = StringIO.new
102
- Benchmark.realtime { iterations.times { |i| MiniTest::Unit.new.run([klass]) } }
102
+ Benchmark.realtime { iterations.times { |_i| MiniTest::Unit.new.run([klass]) } }
103
103
  end
104
104
  else
105
105
  load 'test/unit/ui/console/testrunner.rb' unless defined?(Test::Unit::UI::Console::TestRunner)
106
- unless $silent_option
106
+ unless @silent_option
107
107
  begin
108
108
  load 'test/unit/ui/console/outputlevel.rb' unless defined?(Test::Unit::UI::Console::OutputLevel::SILENT)
109
- $silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT }
109
+ @silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT }
110
110
  rescue LoadError
111
- $silent_option = Test::Unit::UI::SILENT
111
+ @silent_option = Test::Unit::UI::SILENT
112
112
  end
113
113
  end
114
- Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, $silent_option) } }
114
+ Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, @silent_option) } }
115
115
  end
116
116
  end
117
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
117
118
 
118
- if ENV["MOCHA_GENERATE_DOCS"]
119
+ if ENV['MOCHA_GENERATE_DOCS']
119
120
  require 'yard'
120
121
 
121
122
  desc 'Remove generated documentation'
122
123
  task 'clobber_yardoc' do
123
- `rm -rf ./doc`
124
+ `rm -rf ./docs`
124
125
  end
125
126
 
126
127
  task 'docs_environment' do
@@ -131,19 +132,20 @@ if ENV["MOCHA_GENERATE_DOCS"]
131
132
 
132
133
  desc 'Generate documentation'
133
134
  YARD::Rake::YardocTask.new('yardoc' => 'docs_environment') do |task|
134
- task.options = ["--title", "Mocha #{Mocha::VERSION}"]
135
+ task.options = ['--title', "Mocha #{Mocha::VERSION}", '--fail-on-warning']
135
136
  end
136
137
 
137
- desc "Generate documentation"
138
- task 'generate_docs' => ['clobber_yardoc', 'yardoc']
138
+ task 'checkout_docs_cname' do
139
+ `git checkout docs/CNAME`
140
+ end
139
141
 
140
- desc "Publish docs to #{MOCHA_DOCS_HOST}/docs/mocha"
141
- task 'publish_docs' => 'generate_docs' do
142
- path = "/home/freerange/docs/mocha"
143
- system %{ssh #{MOCHA_DOCS_HOST} "sudo rm -fr #{path} && mkdir -p #{path}" && scp -r doc/* #{MOCHA_DOCS_HOST}:#{path}}
142
+ task 'checkout_docs_js' do
143
+ `git checkout docs/js/app.js`
144
+ `git checkout docs/js/jquery.js`
144
145
  end
145
- end
146
146
 
147
- task 'release' => 'default' do
148
- Rake::Task['publish_docs'].invoke
147
+ desc 'Generate documentation'
148
+ task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname checkout_docs_js]
149
149
  end
150
+
151
+ task 'release' => ['default', 'rubygems:release']
@@ -3,5 +3,6 @@ source 'https://rubygems.org'
3
3
  gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
+ gem "rake"
6
7
  gem "minitest"
7
8
  end
@@ -3,9 +3,6 @@ source 'https://rubygems.org'
3
3
  gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
- if RUBY_VERSION < '1.9'
7
- gem "test-unit", "~> 2"
8
- else
9
- gem "test-unit"
10
- end
6
+ gem "rake"
7
+ gem "test-unit"
11
8
  end
data/init.rb CHANGED
@@ -1,3 +1 @@
1
- # Mocha should no longer be loaded at plugin load time
2
- # You should explicitly load Mocha *after* Test::Unit or MiniTest have been loaded
3
- # e.g. by adding "require 'mocha'" at the bottom of test/test_helper.rb
1
+ warn 'Mocha deprecation warning: The old-style Rails plugin will not be supported in future versions of Mocha.'
@@ -1,72 +1,19 @@
1
- require 'mocha/ruby_version'
2
- require 'mocha/class_method'
1
+ require 'mocha/stubbed_method'
3
2
 
4
3
  module Mocha
4
+ class AnyInstanceMethod < StubbedMethod
5
+ private
5
6
 
6
- class AnyInstanceMethod < ClassMethod
7
-
8
- def mock
9
- stubbee.any_instance.mocha
10
- end
11
-
12
- def reset_mocha
13
- stubbee.any_instance.reset_mocha
14
- end
15
-
16
- def hide_original_method
17
- if @original_visibility = method_visibility(method)
18
- begin
19
- @original_method = stubbee.instance_method(method)
20
- if RUBY_V2_PLUS
21
- @definition_target = PrependedModule.new
22
- stubbee.__send__ :prepend, @definition_target
23
- else
24
- if @original_method && @original_method.owner == stubbee
25
- stubbee.send(:remove_method, method)
26
- end
27
- end
28
- rescue NameError
29
- # deal with nasties like ActiveRecord::Associations::AssociationProxy
30
- end
31
- end
32
- end
33
-
34
- def define_new_method
35
- definition_target.class_eval(<<-CODE, __FILE__, __LINE__ + 1)
36
- def #{method}(*args, &block)
37
- self.class.any_instance.mocha.method_missing(:#{method}, *args, &block)
38
- end
39
- CODE
40
- if @original_visibility
41
- Module.instance_method(@original_visibility).bind(definition_target).call(method)
42
- end
43
- end
44
-
45
- def remove_new_method
46
- definition_target.send(:remove_method, method)
47
- end
48
-
49
- def restore_original_method
50
- unless RUBY_V2_PLUS
51
- if @original_method && @original_method.owner == stubbee
52
- stubbee.send(:define_method, method, @original_method)
53
- Module.instance_method(@original_visibility).bind(stubbee).call(method)
54
- end
55
- end
7
+ def mock_owner
8
+ stubbee.any_instance
56
9
  end
57
10
 
58
- def method_visibility(method)
59
- (stubbee.public_instance_methods(true).include?(method) && :public) ||
60
- (stubbee.protected_instance_methods(true).include?(method) && :protected) ||
61
- (stubbee.private_instance_methods(true).include?(method) && :private)
11
+ def stubbee_method(method_name)
12
+ stubbee.instance_method(method_name)
62
13
  end
63
14
 
64
- private
65
-
66
- def definition_target
67
- @definition_target ||= stubbee
15
+ def original_method_owner
16
+ stubbee
68
17
  end
69
-
70
18
  end
71
-
72
19
  end