mocha 1.8.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (274) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.rubocop.yml +3 -0
  4. data/.rubocop_todo.yml +7 -30
  5. data/.yardopts +1 -0
  6. data/CONTRIBUTING.md +1 -1
  7. data/README.md +56 -31
  8. data/RELEASE.md +166 -0
  9. data/Rakefile +15 -7
  10. data/init.rb +1 -3
  11. data/lib/mocha/any_instance_method.rb +11 -53
  12. data/lib/mocha/api.rb +119 -56
  13. data/lib/mocha/block_matcher.rb +31 -0
  14. data/lib/mocha/cardinality.rb +52 -34
  15. data/lib/mocha/class_methods.rb +17 -15
  16. data/lib/mocha/configuration.rb +351 -67
  17. data/lib/mocha/deprecation.rb +2 -1
  18. data/lib/mocha/detection/test_unit.rb +1 -3
  19. data/lib/mocha/exception_raiser.rb +2 -1
  20. data/lib/mocha/expectation.rb +120 -81
  21. data/lib/mocha/expectation_error.rb +1 -3
  22. data/lib/mocha/expectation_list.rb +6 -6
  23. data/lib/mocha/inspect.rb +30 -26
  24. data/lib/mocha/instance_method.rb +19 -2
  25. data/lib/mocha/integration/mini_test.rb +7 -0
  26. data/lib/mocha/integration/test_unit.rb +7 -0
  27. data/lib/mocha/integration.rb +1 -3
  28. data/lib/mocha/invocation.rb +77 -0
  29. data/lib/mocha/macos_version.rb +5 -0
  30. data/lib/mocha/minitest.rb +6 -1
  31. data/lib/mocha/mock.rb +80 -39
  32. data/lib/mocha/mockery.rb +34 -80
  33. data/lib/mocha/names.rb +1 -1
  34. data/lib/mocha/object_methods.rb +13 -19
  35. data/lib/mocha/parameter_matchers/all_of.rb +1 -1
  36. data/lib/mocha/parameter_matchers/any_of.rb +1 -1
  37. data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -9
  38. data/lib/mocha/parameter_matchers/has_entries.rb +2 -3
  39. data/lib/mocha/parameter_matchers/has_entry.rb +24 -16
  40. data/lib/mocha/parameter_matchers/has_key.rb +2 -3
  41. data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
  42. data/lib/mocha/parameter_matchers/has_value.rb +2 -3
  43. data/lib/mocha/parameter_matchers/includes.rb +2 -0
  44. data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
  45. data/lib/mocha/parameter_matchers/is_a.rb +2 -3
  46. data/lib/mocha/parameter_matchers/not.rb +2 -3
  47. data/lib/mocha/parameter_matchers.rb +2 -1
  48. data/lib/mocha/raised_exception.rb +11 -0
  49. data/lib/mocha/return_values.rb +3 -3
  50. data/lib/mocha/setup.rb +5 -0
  51. data/lib/mocha/single_return_value.rb +2 -1
  52. data/lib/mocha/singleton_class.rb +9 -0
  53. data/lib/mocha/state_machine.rb +31 -40
  54. data/lib/mocha/stubbed_method.rb +125 -0
  55. data/lib/mocha/test_unit.rb +6 -1
  56. data/lib/mocha/thrower.rb +2 -1
  57. data/lib/mocha/thrown_object.rb +12 -0
  58. data/lib/mocha/version.rb +1 -1
  59. data/lib/mocha/yield_parameters.rb +5 -11
  60. data/lib/mocha.rb +8 -0
  61. data/mocha.gemspec +14 -10
  62. metadata +16 -233
  63. data/bin/build-matrix +0 -83
  64. data/docs/CNAME +0 -1
  65. data/docs/Mocha/API.html +0 -1056
  66. data/docs/Mocha/ClassMethods.html +0 -267
  67. data/docs/Mocha/Configuration.html +0 -626
  68. data/docs/Mocha/Expectation.html +0 -2709
  69. data/docs/Mocha/ExpectationError.html +0 -157
  70. data/docs/Mocha/ExpectationErrorFactory.html +0 -269
  71. data/docs/Mocha/Hooks.html +0 -385
  72. data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -165
  73. data/docs/Mocha/Integration/MiniTest.html +0 -123
  74. data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -165
  75. data/docs/Mocha/Integration/TestUnit.html +0 -123
  76. data/docs/Mocha/Integration.html +0 -125
  77. data/docs/Mocha/Mock.html +0 -1197
  78. data/docs/Mocha/ObjectMethods.html +0 -712
  79. data/docs/Mocha/ParameterMatchers/AllOf.html +0 -154
  80. data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -154
  81. data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
  82. data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
  83. data/docs/Mocha/ParameterMatchers/Base.html +0 -448
  84. data/docs/Mocha/ParameterMatchers/Equals.html +0 -154
  85. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
  86. data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -154
  87. data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -154
  88. data/docs/Mocha/ParameterMatchers/HasKey.html +0 -154
  89. data/docs/Mocha/ParameterMatchers/HasValue.html +0 -154
  90. data/docs/Mocha/ParameterMatchers/Includes.html +0 -154
  91. data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -154
  92. data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
  93. data/docs/Mocha/ParameterMatchers/KindOf.html +0 -154
  94. data/docs/Mocha/ParameterMatchers/Not.html +0 -154
  95. data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
  96. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -154
  97. data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -154
  98. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -154
  99. data/docs/Mocha/ParameterMatchers.html +0 -3049
  100. data/docs/Mocha/Sequence.html +0 -149
  101. data/docs/Mocha/StateMachine/State.html +0 -141
  102. data/docs/Mocha/StateMachine/StatePredicate.html +0 -141
  103. data/docs/Mocha/StateMachine.html +0 -539
  104. data/docs/Mocha/StubbingError.html +0 -150
  105. data/docs/Mocha/UnexpectedInvocation.html +0 -140
  106. data/docs/Mocha.html +0 -127
  107. data/docs/_index.html +0 -537
  108. data/docs/class_list.html +0 -51
  109. data/docs/css/common.css +0 -1
  110. data/docs/css/full_list.css +0 -58
  111. data/docs/css/style.css +0 -496
  112. data/docs/file.COPYING.html +0 -81
  113. data/docs/file.MIT-LICENSE.html +0 -85
  114. data/docs/file.README.html +0 -418
  115. data/docs/file.RELEASE.html +0 -875
  116. data/docs/file_list.html +0 -71
  117. data/docs/frames.html +0 -17
  118. data/docs/index.html +0 -418
  119. data/docs/js/app.js +0 -292
  120. data/docs/js/full_list.js +0 -216
  121. data/docs/js/jquery.js +0 -4
  122. data/docs/method_list.html +0 -571
  123. data/docs/top-level-namespace.html +0 -118
  124. data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
  125. data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
  126. data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
  127. data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
  128. data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
  129. data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
  130. data/gemfiles/Gemfile.minitest.2.11.0 +0 -7
  131. data/gemfiles/Gemfile.minitest.2.11.2 +0 -7
  132. data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
  133. data/gemfiles/Gemfile.test-unit.2.0.0 +0 -7
  134. data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
  135. data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
  136. data/lib/mocha/class_method.rb +0 -113
  137. data/lib/mocha/mini_test.rb +0 -5
  138. data/lib/mocha/module_method.rb +0 -6
  139. data/lib/mocha/module_methods.rb +0 -10
  140. data/lib/mocha/multiple_yields.rb +0 -15
  141. data/lib/mocha/no_yields.rb +0 -5
  142. data/lib/mocha/parameter_matchers/object.rb +0 -15
  143. data/lib/mocha/pretty_parameters.rb +0 -24
  144. data/lib/mocha/single_yield.rb +0 -13
  145. data/lib/mocha/standalone.rb +0 -4
  146. data/lib/mocha/unexpected_invocation.rb +0 -24
  147. data/lib/mocha_standalone.rb +0 -4
  148. data/test/acceptance/acceptance_test_helper.rb +0 -35
  149. data/test/acceptance/bug_18914_test.rb +0 -38
  150. data/test/acceptance/bug_21465_test.rb +0 -32
  151. data/test/acceptance/bug_21563_test.rb +0 -23
  152. data/test/acceptance/exception_rescue_test.rb +0 -54
  153. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -56
  154. data/test/acceptance/expected_invocation_count_test.rb +0 -230
  155. data/test/acceptance/failure_messages_test.rb +0 -62
  156. data/test/acceptance/issue_272_test.rb +0 -51
  157. data/test/acceptance/issue_65_test.rb +0 -65
  158. data/test/acceptance/issue_70_test.rb +0 -54
  159. data/test/acceptance/mocha_example_test.rb +0 -97
  160. data/test/acceptance/mocha_test_result_test.rb +0 -84
  161. data/test/acceptance/mock_test.rb +0 -98
  162. data/test/acceptance/mock_with_initializer_block_test.rb +0 -56
  163. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -76
  164. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -67
  165. data/test/acceptance/optional_parameters_test.rb +0 -68
  166. data/test/acceptance/parameter_matcher_test.rb +0 -300
  167. data/test/acceptance/partial_mocks_test.rb +0 -45
  168. data/test/acceptance/prepend_test.rb +0 -87
  169. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -77
  170. data/test/acceptance/raise_exception_test.rb +0 -37
  171. data/test/acceptance/return_value_test.rb +0 -50
  172. data/test/acceptance/sequence_test.rb +0 -190
  173. data/test/acceptance/states_test.rb +0 -72
  174. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -65
  175. data/test/acceptance/stub_any_instance_method_test.rb +0 -282
  176. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -106
  177. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -79
  178. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -74
  179. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -145
  180. data/test/acceptance/stub_everything_test.rb +0 -54
  181. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -92
  182. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -68
  183. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -68
  184. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -137
  185. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -77
  186. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -76
  187. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -68
  188. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -71
  189. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -39
  190. data/test/acceptance/stub_module_method_test.rb +0 -201
  191. data/test/acceptance/stub_test.rb +0 -50
  192. data/test/acceptance/stubba_example_test.rb +0 -94
  193. data/test/acceptance/stubba_test_result_test.rb +0 -72
  194. data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
  195. data/test/acceptance/stubbing_frozen_object_test.rb +0 -89
  196. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -53
  197. data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
  198. data/test/acceptance/stubbing_nil_test.rb +0 -60
  199. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -141
  200. data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
  201. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
  202. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
  203. data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
  204. data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
  205. data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
  206. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -34
  207. data/test/acceptance/throw_test.rb +0 -43
  208. data/test/acceptance/unexpected_invocation_test.rb +0 -24
  209. data/test/acceptance/unstubbing_test.rb +0 -195
  210. data/test/assertions.rb +0 -8
  211. data/test/deprecation_disabler.rb +0 -15
  212. data/test/execution_point.rb +0 -36
  213. data/test/integration/mini_test_test.rb +0 -8
  214. data/test/integration/shared_tests.rb +0 -176
  215. data/test/integration/test_unit_test.rb +0 -8
  216. data/test/method_definer.rb +0 -22
  217. data/test/mini_test_result.rb +0 -96
  218. data/test/minitest_result.rb +0 -48
  219. data/test/simple_counter.rb +0 -11
  220. data/test/test_helper.rb +0 -58
  221. data/test/test_runner.rb +0 -56
  222. data/test/test_unit_result.rb +0 -22
  223. data/test/unit/any_instance_method_test.rb +0 -150
  224. data/test/unit/array_inspect_test.rb +0 -14
  225. data/test/unit/backtrace_filter_test.rb +0 -17
  226. data/test/unit/cardinality_test.rb +0 -54
  227. data/test/unit/central_test.rb +0 -99
  228. data/test/unit/change_state_side_effect_test.rb +0 -37
  229. data/test/unit/class_method_test.rb +0 -254
  230. data/test/unit/class_methods_test.rb +0 -69
  231. data/test/unit/configuration_test.rb +0 -37
  232. data/test/unit/date_time_inspect_test.rb +0 -19
  233. data/test/unit/exception_raiser_test.rb +0 -40
  234. data/test/unit/expectation_list_test.rb +0 -80
  235. data/test/unit/expectation_test.rb +0 -492
  236. data/test/unit/hash_inspect_test.rb +0 -14
  237. data/test/unit/hooks_test.rb +0 -35
  238. data/test/unit/in_state_ordering_constraint_test.rb +0 -39
  239. data/test/unit/method_matcher_test.rb +0 -26
  240. data/test/unit/mock_test.rb +0 -363
  241. data/test/unit/mockery_test.rb +0 -174
  242. data/test/unit/module_methods_test.rb +0 -17
  243. data/test/unit/multiple_yields_test.rb +0 -16
  244. data/test/unit/no_yields_test.rb +0 -16
  245. data/test/unit/object_inspect_test.rb +0 -58
  246. data/test/unit/object_methods_test.rb +0 -62
  247. data/test/unit/parameter_matchers/all_of_test.rb +0 -24
  248. data/test/unit/parameter_matchers/any_of_test.rb +0 -24
  249. data/test/unit/parameter_matchers/anything_test.rb +0 -19
  250. data/test/unit/parameter_matchers/equals_test.rb +0 -23
  251. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -50
  252. data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
  253. data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
  254. data/test/unit/parameter_matchers/has_key_test.rb +0 -54
  255. data/test/unit/parameter_matchers/has_value_test.rb +0 -55
  256. data/test/unit/parameter_matchers/includes_test.rb +0 -106
  257. data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
  258. data/test/unit/parameter_matchers/is_a_test.rb +0 -23
  259. data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
  260. data/test/unit/parameter_matchers/not_test.rb +0 -24
  261. data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
  262. data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
  263. data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
  264. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
  265. data/test/unit/parameters_matcher_test.rb +0 -119
  266. data/test/unit/receivers_test.rb +0 -96
  267. data/test/unit/return_values_test.rb +0 -61
  268. data/test/unit/sequence_test.rb +0 -100
  269. data/test/unit/single_return_value_test.rb +0 -12
  270. data/test/unit/single_yield_test.rb +0 -16
  271. data/test/unit/state_machine_test.rb +0 -96
  272. data/test/unit/string_inspect_test.rb +0 -9
  273. data/test/unit/thrower_test.rb +0 -18
  274. data/test/unit/yield_parameters_test.rb +0 -91
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0c0293e3246e6c08b3091803488531187ef47253ec22fbcd0b48921e401aa9e
4
- data.tar.gz: 34c50006ebf871ed458dd97d2057caeeca9ae329a41da8d9abeb8e818a9f7042
3
+ metadata.gz: 77366bffa410729ac6089097db85ded323e74d1ec7bc6eb0ea13ae4a18b44eac
4
+ data.tar.gz: f9f3c89bbc29393e99ec62e0d1395ed4fa4863d0f790d24bbe6be3537450e4c1
5
5
  SHA512:
6
- metadata.gz: d3004d3ac125a41336d2138c35cf581cb05c51b96b7ecd895422715e84db62dca230ad96828c2a8c5f08b7ac0e00d0721aee20a8d17f6ef88b810c0b025bae3b
7
- data.tar.gz: 3dab739556bbab55d0ded0fb0f81368a7b17f3cc5a635e65a9b5c5e6c9a5b2700f0b4f1d15db887fd8b477d89b28f8147382a4403589de265a6c6e7335adc724
6
+ metadata.gz: 91e277be3c868ef2f6655016a53f040835b8e9d6390c789b6f047be72e9b96726865eefcb161b86d0f8e89ead1c58e9adbf1a1cbcdf9cba8a0f0b536de86222d
7
+ data.tar.gz: 4b7bf751e350762a5a3d9cd17fbe1a590ff5122a718417b75304fa86f8323b20652a24584cedabd859395aeef004402e57c70c15cd88746032659b0d9df4cccf
@@ -0,0 +1 @@
1
+ github: floehopper
data/.rubocop.yml CHANGED
@@ -8,6 +8,9 @@ AllCops:
8
8
  Style/Alias:
9
9
  EnforcedStyle: prefer_alias_method
10
10
 
11
+ Style/Documentation:
12
+ Enabled: false
13
+
11
14
  # Enumerable#each_with_object only available since Ruby v1.9
12
15
  Style/EachWithObject:
13
16
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,49 +1,26 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-07-26 12:42:35 +0100 using RuboCop version 0.58.2.
3
+ # on 2019-11-16 18:15:36 +0000 using RuboCop version 0.58.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 53
9
+ # Offense count: 57
10
10
  Metrics/AbcSize:
11
- Max: 39
11
+ Max: 26
12
12
 
13
- # Offense count: 2
14
- # Configuration parameters: CountComments, ExcludedMethods.
15
- # ExcludedMethods: refine
16
- Metrics/BlockLength:
17
- Max: 48
18
-
19
- # Offense count: 22
13
+ # Offense count: 23
20
14
  # Configuration parameters: CountComments.
21
15
  Metrics/ClassLength:
22
- Max: 368
23
-
24
- # Offense count: 4
25
- Metrics/CyclomaticComplexity:
26
- Max: 9
16
+ Max: 366
27
17
 
28
- # Offense count: 173
18
+ # Offense count: 172
29
19
  # Configuration parameters: CountComments.
30
20
  Metrics/MethodLength:
31
21
  Max: 31
32
22
 
33
- # Offense count: 1
34
- # Configuration parameters: CountComments.
35
- Metrics/ModuleLength:
36
- Max: 158
37
-
38
- # Offense count: 5
39
- Metrics/PerceivedComplexity:
40
- Max: 11
41
-
42
- # Offense count: 105
43
- Style/Documentation:
44
- Enabled: false
45
-
46
- # Offense count: 501
23
+ # Offense count: 545
47
24
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
48
25
  # URISchemes: http, https
49
26
  Metrics/LineLength:
data/.yardopts CHANGED
@@ -1,3 +1,4 @@
1
+ --output-dir docs
1
2
  --template-path yard-templates
2
3
  --no-private
3
4
  lib/mocha/api.rb
data/CONTRIBUTING.md CHANGED
@@ -3,5 +3,5 @@
3
3
  * Make your changes in a branch.
4
4
  * Add/modify/remove tests as appropriate.
5
5
  * Open a pull request based on a branch on your fork.
6
- * Wait for your pull request build to pass on [Travis CI](https://travis-ci.org/freerange/mocha/pull_requests).
6
+ * Wait for your pull request build to pass on [Circle CI](https://app.circleci.com/pipelines/github/freerange/mocha).
7
7
  * Pull requests with failing tests will not be accepted.
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
- ## Mocha [![Build Status](https://travis-ci.org/freerange/mocha.svg?branch=master)](https://travis-ci.org/freerange/mocha) [![Gem Version](https://badge.fury.io/rb/mocha.svg)](http://badge.fury.io/rb/mocha) [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=mocha&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=mocha&package-manager=bundler&version-scheme=semver)
2
-
1
+ ## Mocha [![CircleCI status of freerange/mocha](https://circleci.com/gh/freerange/mocha.svg?style=shield&circle-token=bc1f6576c77da43ec58badde9273fa4eb1d7f53a)](https://app.circleci.com/pipelines/github/freerange/mocha) [![Gem Version](https://badge.fury.io/rb/mocha.svg)](http://badge.fury.io/rb/mocha) [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=mocha&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=mocha&package-manager=bundler&version-scheme=semver)
3
2
 
4
3
  ### Description
5
4
 
6
- * A Ruby library for mocking and stubbing.
5
+ * A Ruby library for [mocking](http://xunitpatterns.com/Mock%20Object.html) and [stubbing](http://xunitpatterns.com/Test%20Stub.html) - but deliberately not (yet) [faking](http://xunitpatterns.com/Fake%20Object.html) or [spying](http://xunitpatterns.com/Test%20Spy.html).
7
6
  * A unified, simple and readable syntax for both full & partial mocking.
8
7
  * Built-in support for MiniTest and Test::Unit.
9
8
  * Supported by many other test frameworks.
10
9
 
10
+ ### Intended Usage
11
+ Mocha is intended to be used in unit tests for the [Mock Object](http://xunitpatterns.com/Mock%20Object.html) or [Test Stub](http://xunitpatterns.com/Test%20Stub.html) types of [Test Double](http://xunitpatterns.com/Test%20Double.html), not the [Fake Object](http://xunitpatterns.com/Fake%20Object.html) or [Test Spy](http://xunitpatterns.com/Test%20Spy.html) types. Although it would be possible to extend Mocha to allow the implementation of fakes and spies, we have chosen to keep it focused on mocks and stubs.
12
+
11
13
  ### Installation
12
14
 
13
15
  #### Gem
@@ -44,35 +46,21 @@ If you're using Bundler, include Mocha in the `Gemfile` and then setup Mocha lat
44
46
 
45
47
  ```ruby
46
48
  # Gemfile
47
- gem "mocha"
49
+ gem 'mocha'
48
50
 
49
51
  # Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
50
- require "test/unit"
51
- require "mocha/test_unit"
52
+ require 'test/unit'
53
+ require 'mocha/test_unit'
52
54
  ```
53
55
 
54
56
  ##### MiniTest
55
57
 
56
58
  ```ruby
57
59
  # Gemfile
58
- gem "mocha"
59
-
60
- # Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
61
- require "minitest/unit"
62
- require "mocha/minitest"
63
- ```
64
-
65
- #### Rails
66
-
67
- If you're loading Mocha using Bundler within a Rails application, you should setup Mocha manually e.g. at the bottom of your `test_helper.rb`.
68
-
69
- ##### MiniTest
70
-
71
- ```ruby
72
- # Gemfile in Rails app
73
60
  gem 'mocha'
74
61
 
75
- # At bottom of test_helper.rb (or at least after `require 'rails/test_help'`)
62
+ # Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
63
+ require 'minitest/unit'
76
64
  require 'mocha/minitest'
77
65
  ```
78
66
 
@@ -92,30 +80,54 @@ end
92
80
 
93
81
  Note: There is no need to use a require statement to setup Mocha; RSpec does this itself.
94
82
 
95
- #### Rails Plugin
83
+ ##### Cucumber
96
84
 
97
- Install the Rails plugin...
85
+ ```ruby
86
+ # In e.g. features/support/mocha.rb
87
+ require 'mocha/api'
88
+
89
+ World(Mocha::API)
90
+
91
+ Around do |scenario, block|
92
+ begin
93
+ mocha_setup
94
+ block.call
95
+ mocha_verify
96
+ ensure
97
+ mocha_teardown
98
+ end
99
+ end
100
+ ```
98
101
 
99
- $ rails plugin install git://github.com/freerange/mocha.git
102
+ #### Rails
100
103
 
101
- Note: As of version 0.9.8, the Mocha plugin is not automatically setup at plugin load time. Instead it must be manually setup e.g. at the bottom of your `test_helper.rb`.
104
+ If you're loading Mocha using Bundler within a Rails application, you should setup Mocha manually e.g. at the bottom of your `test_helper.rb`.
102
105
 
103
106
  ##### MiniTest
104
107
 
108
+ Note that since Rails v4 (at least), `ActiveSupport::TestCase` has inherited from `Minitest::Test` or its earlier equivalents. Thus unless you are *explicitly* using Test::Unit, you are likely to be using MiniTest.
109
+
105
110
  ```ruby
111
+ # Gemfile in Rails app
112
+ gem 'mocha'
113
+
106
114
  # At bottom of test_helper.rb (or at least after `require 'rails/test_help'`)
107
115
  require 'mocha/minitest'
108
116
  ```
109
117
 
118
+ ##### Other Test Framework
119
+
120
+ Follow the instructions for the relevant test framework in the [Bundler](#bundler) section, but ensure that the relevant Mocha file (`mocha/minitest`, `mocha/test_unit`, or `mocha/api`) is required **after** the test framework has been loaded, e.g. at the bottom of `test_helper.rb` or `spec_helper.rb`, or at least after `rails/test_help` has been required.
121
+
110
122
  #### Known Issues
111
123
 
124
+ * In Mocha v1.10.0 an undocumented feature of `API#mock`, `API#stub` & `API#stub_everything` was changed. Previously when these methods were passed a single symbol, they returned a mock object that responded to the method identified by the symbol. Now Passing a single symbol is equivalent to passing a single string, i.e. it now defines the 'name' of the mock object.
112
125
  * In Mocha v1.2.0 there is a scenario where stubbing a class method originally defined in a module hangs the Ruby interpreter due to [a bug in Ruby v2.3.1](https://bugs.ruby-lang.org/issues/12832). See #272. This was fixed in Mocha v1.2.1.
113
126
  * Since v1.1.0 Mocha has used prepended modules internally for stubbing methods. There is [an obscure Ruby bug](https://bugs.ruby-lang.org/issues/12876) in many (but not all) versions of Ruby between v2.0 & v2.3 which under certain circumstances may cause your Ruby interpreter to hang. See the Ruby bug report for more details. The bug has been fixed in Ruby v2.3.3 & v2.4.0.
114
127
  * Stubbing an aliased class method, where the original method is defined in a module that's used to `extend` the class doesn't work in Ruby 1.8.x. See stub_method_defined_on_module_and_aliased_test.rb for an example of this behaviour.
115
128
  * 0.13.x versions cause a harmless, but annoying, deprecation warning when used with Rails 3.2.0-3.2.12, 3.1.0-3.1.10 & 3.0.0-3.0.19.
116
129
  * 0.11.x versions don't work with Rails 3.2.13 (`TypeError: superclass mismatch for class ExpectationError`). See #115.
117
130
  * Versions 0.10.2, 0.10.3 & 0.11.0 of the Mocha gem were broken. Please do not use these versions.
118
- * Versions 0.9.6 & 0.9.7 of the Mocha Rails plugin were broken. Please do not use these versions.
119
131
 
120
132
  ### Usage
121
133
 
@@ -256,7 +268,15 @@ end
256
268
 
257
269
  ### Thread safety
258
270
 
259
- Mocha is currently *not* thread-safe. There are two main reasons for this: (a) in multi-threaded code Mocha exceptions may be raised in a thread other than the one which is running the test and thus a Mocha exception may not be correctly intercepted by Mocha exception handling code; and (b) partial mocking changes the state of objects in the `ObjectSpace` which is shared across all threads in the Ruby process and this access to what is effectively global state is not synchronized.
271
+ Mocha currently *does not* attempt to be thread-safe.
272
+
273
+ #### Can I test multi-threaded code with Mocha?
274
+
275
+ The short answer is no. In multi-threaded code Mocha exceptions may be raised in a thread other than the one which is running the test and thus a Mocha exception may not be correctly intercepted by Mocha exception handling code.
276
+
277
+ #### Can I run my tests across multiple threads?
278
+
279
+ Maybe, but probably not. Partial mocking changes the state of objects in the `ObjectSpace` which is shared across all threads in the Ruby process and this access to what is effectively global state is not synchronized. So, for example, if two tests are running concurrently and one uses `#any_instance` to modify a class, both tests will see those changes immediately.
260
280
 
261
281
  ### Expectation matching / invocation order
262
282
 
@@ -277,6 +297,11 @@ If you want, Mocha can generate a warning or raise an exception when:
277
297
 
278
298
  See the [documentation](https://mocha.jamesmead.org/Mocha/Configuration.html) for `Mocha::Configuration` for further details.
279
299
 
300
+ ##### MOCHA_OPTIONS
301
+ `MOCHA_OPTIONS` is an environment variable whose value can be set to a comma-separated list, so that we can specify multiple options e.g. `MOCHA_OPTIONS=debug,use_test_unit_gem`.
302
+ Only the following values are currently recognized and have an effect:
303
+ * `debug`: Enables a debug mode which will output backtraces for each deprecation warning. This is useful for finding where in the test suite the deprecated calls are.
304
+
280
305
  ### Useful Links
281
306
 
282
307
  * [Official Documentation](https://mocha.jamesmead.org)
@@ -298,16 +323,16 @@ See this [list of contributors](https://github.com/freerange/mocha/graphs/contri
298
323
  * Update the RELEASE.md file with a summary of changes
299
324
  * Bump the version in `lib/mocha/version.rb`
300
325
  * Commit & push to GitHub
301
- * Check Travis CI build is passing - https://travis-ci.org/freerange/mocha
326
+ * Check CircleCI build is passing - https://app.circleci.com/pipelines/github/freerange/mocha
302
327
 
303
328
  * Sign in to Google Analytics - https://analytics.google.com/analytics/web/
304
- * Find the web property ID for Go Free Range Ltd > Mocha Documentation (UA-45002715-2)
329
+ * Find the web property ID for floehopper (625523) > Mocha Documentation (UA-625523-7)
305
330
  * Generate documentation:
306
331
 
307
332
  ```bash
308
333
  $ MOCHA_GENERATE_DOCS=true bundle install
309
334
 
310
- $ MOCHA_GENERATE_DOCS=true GOOGLE_ANALYTICS_WEB_PROPERTY_ID=UA-45002715-2 rake generate_docs
335
+ $ MOCHA_GENERATE_DOCS=true GOOGLE_ANALYTICS_WEB_PROPERTY_ID=UA-625523-7 rake generate_docs
311
336
  ```
312
337
  * Commit documentation & push to GitHub
313
338
  * Sign in to rubygems.org and find API key - https://rubygems.org/profile/edit
data/RELEASE.md CHANGED
@@ -1,5 +1,171 @@
1
1
  # Release Notes
2
2
 
3
+ ## 1.13.0
4
+
5
+ ### External changes
6
+
7
+ * Add `ParameterMatchers#has_keys` - thanks to @cstyles for #512 (18d8104)
8
+ * Fix misleading exception message in `ParameterMatchers#has_entry` - thanks to @cstyles for #513 (9c4ef13)
9
+ * Only add dependency on rubocop if we're actually going to use it (f2f879f)
10
+ * Fix rake dependency constraints for older Ruby versions (7ce5f29)
11
+
12
+ ### Internal changes
13
+
14
+ * Check documentation can be generated as part of CircleCI build (b30d9a9)
15
+ * Add --fail-on-warning option to yard rake task (53a6ee3)
16
+ * Add a weekly scheduled build to the CircleCI build (fd2a4c6)
17
+ * Add Ruby v1.8 to the CircleCI build matrix (818ca03)
18
+ * Add API token to fix CircleCI badge in README (607c5aa)
19
+ * Provide wrapped option for #mocha_inspect on hashes & arrays (d8f44bc)
20
+ * Use CircleCI instead of TravisCI for automated builds (c98c6ec)
21
+ * Switch to newer default Travis CI build env (c78f75c)
22
+ * Use latest Ruby versions in Travis CI builds (9e0043a)
23
+ * Use latest JRuby v9.2.18 in Travis CI builds (8c99a1b)
24
+ * Use consistent JRuby versions in Travis CI builds (0f849aa)
25
+ * Use more recent version of JRuby in Travis CI build matrix (58653db)
26
+
27
+ ## 1.12.0
28
+
29
+ ### External changes
30
+
31
+ * Various improvements to README inspired by #207 and #390 - thanks to @nitishr for his work on #390 (fed0eee6)
32
+ * Improve documentation related to `StateMachine` classes - thanks to @nitishr (#425 & #427)
33
+ * Fix regression in cardinality introduced in v1.10.0 (59454a8) and reported in #473 - thanks to @srvance for reporting and @nitishr for fixing (#474)
34
+ * Fix documentation for `Mocha::Expectation#when` - thanks to @olleolleolle (b4f59daa & #477)
35
+ * Remove `Mocha::Mock#respond_to?` from documentation - thanks to @nitishr (#480)
36
+ * Improvements to documentation for `Expectation#yields` & `#multiple_yields` - thanks to @andyw8 for reporting in #495 (1b6571c)
37
+ * Remove documentation & tests from gem to reduce its size by over 50% - thanks to @gabetax (#500)
38
+ * Update documentation to point to travis-ci.com instead of travis-ci.org
39
+
40
+ ### Internal changes
41
+
42
+ * Refactor `StateMachine`-related classes - thanks to @nitishr (#425 & #427)
43
+ * Remove redundant test - thanks to @nitishr (8e4f1a7c)
44
+ * Add Ruby 2.7 to Travis CI matrix - thanks to @bastelfreak (fc5ea2f2)
45
+ * Simplify `Mockery` - thanks to @nitishr (#449)
46
+ * Update Travis CI badge to point to main vs master branch (bd8028f8)
47
+ * Generate docs using newer version of yard (v0.9.25) (c619afac)
48
+ * Manually upgrade jquery in docs from v1.7.1 -> v1.9.0 to fix CVE-2017-16011 (211098a5, dd5eeedb & 1b76e4d5; also see #492)
49
+ * Remove reference to non-existent jquery source map to fix error in Chrome developer tools (20156555)
50
+ * Temporarily ignore Ruby v1.8.7 build failures (e5b9feef)
51
+
52
+ ## 1.11.2
53
+
54
+ ### External changes
55
+
56
+ * Fix regression introduced in v1.10.0 that meant `Object#inspect` was called unnecessarily (368abd98)
57
+ * Warn when mock object receives invocations in another test - thanks to @nitishr (#442)
58
+ * Avoid rubocop comments appearing in YARD-generated docs (d8019eed)
59
+
60
+ ### Internal changes
61
+
62
+ * Replace `StubbedMethod#original_method` & `#original_visibility` attribute reader methods with instance variables - thanks to @nitishr (d917f332)
63
+ * Set up `MochaExampleTest` & `StubbaExampleTest` as acceptance tests - thanks to @nitishr (4881cc58)
64
+ * Delete unused `PrettyParameters` class - thanks to @nitishr (314ea922)
65
+
66
+ ## 1.11.1
67
+
68
+ ### External changes
69
+
70
+ * 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)
71
+
72
+ ## 1.11.0
73
+
74
+ ### External changes
75
+
76
+ * Add `Expectation#with_block_given` & `Expectation#with_no_block_given` (#441).
77
+ * Allows non-deprecated solution for #382. Thanks to @yemartin for reporting and to @techbelly & @nitishr for feedback.
78
+ * Fix issue with non-Array arguments passed to `Expectation#multiple_yields` (#444).
79
+ * The undocumented behaviour is now properly supported and documented.
80
+
81
+ ### Internal changes
82
+
83
+ * Move static YARD options from Rake task to `.yardopts` file - thanks to @nitishr (#429)
84
+ * Simplify implementation of yielding functionality - thanks to @nitishr (#439)
85
+ * Add missing require statement to `acceptance_test_helper.rb` (1070fc02)
86
+ * Add some baseline acceptance tests for yielding behaviour (c2cac911)
87
+ * Display a sponsor button on GitHub repo page (9fc5911b)
88
+ * Use new Deprecation.warning behaviour in `Invocation#call` (932d1166)
89
+
90
+ ## 1.10.2
91
+
92
+ * 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):
93
+ * The behaviour of `API#mock`, `API#stub` and `API#stub_everything` when called with a symbol as the first argument.
94
+ * The behaviour of `Expectation#yields` and `Expectation#multiple_yields` when the stubbed method is called without a block.
95
+
96
+ ## 1.10.1
97
+
98
+ * Ensure ObjectMethods & ClassMethods included when API extended (43778756)
99
+ * 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)
100
+
101
+ ## 1.10.0
102
+
103
+ * Improve deprecation warning when requiring 'mocha/setup' (388f44d7)
104
+ * Add documentation for Cucumber integration (13ab797b)
105
+ * Add documentation about an undocumented feature of `API#mock`, `API#stub` & `API#stub_everything` being changed (7ed2e4e7, d30c1717)
106
+
107
+ ## 1.10.0.beta.1
108
+
109
+ * Hide `ClassMethods#method_visibility` & `#method_exists?` methods to avoid clash with Rails (#428)
110
+
111
+ ## 1.10.0.alpha
112
+
113
+ ### External changes
114
+
115
+ * Remove dependency on metaclass gem (#49, #365)
116
+ * Accept symbol (as well as a string) as mock/stub name - thanks to @nitishr (#347, #353, #377)
117
+ * More realistic examples in documentation for `Expectation#yields` and `#multiple_yields` - thanks to @nitishr (#352, #383)
118
+ * Improve documentation for `Mock#responds_like` & `#responds_like_instance_of` - thanks to @nitishr (#337, #384)
119
+ * 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)
120
+ * Document `MOCHA_OPTIONS` in README - thanks to @nitishr (#311, #386)
121
+ * Add documentation to explain how Mocha is intended to be used - thanks to @nitishr (#330, #385)
122
+ * Deprecation warning if integration using 'mocha/test_unit' or 'mocha/minitest' fails - thanks to @nitishr (#229, #389, c6032d0b)
123
+ * Require at least one specified sequence for `Expectation#in_sequence` - thanks to @nitishr (#79, #396, 9020248a)
124
+ * Make signatures of `Mock#unstub` & `ObjectMethods#unstub` consistent - thanks to @nitishr (#397, f04d437)
125
+ * Deprecate requiring 'mocha/setup' (36adf880)
126
+ * Optionally display matching invocations alongside expectations - thanks to @nitishr (#178, #394, 00f0540, #410)
127
+ * Put deprecations into effect (#400, #418):
128
+ * Remove deprecated 'mocha_standalone.rb' & 'mocha/standalone.rb'
129
+ * Fail fast if no test library loaded
130
+ * Removed optional block for `Mocha::API#mock`, `#stub` & `#stub_everything`
131
+ * Remove deprecated `ParameterMatchers#has_equivalent_query_string` method
132
+ * Remove deprecated 'mocha/mini_test.rb'
133
+ * Fix typo in docs for `Mocha::Configuration.prevent` (266ce71c)
134
+ * New-style configuration (see documentation for `Mocha::Configuration`) (#407, #421)
135
+ * Deprecate support for Ruby versions earlier than v1.9 (#325, c5f8496d)
136
+ * Deprecate support for versions of test-unit & minitest which need monkey-patching (a34e1a88)
137
+ * Deprecate old-style Rails plugin (#403, 2df77134)
138
+ * Documentation fixes & improvements which also fix YARD warnings (472d5416, a2c0d64a)
139
+
140
+ ### Internal changes
141
+
142
+ * Pin minitest to v5.11.3 for Ruby v1.8.7 to fix build; minitest no longer supports Ruby v1.8.7 (4a0a580)
143
+ * Upgrade JRuby to v9.2.8.0 in Travis CI builds (aa29b3f)
144
+ * Only run rubocop for MRI Ruby versions & non-integration test builds (8f1c6af)
145
+ * Reduce duplication in any instance method class - thanks to @nitishr (#378)
146
+ * Simplify `AnyInstanceMethod`, `ClassMethod`, `InstanceMethod`, `ModuleMethod` class hierarchy - thanks to @nitishr (#381)
147
+ * Simplify `ClassMethods#method_exists?` & `ObjectMethods#method_exists?` making them consistent - thanks to @nitishr (#270, #362, #370)
148
+ * Don't override definition of `singleton_class` in `ClassMethods` - thanks to @nitishr (#391, #392)
149
+ * Do not include 'method_definer' methods into all objects (#268, #402)
150
+ * Distinguish different `ObjectMethods` modules (#268, #404)
151
+ * Pass invocation to expectation list methods - thanks to @nitishr (#408, #409, #411)
152
+ * Consistently use `assert_raises` - thanks to @nitishr (#405, #412, a66b7bed)
153
+ * Update Ruby & JRuby versions in Travis CI config (18cb1a93, eb061c53)
154
+ * Rubocop improvements (aa16ea67...6f4db70b, 2a1240e6...e95716ae)
155
+ * Fix inconsistency in CardinalityTest (aa10e0a8)
156
+ * Fix test failures on Mac OSX Catalina - thanks to @nitishr (#413, #417, #419, 8a0f2535)
157
+ * Remove default argument in `Expectation#invoke` - thanks to @nitishr (#414, #420)
158
+
159
+ ## 1.9.0
160
+
161
+ * Add TruffleRuby to Travis CI build matrix - thanks to @deepj (#354)
162
+ * Explicitly set Travis CI OS to Ubuntu Trusty 14.04 (ded1fa45)
163
+ * Expand explanation of thread-safety concerns - thanks to @techbelly (#357)
164
+ * Refactor class method and any instance method - thanks to @chrisroos (#358)
165
+ * Rely on default bundler version in Travis CI builds (3352e9c5)
166
+ * Fix local build-matrix script (11abe231)
167
+ * No need to install latest bundler in build-matrix script (8247a894)
168
+
3
169
  ## 1.8.0
4
170
 
5
171
  * Constrain rubocop version to avoid breaking Travis CI builds (05e507f5)
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ task 'test' do
17
17
  end
18
18
  end
19
19
 
20
- namespace 'test' do
20
+ namespace 'test' do # rubocop:disable Metrics/BlockLength
21
21
  unit_tests = FileList['test/unit/**/*_test.rb']
22
22
  all_acceptance_tests = FileList['test/acceptance/*_test.rb']
23
23
  ruby186_incompatible_acceptance_tests = FileList['test/acceptance/stub_class_method_defined_on_*_test.rb'] + FileList['test/acceptance/stub_instance_method_defined_on_*_test.rb']
@@ -85,13 +85,14 @@ end
85
85
 
86
86
  begin
87
87
  require 'rubocop/rake_task'
88
- if RUBY_VERSION >= '2.2.0'
88
+ if RUBY_VERSION >= '2.2.0' && (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby') && ENV['MOCHA_RUN_INTEGRATION_TESTS'].nil?
89
89
  RuboCop::RakeTask.new
90
90
  task 'test' => 'rubocop'
91
91
  end
92
92
  rescue LoadError # rubocop:disable Lint/HandleExceptions
93
93
  end
94
94
 
95
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
95
96
  def benchmark_test_case(klass, iterations)
96
97
  require 'benchmark'
97
98
  require 'mocha/detection/mini_test'
@@ -119,6 +120,7 @@ def benchmark_test_case(klass, iterations)
119
120
  Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, @silent_option) } }
120
121
  end
121
122
  end
123
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
122
124
 
123
125
  if ENV['MOCHA_GENERATE_DOCS']
124
126
  require 'yard'
@@ -136,14 +138,20 @@ if ENV['MOCHA_GENERATE_DOCS']
136
138
 
137
139
  desc 'Generate documentation'
138
140
  YARD::Rake::YardocTask.new('yardoc' => 'docs_environment') do |task|
139
- task.options = [
140
- '--title', "Mocha #{Mocha::VERSION}",
141
- '--output-dir', 'docs'
142
- ]
141
+ task.options = ['--title', "Mocha #{Mocha::VERSION}", '--fail-on-warning']
142
+ end
143
+
144
+ task 'checkout_docs_cname' do
145
+ `git checkout docs/CNAME`
146
+ end
147
+
148
+ task 'checkout_docs_js' do
149
+ `git checkout docs/js/app.js`
150
+ `git checkout docs/js/jquery.js`
143
151
  end
144
152
 
145
153
  desc 'Generate documentation'
146
- task 'generate_docs' => %w[clobber_yardoc yardoc]
154
+ task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname checkout_docs_js]
147
155
  end
148
156
 
149
157
  task 'release' => 'default'
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,66 +1,24 @@
1
1
  require 'mocha/ruby_version'
2
- require 'mocha/class_method'
2
+ require 'mocha/stubbed_method'
3
3
 
4
4
  module Mocha
5
- class AnyInstanceMethod < ClassMethod
6
- def mock
7
- stubbee.any_instance.mocha
8
- end
9
-
10
- def reset_mocha
11
- stubbee.any_instance.reset_mocha
12
- end
13
-
14
- def hide_original_method
15
- return unless (@original_visibility = method_visibility(method))
16
- begin
17
- if RUBY_V2_PLUS
18
- @definition_target = PrependedModule.new
19
- stubbee.__send__ :prepend, @definition_target
20
- else
21
- @original_method = stubbee.instance_method(method)
22
- if @original_method && @original_method.owner == stubbee
23
- stubbee.send(:remove_method, method)
24
- end
25
- end
26
- # rubocop:disable Lint/HandleExceptions
27
- rescue NameError
28
- # deal with nasties like ActiveRecord::Associations::AssociationProxy
29
- end
30
- # rubocop:enable Lint/HandleExceptions
31
- end
32
-
33
- def define_new_method
34
- definition_target.class_eval(<<-CODE, __FILE__, __LINE__ + 1)
35
- def #{method}(*args, &block)
36
- self.class.any_instance.mocha.method_missing(:#{method}, *args, &block)
37
- end
38
- CODE
39
- return unless @original_visibility
40
- Module.instance_method(@original_visibility).bind(definition_target).call(method)
41
- end
5
+ class AnyInstanceMethod < StubbedMethod
6
+ private
42
7
 
43
- def remove_new_method
44
- definition_target.send(:remove_method, method)
8
+ def mock_owner
9
+ stubbee.any_instance
45
10
  end
46
11
 
47
- def restore_original_method
48
- return if RUBY_V2_PLUS
49
- return unless @original_method && @original_method.owner == stubbee
50
- stubbee.send(:define_method, method, @original_method)
51
- Module.instance_method(@original_visibility).bind(stubbee).call(method)
12
+ def method_body(method)
13
+ method
52
14
  end
53
15
 
54
- def method_visibility(method)
55
- (stubbee.public_instance_methods(true).include?(method) && :public) ||
56
- (stubbee.protected_instance_methods(true).include?(method) && :protected) ||
57
- (stubbee.private_instance_methods(true).include?(method) && :private)
16
+ def stubbee_method(method_name)
17
+ stubbee.instance_method(method_name)
58
18
  end
59
19
 
60
- private
61
-
62
- def definition_target
63
- @definition_target ||= stubbee
20
+ def original_method_owner
21
+ stubbee
64
22
  end
65
23
  end
66
24
  end