mocha 1.11.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (262) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -1
  3. data/CONTRIBUTING.md +1 -1
  4. data/Gemfile +29 -0
  5. data/README.md +35 -31
  6. data/RELEASE.md +128 -0
  7. data/Rakefile +26 -22
  8. data/gemfiles/Gemfile.minitest.latest +1 -0
  9. data/gemfiles/Gemfile.test-unit.latest +2 -5
  10. data/lib/mocha/any_instance_method.rb +0 -5
  11. data/lib/mocha/api.rb +29 -78
  12. data/lib/mocha/cardinality.rb +30 -27
  13. data/lib/mocha/class_methods.rb +2 -2
  14. data/lib/mocha/configuration.rb +30 -108
  15. data/lib/mocha/expectation.rb +86 -31
  16. data/lib/mocha/inspect.rb +5 -3
  17. data/lib/mocha/instance_method.rb +0 -4
  18. data/lib/mocha/integration/mini_test.rb +10 -38
  19. data/lib/mocha/integration/test_unit/adapter.rb +1 -1
  20. data/lib/mocha/integration/test_unit.rb +10 -33
  21. data/lib/mocha/invocation.rb +12 -16
  22. data/lib/mocha/minitest.rb +2 -4
  23. data/lib/mocha/mock.rb +26 -26
  24. data/lib/mocha/mockery.rb +10 -25
  25. data/lib/mocha/parameter_matchers/base.rb +1 -1
  26. data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -1
  27. data/lib/mocha/parameter_matchers/has_entry.rb +22 -13
  28. data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
  29. data/lib/mocha/parameter_matchers/instance_methods.rb +10 -1
  30. data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +64 -0
  31. data/lib/mocha/parameter_matchers.rb +1 -0
  32. data/lib/mocha/parameters_matcher.rb +3 -3
  33. data/lib/mocha/ruby_version.rb +1 -2
  34. data/lib/mocha/state_machine.rb +30 -38
  35. data/lib/mocha/stubbed_method.rb +5 -42
  36. data/lib/mocha/test_unit.rb +2 -4
  37. data/lib/mocha/version.rb +1 -1
  38. data/lib/mocha.rb +0 -8
  39. data/mocha.gemspec +6 -31
  40. metadata +10 -286
  41. data/bin/build-matrix +0 -82
  42. data/docs/CNAME +0 -1
  43. data/docs/Mocha/API.html +0 -1285
  44. data/docs/Mocha/ClassMethods.html +0 -264
  45. data/docs/Mocha/Configuration.html +0 -1525
  46. data/docs/Mocha/Expectation.html +0 -2862
  47. data/docs/Mocha/ExpectationError.html +0 -152
  48. data/docs/Mocha/ExpectationErrorFactory.html +0 -260
  49. data/docs/Mocha/Hooks.html +0 -370
  50. data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -164
  51. data/docs/Mocha/Integration/MiniTest.html +0 -123
  52. data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -164
  53. data/docs/Mocha/Integration/TestUnit.html +0 -123
  54. data/docs/Mocha/Integration.html +0 -125
  55. data/docs/Mocha/Mock.html +0 -1210
  56. data/docs/Mocha/ObjectMethods.html +0 -765
  57. data/docs/Mocha/ParameterMatchers/AllOf.html +0 -153
  58. data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -153
  59. data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
  60. data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
  61. data/docs/Mocha/ParameterMatchers/Base.html +0 -441
  62. data/docs/Mocha/ParameterMatchers/Equals.html +0 -153
  63. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
  64. data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -153
  65. data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -153
  66. data/docs/Mocha/ParameterMatchers/HasKey.html +0 -153
  67. data/docs/Mocha/ParameterMatchers/HasValue.html +0 -153
  68. data/docs/Mocha/ParameterMatchers/Includes.html +0 -153
  69. data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -153
  70. data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
  71. data/docs/Mocha/ParameterMatchers/KindOf.html +0 -153
  72. data/docs/Mocha/ParameterMatchers/Not.html +0 -153
  73. data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
  74. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -153
  75. data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -153
  76. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -153
  77. data/docs/Mocha/ParameterMatchers.html +0 -2949
  78. data/docs/Mocha/Sequence.html +0 -149
  79. data/docs/Mocha/StateMachine/State.html +0 -140
  80. data/docs/Mocha/StateMachine/StatePredicate.html +0 -140
  81. data/docs/Mocha/StateMachine.html +0 -527
  82. data/docs/Mocha/StubbingError.html +0 -150
  83. data/docs/Mocha.html +0 -254
  84. data/docs/_index.html +0 -519
  85. data/docs/class_list.html +0 -51
  86. data/docs/css/common.css +0 -1
  87. data/docs/css/full_list.css +0 -58
  88. data/docs/css/style.css +0 -496
  89. data/docs/file.COPYING.html +0 -81
  90. data/docs/file.MIT-LICENSE.html +0 -85
  91. data/docs/file.README.html +0 -448
  92. data/docs/file.RELEASE.html +0 -1028
  93. data/docs/file_list.html +0 -71
  94. data/docs/frames.html +0 -17
  95. data/docs/index.html +0 -448
  96. data/docs/js/app.js +0 -303
  97. data/docs/js/full_list.js +0 -216
  98. data/docs/js/jquery.js +0 -4
  99. data/docs/method_list.html +0 -651
  100. data/docs/top-level-namespace.html +0 -118
  101. data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
  102. data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
  103. data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
  104. data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
  105. data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
  106. data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
  107. data/gemfiles/Gemfile.minitest.2.11.0 +0 -7
  108. data/gemfiles/Gemfile.minitest.2.11.2 +0 -7
  109. data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
  110. data/gemfiles/Gemfile.minitest.5.11.3 +0 -7
  111. data/gemfiles/Gemfile.test-unit.2.0.0 +0 -7
  112. data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
  113. data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
  114. data/init.rb +0 -1
  115. data/lib/mocha/integration/mini_test/nothing.rb +0 -19
  116. data/lib/mocha/integration/mini_test/version_13.rb +0 -54
  117. data/lib/mocha/integration/mini_test/version_140.rb +0 -54
  118. data/lib/mocha/integration/mini_test/version_141.rb +0 -65
  119. data/lib/mocha/integration/mini_test/version_142_to_172.rb +0 -65
  120. data/lib/mocha/integration/mini_test/version_200.rb +0 -66
  121. data/lib/mocha/integration/mini_test/version_201_to_222.rb +0 -66
  122. data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +0 -70
  123. data/lib/mocha/integration/mini_test/version_2112_to_320.rb +0 -73
  124. data/lib/mocha/integration/mini_test/version_230_to_2101.rb +0 -68
  125. data/lib/mocha/integration/test_unit/gem_version_200.rb +0 -62
  126. data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +0 -62
  127. data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +0 -62
  128. data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +0 -68
  129. data/lib/mocha/integration/test_unit/nothing.rb +0 -19
  130. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +0 -61
  131. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +0 -63
  132. data/lib/mocha/integration.rb +0 -11
  133. data/lib/mocha/setup.rb +0 -14
  134. data/lib/mocha/singleton_class.rb +0 -9
  135. data/test/acceptance/acceptance_test_helper.rb +0 -42
  136. data/test/acceptance/bug_18914_test.rb +0 -37
  137. data/test/acceptance/bug_21465_test.rb +0 -31
  138. data/test/acceptance/bug_21563_test.rb +0 -22
  139. data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +0 -69
  140. data/test/acceptance/exception_rescue_test.rb +0 -53
  141. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
  142. data/test/acceptance/expected_invocation_count_test.rb +0 -229
  143. data/test/acceptance/failure_messages_test.rb +0 -77
  144. data/test/acceptance/issue_272_test.rb +0 -50
  145. data/test/acceptance/issue_457_test.rb +0 -31
  146. data/test/acceptance/issue_65_test.rb +0 -64
  147. data/test/acceptance/issue_70_test.rb +0 -53
  148. data/test/acceptance/mocha_example_test.rb +0 -106
  149. data/test/acceptance/mocha_test_result_test.rb +0 -83
  150. data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -98
  151. data/test/acceptance/mock_test.rb +0 -191
  152. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
  153. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
  154. data/test/acceptance/multiple_yielding_test.rb +0 -59
  155. data/test/acceptance/optional_parameters_test.rb +0 -67
  156. data/test/acceptance/parameter_matcher_test.rb +0 -299
  157. data/test/acceptance/partial_mocks_test.rb +0 -44
  158. data/test/acceptance/prepend_test.rb +0 -86
  159. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -76
  160. data/test/acceptance/raise_exception_test.rb +0 -36
  161. data/test/acceptance/return_value_test.rb +0 -49
  162. data/test/acceptance/sequence_test.rb +0 -189
  163. data/test/acceptance/states_test.rb +0 -71
  164. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -64
  165. data/test/acceptance/stub_any_instance_method_test.rb +0 -301
  166. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -105
  167. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
  168. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -73
  169. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -144
  170. data/test/acceptance/stub_everything_test.rb +0 -53
  171. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -91
  172. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -67
  173. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -67
  174. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -136
  175. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -76
  176. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
  177. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -67
  178. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -70
  179. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -38
  180. data/test/acceptance/stub_module_method_test.rb +0 -200
  181. data/test/acceptance/stub_test.rb +0 -49
  182. data/test/acceptance/stubba_example_test.rb +0 -103
  183. data/test/acceptance/stubba_test_result_test.rb +0 -71
  184. data/test/acceptance/stubbing_error_backtrace_test.rb +0 -63
  185. data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
  186. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -52
  187. data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
  188. data/test/acceptance/stubbing_nil_test.rb +0 -60
  189. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -157
  190. data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
  191. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
  192. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
  193. data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
  194. data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
  195. data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
  196. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -33
  197. data/test/acceptance/throw_test.rb +0 -42
  198. data/test/acceptance/unexpected_invocation_test.rb +0 -23
  199. data/test/acceptance/unstubbing_test.rb +0 -194
  200. data/test/acceptance/yielding_test.rb +0 -80
  201. data/test/assertions.rb +0 -8
  202. data/test/deprecation_disabler.rb +0 -15
  203. data/test/execution_point.rb +0 -36
  204. data/test/integration/mini_test_test.rb +0 -8
  205. data/test/integration/shared_tests.rb +0 -178
  206. data/test/integration/test_unit_test.rb +0 -8
  207. data/test/method_definer.rb +0 -16
  208. data/test/mini_test_result.rb +0 -96
  209. data/test/minitest_result.rb +0 -48
  210. data/test/simple_counter.rb +0 -11
  211. data/test/test_helper.rb +0 -58
  212. data/test/test_runner.rb +0 -58
  213. data/test/test_unit_result.rb +0 -22
  214. data/test/unit/any_instance_method_test.rb +0 -175
  215. data/test/unit/array_inspect_test.rb +0 -14
  216. data/test/unit/backtrace_filter_test.rb +0 -17
  217. data/test/unit/cardinality_test.rb +0 -72
  218. data/test/unit/central_test.rb +0 -98
  219. data/test/unit/change_state_side_effect_test.rb +0 -37
  220. data/test/unit/class_methods_test.rb +0 -69
  221. data/test/unit/configuration_test.rb +0 -37
  222. data/test/unit/date_time_inspect_test.rb +0 -19
  223. data/test/unit/exception_raiser_test.rb +0 -45
  224. data/test/unit/expectation_list_test.rb +0 -82
  225. data/test/unit/expectation_test.rb +0 -504
  226. data/test/unit/hash_inspect_test.rb +0 -14
  227. data/test/unit/hooks_test.rb +0 -35
  228. data/test/unit/in_state_ordering_constraint_test.rb +0 -39
  229. data/test/unit/instance_method_test.rb +0 -282
  230. data/test/unit/method_matcher_test.rb +0 -26
  231. data/test/unit/mock_test.rb +0 -372
  232. data/test/unit/mockery_test.rb +0 -171
  233. data/test/unit/module_methods_test.rb +0 -16
  234. data/test/unit/object_inspect_test.rb +0 -60
  235. data/test/unit/object_methods_test.rb +0 -63
  236. data/test/unit/parameter_matchers/all_of_test.rb +0 -24
  237. data/test/unit/parameter_matchers/any_of_test.rb +0 -24
  238. data/test/unit/parameter_matchers/anything_test.rb +0 -19
  239. data/test/unit/parameter_matchers/equals_test.rb +0 -23
  240. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -41
  241. data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
  242. data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
  243. data/test/unit/parameter_matchers/has_key_test.rb +0 -54
  244. data/test/unit/parameter_matchers/has_value_test.rb +0 -55
  245. data/test/unit/parameter_matchers/includes_test.rb +0 -106
  246. data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
  247. data/test/unit/parameter_matchers/is_a_test.rb +0 -23
  248. data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
  249. data/test/unit/parameter_matchers/not_test.rb +0 -24
  250. data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
  251. data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
  252. data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
  253. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
  254. data/test/unit/parameters_matcher_test.rb +0 -119
  255. data/test/unit/receivers_test.rb +0 -96
  256. data/test/unit/return_values_test.rb +0 -66
  257. data/test/unit/sequence_test.rb +0 -100
  258. data/test/unit/single_return_value_test.rb +0 -17
  259. data/test/unit/state_machine_test.rb +0 -96
  260. data/test/unit/string_inspect_test.rb +0 -9
  261. data/test/unit/thrower_test.rb +0 -23
  262. data/test/unit/yield_parameters_test.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 398d43b17f224be63c21bcd24cbe4d1bff6b90267e1a870eb4f2a3432515da88
4
- data.tar.gz: bd7c4a5ce95a20b5b403750982d63356e1553af54f45d538cc3e3c514f7fb079
3
+ metadata.gz: 4f52376e6c8b1042085cca75e7d22e0241452dca80e73de22510f39a83041030
4
+ data.tar.gz: aa4584255d27f58ee1e9c18935921e352044ac8c2cc91d97221d280e21c54b29
5
5
  SHA512:
6
- metadata.gz: 0b8a00e3b21f5761fede57f919785ac653e714d28151325980d6ae5bd5d0a7ec5ecdcbaf96d6e36c6659347852e414b3a1c10fb57e0c72b981e70348308174f1
7
- data.tar.gz: f85f050cbbb7bfa224420e8ad2f67f6b683576a1d8ef1d79f55acecda495febca0f6b0aae79721c0159028f752c2e19268f06c5dc8e27f40dd5449e8ea5b96ae
6
+ metadata.gz: d23cc4f2cb0ffcf1464103c1bca607d8a2fac7fef3592dc4637d25ed72dbfd91f5d7234c9f4df23f1c27248829b6638013396e780212f41d9a44236b7a95bd16
7
+ data.tar.gz: efbcf261aab3292625c56f9f8cab796a19b4dc1ac474a64041ee1a6a92e72c4941b1ce0a0299322e682607d8e8c92598da7ffe853de1257cd92f49027b0891d4
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.2 # closest to required_ruby_version of '>= 1.8.6'
4
+ TargetRubyVersion: 2.2 # closest to required_ruby_version of '>= 2.0'
5
5
 
6
6
  # Even the reference in the documentation suggests that you should prefer
7
7
  # `alias_method` vs `alias`, so I don't understand why that isn't the default.
@@ -48,6 +48,10 @@ Style/WhileUntilModifier:
48
48
  Style/AccessModifierDeclarations:
49
49
  Enabled: false
50
50
 
51
+ # This is useful when using `ExecutionPoint.current` to make tests more robust
52
+ Style/Semicolon:
53
+ Enabled: false
54
+
51
55
  # Enabling this cop results in an "Infinite loop detected" exception
52
56
  Layout/AccessModifierIndentation:
53
57
  Enabled: false
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/Gemfile CHANGED
@@ -1,3 +1,32 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ # rubocop:disable Bundler/DuplicatedGem
6
+ if RUBY_VERSION < '2.2'
7
+ gem 'rake', '~> 12.3.3'
8
+ else
9
+ gem 'rake'
10
+ end
11
+ # rubocop:enable Bundler/DuplicatedGem
12
+
13
+ gem 'introspection', '~> 0.0.1'
14
+
15
+ # Avoid breaking change in psych v4 (https://bugs.ruby-lang.org/issues/17866)
16
+ if RUBY_VERSION >= '3.1.0'
17
+ gem 'psych', '< 4'
18
+ end
19
+
20
+ if RUBY_VERSION >= '2.2.0'
21
+ # No test libraries in standard library
22
+ gem 'minitest'
23
+ end
24
+ if RUBY_VERSION >= '2.2.0'
25
+ gem 'rubocop', '<= 0.58.2'
26
+ end
27
+ if ENV['MOCHA_GENERATE_DOCS']
28
+ gem 'redcarpet'
29
+ gem 'yard'
30
+ end
31
+
32
+ gem 'ruby2_keywords', '~> 0.0.5'
data/README.md CHANGED
@@ -1,5 +1,4 @@
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)
3
2
 
4
3
  ### Description
5
4
 
@@ -47,35 +46,21 @@ If you're using Bundler, include Mocha in the `Gemfile` and then setup Mocha lat
47
46
 
48
47
  ```ruby
49
48
  # Gemfile
50
- gem "mocha"
49
+ gem 'mocha'
51
50
 
52
51
  # Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
53
- require "test/unit"
54
- require "mocha/test_unit"
52
+ require 'test/unit'
53
+ require 'mocha/test_unit'
55
54
  ```
56
55
 
57
56
  ##### MiniTest
58
57
 
59
58
  ```ruby
60
59
  # Gemfile
61
- gem "mocha"
62
-
63
- # Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
64
- require "minitest/unit"
65
- require "mocha/minitest"
66
- ```
67
-
68
- #### Rails
69
-
70
- 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`.
71
-
72
- ##### MiniTest
73
-
74
- ```ruby
75
- # Gemfile in Rails app
76
60
  gem 'mocha'
77
61
 
78
- # 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'
79
64
  require 'mocha/minitest'
80
65
  ```
81
66
 
@@ -95,13 +80,6 @@ end
95
80
 
96
81
  Note: There is no need to use a require statement to setup Mocha; RSpec does this itself.
97
82
 
98
- ##### MiniTest
99
-
100
- ```ruby
101
- # At bottom of test_helper.rb (or at least after `require 'rails/test_help'`)
102
- require 'mocha/minitest'
103
- ```
104
-
105
83
  ##### Cucumber
106
84
 
107
85
  ```ruby
@@ -121,9 +99,29 @@ Around do |scenario, block|
121
99
  end
122
100
  ```
123
101
 
102
+ #### Rails
103
+
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`.
105
+
106
+ ##### MiniTest
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
+
110
+ ```ruby
111
+ # Gemfile in Rails app
112
+ gem 'mocha'
113
+
114
+ # At bottom of test_helper.rb (or at least after `require 'rails/test_help'`)
115
+ require 'mocha/minitest'
116
+ ```
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
+
124
122
  #### Known Issues
125
123
 
126
- * 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.
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.
127
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.
128
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.
129
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.
@@ -304,6 +302,12 @@ See the [documentation](https://mocha.jamesmead.org/Mocha/Configuration.html) fo
304
302
  Only the following values are currently recognized and have an effect:
305
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.
306
304
 
305
+ ### Semantic versioning
306
+
307
+ * Every effort is made to comply with [semantic versioning](https://semver.org/).
308
+ * However, this only applies to the behaviour documented in the public API.
309
+ * The documented public API does *not* include the content or format of messsages displayed to the user, e.g. assertion failure messages.
310
+
307
311
  ### Useful Links
308
312
 
309
313
  * [Official Documentation](https://mocha.jamesmead.org)
@@ -325,7 +329,7 @@ See this [list of contributors](https://github.com/freerange/mocha/graphs/contri
325
329
  * Update the RELEASE.md file with a summary of changes
326
330
  * Bump the version in `lib/mocha/version.rb`
327
331
  * Commit & push to GitHub
328
- * Check Travis CI build is passing - https://travis-ci.org/freerange/mocha
332
+ * Check CircleCI build is passing - https://app.circleci.com/pipelines/github/freerange/mocha
329
333
 
330
334
  * Sign in to Google Analytics - https://analytics.google.com/analytics/web/
331
335
  * Find the web property ID for floehopper (625523) > Mocha Documentation (UA-625523-7)
@@ -340,7 +344,7 @@ $ MOCHA_GENERATE_DOCS=true GOOGLE_ANALYTICS_WEB_PROPERTY_ID=UA-625523-7 rake gen
340
344
  * Sign in to rubygems.org and find API key - https://rubygems.org/profile/edit
341
345
 
342
346
  ```bash
343
- $ curl -u james@floehopper.org https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials`
347
+ $ curl -u <email-address> -H 'OTP:<one-time-password>' https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials
344
348
  ```
345
349
 
346
350
  * Release gem to Rubygems:
data/RELEASE.md CHANGED
@@ -1,5 +1,133 @@
1
1
  # Release Notes
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### External changes
6
+
7
+ * Remove support for Ruby v1.9 - thanks to @wasabigeek (#552)
8
+ * Support strict keyword argument matching - see docs for `Expectation#with` & `Configuration#strict_keyword_argument_matching=` - thanks to @wasabigeek (#446,#535,#544,#562)
9
+ * Deprecate `Hash` args that don't strictly match (#563,981c31be)
10
+ * Drop support for older versions of test-unit - gem versions of test-unit earlier than v2.5.1 and versions of test-unit
11
+ from the Ruby v1.8 standard library are no longer supported (#540,969f4845)
12
+ * Drop support for older versions of minitest - versions of minitest earlier than v3.3.0 are no longer supported (#541,ca69dc9e)
13
+ * Remove deprecated `mocha/setup.rb` mechanism (642a0ff4)
14
+ * Add missing docs for `API#stub` parameter (257b4cb4)
15
+ * Remove optional reinstatement of v1.9 behaviour (#436,#438,#569,1473ee25)
16
+ * Remove deprecated methods in `Configuration` (#421,e7ff7528)
17
+ * Fail fast when mock receives invocations in another test (#440,#442,cb054d59)
18
+ * Improve docs re using matchers in `Expectation#with` (da7237cd)
19
+ * Expand `Expectation#with` docs re keyword arguments (fed6808d)
20
+ * Improve docs for `strict_keyword_argument_matching` (8d8f881d)
21
+ * Remove deprecated Rails plugin `init.rb` file (1c617175)
22
+ * Improve strict keyword argument matching deprecation warning by including the source location of the stub definition (77c0d4cc)
23
+ * Add README section re semantic versioning (00758246)
24
+
25
+ ### Internal changes
26
+
27
+ * Separate linting from tests in terms of Rake tasks & CircleCI jobs - thanks to @wasabigeek (#556)
28
+ * Remove tests specific to Ruby v1.8 behaviour (46fca7ac, 3b369e99)
29
+ * Multi-line rubocop disable in `Mock#method_missing` (af2194c4)
30
+ * Remove unused arg for `HashMethods#mocha_inspect` (4f59e27f)
31
+ * Improve test runner assertions - failure vs error (eec7200a)
32
+ * Improve test coverage of `PositionalOrKeywordHash` (c294fe70)
33
+ * More consistent Test::Unit & Minitest integration (27dd3817)
34
+ * Remove redundant `require` statements (d82218a8,fa17b114)
35
+ * Add missing `require` statement (73493761)
36
+ * Disable Style/Semicolon cop globally (8cd0b705)
37
+
38
+ ## 1.16.0
39
+
40
+ ### External changes
41
+
42
+ * Default `Configuration#reinstate_undocumented_behaviour_from_v1_9=` to `false` (6fcaf947)
43
+ * Deprecate `Configuration#reinstate_undocumented_behaviour_from_v1_9=` (a797c5fd)
44
+
45
+ ### Internal changes
46
+
47
+ * Remove redundant deprecation disabling in MockTest (dc8ca969)
48
+
49
+ ## 1.15.0
50
+
51
+ ### External changes
52
+
53
+ * Fix examples using mock constructor with block (1cc17667)
54
+ * Add another example for `API#sequence` (b7a7d233, #59)
55
+ * Remove support for Ruby v1.8 (ddb5d672)
56
+ * Deprecate support for Ruby versions earlier than v2.0 - thanks to @wasabigeek (#553, #555)
57
+
58
+ ### Internal changes
59
+
60
+ * Update instructions for obtaining Rubygems API key (ed9c040a)
61
+ * Consistent definitions for `respond_to?` methods (#533)
62
+ * Run test tasks before release tasks (92a1bc6e, #447)
63
+ * Fix test:performance Rake task (#538, #539)
64
+ * Tidying following removal of support for Ruby v1.8 - thanks to @nitishr (#542)
65
+ * Remove `ParametersMatcher` from `Invocation#call_description` - thanks to @wasabigeek (#543)
66
+ * Remove unnecessary splatting in Invocation - thanks to @wasabigeek (#549)
67
+ * Extract `handle_method_call` from `method_missing` - thanks to @wasabigeek (#550)
68
+
69
+ ## 1.14.0
70
+
71
+ ### External changes
72
+
73
+ * Mock#expects,#stubs should return last expectation - thanks to @vlad-pisanov for #524 (b6b637db)
74
+
75
+ ### Internal changes
76
+
77
+ * Avoid breaking change in psych v4 in ruby v3.1 (08b9f4ca)
78
+ * Remove broken Dependabot badge from README (d446657a)
79
+ * Add Ruby 3.0 to the CI matrix - thanks to @mishina2228 for #526 (65bc626e)
80
+ * Move development dependencies from gemspec to Gemfile - thanks to @mishina2228 for #527 (dd127f7b)
81
+
82
+ ## 1.13.0
83
+
84
+ ### External changes
85
+
86
+ * Add `ParameterMatchers#has_keys` - thanks to @cstyles for #512 (18d8104)
87
+ * Fix misleading exception message in `ParameterMatchers#has_entry` - thanks to @cstyles for #513 (9c4ef13)
88
+ * Only add dependency on rubocop if we're actually going to use it (f2f879f)
89
+ * Fix rake dependency constraints for older Ruby versions (7ce5f29)
90
+
91
+ ### Internal changes
92
+
93
+ * Check documentation can be generated as part of CircleCI build (b30d9a9)
94
+ * Add --fail-on-warning option to yard rake task (53a6ee3)
95
+ * Add a weekly scheduled build to the CircleCI build (fd2a4c6)
96
+ * Add Ruby v1.8 to the CircleCI build matrix (818ca03)
97
+ * Add API token to fix CircleCI badge in README (607c5aa)
98
+ * Provide wrapped option for #mocha_inspect on hashes & arrays (d8f44bc)
99
+ * Use CircleCI instead of TravisCI for automated builds (c98c6ec)
100
+ * Switch to newer default Travis CI build env (c78f75c)
101
+ * Use latest Ruby versions in Travis CI builds (9e0043a)
102
+ * Use latest JRuby v9.2.18 in Travis CI builds (8c99a1b)
103
+ * Use consistent JRuby versions in Travis CI builds (0f849aa)
104
+ * Use more recent version of JRuby in Travis CI build matrix (58653db)
105
+
106
+ ## 1.12.0
107
+
108
+ ### External changes
109
+
110
+ * Various improvements to README inspired by #207 and #390 - thanks to @nitishr for his work on #390 (fed0eee6)
111
+ * Improve documentation related to `StateMachine` classes - thanks to @nitishr (#425 & #427)
112
+ * Fix regression in cardinality introduced in v1.10.0 (59454a8) and reported in #473 - thanks to @srvance for reporting and @nitishr for fixing (#474)
113
+ * Fix documentation for `Mocha::Expectation#when` - thanks to @olleolleolle (b4f59daa & #477)
114
+ * Remove `Mocha::Mock#respond_to?` from documentation - thanks to @nitishr (#480)
115
+ * Improvements to documentation for `Expectation#yields` & `#multiple_yields` - thanks to @andyw8 for reporting in #495 (1b6571c)
116
+ * Remove documentation & tests from gem to reduce its size by over 50% - thanks to @gabetax (#500)
117
+ * Update documentation to point to travis-ci.com instead of travis-ci.org
118
+
119
+ ### Internal changes
120
+
121
+ * Refactor `StateMachine`-related classes - thanks to @nitishr (#425 & #427)
122
+ * Remove redundant test - thanks to @nitishr (8e4f1a7c)
123
+ * Add Ruby 2.7 to Travis CI matrix - thanks to @bastelfreak (fc5ea2f2)
124
+ * Simplify `Mockery` - thanks to @nitishr (#449)
125
+ * Update Travis CI badge to point to main vs master branch (bd8028f8)
126
+ * Generate docs using newer version of yard (v0.9.25) (c619afac)
127
+ * Manually upgrade jquery in docs from v1.7.1 -> v1.9.0 to fix CVE-2017-16011 (211098a5, dd5eeedb & 1b76e4d5; also see #492)
128
+ * Remove reference to non-existent jquery source map to fix error in Chrome developer tools (20156555)
129
+ * Temporarily ignore Ruby v1.8.7 build failures (e5b9feef)
130
+
3
131
  ## 1.11.2
4
132
 
5
133
  ### External changes
data/Rakefile CHANGED
@@ -1,11 +1,18 @@
1
1
  require 'bundler'
2
- Bundler::GemHelper.install_tasks
2
+ namespace 'rubygems' do
3
+ Bundler::GemHelper.install_tasks
4
+ end
3
5
  require 'bundler/setup'
4
6
 
5
7
  require 'rake/testtask'
8
+ begin
9
+ # Only available with default Gemfile and in Ruby >= v2.2
10
+ require 'rubocop/rake_task'
11
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
12
+ end
6
13
 
7
- desc 'Run all tests'
8
- task 'default' => ['test', 'test:performance']
14
+ desc 'Run all linters and tests'
15
+ task 'default' => ['lint', 'test', 'test:performance']
9
16
 
10
17
  desc 'Run tests'
11
18
  task 'test' do
@@ -18,15 +25,10 @@ task 'test' do
18
25
  end
19
26
 
20
27
  namespace 'test' do # rubocop:disable Metrics/BlockLength
21
- unit_tests = FileList['test/unit/**/*_test.rb']
22
- all_acceptance_tests = FileList['test/acceptance/*_test.rb']
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']
24
- ruby186_compatible_acceptance_tests = all_acceptance_tests - ruby186_incompatible_acceptance_tests
25
-
26
28
  desc 'Run unit tests'
27
29
  Rake::TestTask.new('units') do |t|
28
30
  t.libs << 'test'
29
- t.test_files = unit_tests
31
+ t.test_files = FileList['test/unit/**/*_test.rb']
30
32
  t.verbose = true
31
33
  t.warning = true
32
34
  end
@@ -34,11 +36,7 @@ namespace 'test' do # rubocop:disable Metrics/BlockLength
34
36
  desc 'Run acceptance tests'
35
37
  Rake::TestTask.new('acceptance') do |t|
36
38
  t.libs << 'test'
37
- t.test_files = if defined?(RUBY_VERSION) && (RUBY_VERSION >= '1.8.7')
38
- all_acceptance_tests
39
- else
40
- ruby186_compatible_acceptance_tests
41
- end
39
+ t.test_files = FileList['test/acceptance/*_test.rb']
42
40
  t.verbose = true
43
41
  t.warning = true
44
42
  end
@@ -83,13 +81,13 @@ namespace 'test' do # rubocop:disable Metrics/BlockLength
83
81
  end
84
82
  end
85
83
 
86
- begin
87
- require 'rubocop/rake_task'
88
- if RUBY_VERSION >= '2.2.0' && (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby') && ENV['MOCHA_RUN_INTEGRATION_TESTS'].nil?
84
+ task 'lint' do
85
+ if defined?(RuboCop::RakeTask)
89
86
  RuboCop::RakeTask.new
90
- task 'test' => 'rubocop'
87
+ Rake::Task['rubocop'].invoke
88
+ else
89
+ puts 'RuboCop not available - skipping linting'
91
90
  end
92
- rescue LoadError # rubocop:disable Lint/HandleExceptions
93
91
  end
94
92
 
95
93
  # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
@@ -100,6 +98,7 @@ def benchmark_test_case(klass, iterations)
100
98
  if defined?(MiniTest)
101
99
  minitest_version = Gem::Version.new(Mocha::Detection::MiniTest.version)
102
100
  if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version)
101
+ Minitest.seed = 1
103
102
  result = Benchmark.realtime { iterations.times { |_i| klass.run(MiniTest::CompositeReporter.new) } }
104
103
  MiniTest::Runnable.runnables.delete(klass)
105
104
  result
@@ -138,15 +137,20 @@ if ENV['MOCHA_GENERATE_DOCS']
138
137
 
139
138
  desc 'Generate documentation'
140
139
  YARD::Rake::YardocTask.new('yardoc' => 'docs_environment') do |task|
141
- task.options = ['--title', "Mocha #{Mocha::VERSION}"]
140
+ task.options = ['--title', "Mocha #{Mocha::VERSION}", '--fail-on-warning']
142
141
  end
143
142
 
144
143
  task 'checkout_docs_cname' do
145
144
  `git checkout docs/CNAME`
146
145
  end
147
146
 
147
+ task 'checkout_docs_js' do
148
+ `git checkout docs/js/app.js`
149
+ `git checkout docs/js/jquery.js`
150
+ end
151
+
148
152
  desc 'Generate documentation'
149
- task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname]
153
+ task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname checkout_docs_js]
150
154
  end
151
155
 
152
- task 'release' => 'default'
156
+ 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
@@ -1,4 +1,3 @@
1
- require 'mocha/ruby_version'
2
1
  require 'mocha/stubbed_method'
3
2
 
4
3
  module Mocha
@@ -9,10 +8,6 @@ module Mocha
9
8
  stubbee.any_instance
10
9
  end
11
10
 
12
- def method_body(method)
13
- method
14
- end
15
-
16
11
  def stubbee_method(method_name)
17
12
  stubbee.instance_method(method_name)
18
13
  end
data/lib/mocha/api.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'mocha/ruby_version'
1
2
  require 'mocha/parameter_matchers'
2
3
  require 'mocha/hooks'
3
4
  require 'mocha/mockery'
@@ -51,7 +52,6 @@ module Mocha
51
52
  #
52
53
  # @overload def mock(name)
53
54
  # @param [String, Symbol] name identifies mock object in error messages.
54
- # @note Prior to v1.10.0 when +name+ was a +Symbol+, this method returned an unnamed +Mock+ that expected the method identified by +name+. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using {Configuration#reinstate_undocumented_behaviour_from_v1_9=}.
55
55
  # @overload def mock(expected_methods_vs_return_values = {})
56
56
  # @param [Hash] expected_methods_vs_return_values expected method name symbols as keys and corresponding return values as values - these expectations are setup as if {Mock#expects} were called multiple times.
57
57
  # @overload def mock(name, expected_methods_vs_return_values = {})
@@ -66,26 +66,8 @@ module Mocha
66
66
  # # an error will be raised unless both Motor#start and Motor#stop have been called
67
67
  # end
68
68
  #
69
- def mock(*arguments) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
70
- if Mocha.configuration.reinstate_undocumented_behaviour_from_v1_9?
71
- if arguments.first.is_a?(Symbol)
72
- method_name = arguments[0]
73
- Deprecation.warning(
74
- "Explicitly include `#{method_name}` in Hash of expected methods vs return values,",
75
- " e.g. `mock(:#{method_name} => nil)`."
76
- )
77
- if arguments[1]
78
- Deprecation.warning(
79
- "In this case the 2nd argument for `mock(:##{method_name}, ...)` is ignored,",
80
- ' but in the future a Hash of expected methods vs return values will be respected.'
81
- )
82
- end
83
- elsif arguments.first.is_a?(String)
84
- name = arguments.shift
85
- end
86
- elsif arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
87
- name = arguments.shift
88
- end
69
+ def mock(*arguments)
70
+ name = arguments.shift.to_s if arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
89
71
  expectations = arguments.shift || {}
90
72
  mock = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
91
73
  mock.expects(expectations)
@@ -98,11 +80,11 @@ module Mocha
98
80
  #
99
81
  # @overload def stub(name)
100
82
  # @param [String, Symbol] name identifies mock object in error messages.
101
- # @note Prior to v1.10.0 when +name+ was a +Symbol+, this method returned an unnamed +Mock+ that stubbed the method identified by +name+. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using {Configuration#reinstate_undocumented_behaviour_from_v1_9=}.
102
83
  # @overload def stub(stubbed_methods_vs_return_values = {})
103
84
  # @param [Hash] stubbed_methods_vs_return_values stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if {Mock#stubs} were called multiple times.
104
85
  # @overload def stub(name, stubbed_methods_vs_return_values = {})
105
86
  # @param [String, Symbol] name identifies mock object in error messages.
87
+ # @param [Hash] stubbed_methods_vs_return_values stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if {Mock#stubs} were called multiple times.
106
88
  #
107
89
  # @example Using stubbed_methods_vs_return_values Hash to setup stubbed methods.
108
90
  # def test_motor_starts_and_stops
@@ -111,33 +93,13 @@ module Mocha
111
93
  # assert motor.stop
112
94
  # # an error will not be raised even if either Motor#start or Motor#stop has not been called
113
95
  # end
114
- # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
115
96
  def stub(*arguments)
116
- if Mocha.configuration.reinstate_undocumented_behaviour_from_v1_9?
117
- if arguments.first.is_a?(Symbol)
118
- method_name = arguments[0]
119
- Deprecation.warning(
120
- "Explicitly include `#{method_name}` in Hash of stubbed methods vs return values,",
121
- " e.g. `stub(:#{method_name} => nil)`."
122
- )
123
- if arguments[1]
124
- Deprecation.warning(
125
- "In this case the 2nd argument for `stub(:##{method_name}, ...)` is ignored,",
126
- ' but in the future a Hash of stubbed methods vs return values will be respected.'
127
- )
128
- end
129
- elsif arguments.first.is_a?(String)
130
- name = arguments.shift
131
- end
132
- elsif arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
133
- name = arguments.shift
134
- end
97
+ name = arguments.shift.to_s if arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
135
98
  expectations = arguments.shift || {}
136
99
  stub = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
137
100
  stub.stubs(expectations)
138
101
  stub
139
102
  end
140
- # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
141
103
 
142
104
  # Builds a mock object that accepts calls to any method. By default it will return +nil+ for any method call.
143
105
  #
@@ -145,7 +107,6 @@ module Mocha
145
107
  #
146
108
  # @overload def stub_everything(name)
147
109
  # @param [String, Symbol] name identifies mock object in error messages.
148
- # @note Prior to v1.10.0 when +name+ was a +Symbol+, this method returned an unnamed +Mock+ that stubbed the method identified by +name+. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using {Configuration#reinstate_undocumented_behaviour_from_v1_9=}.
149
110
  # @overload def stub_everything(stubbed_methods_vs_return_values = {})
150
111
  # @param [Hash] stubbed_methods_vs_return_values stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if {Mock#stubs} were called multiple times.
151
112
  # @overload def stub_everything(name, stubbed_methods_vs_return_values = {})
@@ -159,34 +120,14 @@ module Mocha
159
120
  # assert_nil motor.irrelevant_method_2 # => no error raised
160
121
  # assert motor.stop
161
122
  # end
162
- # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
163
123
  def stub_everything(*arguments)
164
- if Mocha.configuration.reinstate_undocumented_behaviour_from_v1_9?
165
- if arguments.first.is_a?(Symbol)
166
- method_name = arguments[0]
167
- Deprecation.warning(
168
- "Explicitly include `#{method_name}` in Hash of stubbed methods vs return values,",
169
- " e.g. `stub_everything(:#{method_name} => nil)`."
170
- )
171
- if arguments[1]
172
- Deprecation.warning(
173
- "In this case the 2nd argument for `stub_everything(:##{method_name}, ...)` is ignored,",
174
- ' but in the future a Hash of stubbed methods vs return values will be respected.'
175
- )
176
- end
177
- elsif arguments.first.is_a?(String)
178
- name = arguments.shift
179
- end
180
- elsif arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
181
- name = arguments.shift
182
- end
124
+ name = arguments.shift if arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
183
125
  expectations = arguments.shift || {}
184
126
  stub = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
185
127
  stub.stub_everything
186
128
  stub.stubs(expectations)
187
129
  stub
188
130
  end
189
- # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
190
131
 
191
132
  # Builds a new sequence which can be used to constrain the order in which expectations can occur.
192
133
  #
@@ -199,11 +140,22 @@ module Mocha
199
140
  # @example Ensure methods on egg are invoked in correct order.
200
141
  # breakfast = sequence('breakfast')
201
142
  #
202
- # egg = mock('egg') do
203
- # expects(:crack).in_sequence(breakfast)
204
- # expects(:fry).in_sequence(breakfast)
205
- # expects(:eat).in_sequence(breakfast)
206
- # end
143
+ # egg = mock('egg')
144
+ # egg.expects(:crack).in_sequence(breakfast)
145
+ # egg.expects(:fry).in_sequence(breakfast)
146
+ # egg.expects(:eat).in_sequence(breakfast)
147
+ #
148
+ # @example Ensure methods across multiple objects are invoked in correct order.
149
+ # sequence = sequence(:task_order)
150
+ #
151
+ # task_one = mock("task_one")
152
+ # task_two = mock("task_two")
153
+ #
154
+ # task_one.expects(:execute).in_sequence(sequence)
155
+ # task_two.expects(:execute).in_sequence(sequence)
156
+ #
157
+ # task_one.execute
158
+ # task_two.execute
207
159
  def sequence(name)
208
160
  Sequence.new(name)
209
161
  end
@@ -226,14 +178,13 @@ module Mocha
226
178
  # @example Constrain expected invocations to occur in particular states.
227
179
  # power = states('power').starts_as('off')
228
180
  #
229
- # radio = mock('radio') do
230
- # expects(:switch_on).then(power.is('on'))
231
- # expects(:select_channel).with('BBC Radio 4').when(power.is('on'))
232
- # expects(:adjust_volume).with(+5).when(power.is('on'))
233
- # expects(:select_channel).with('BBC World Service').when(power.is('on'))
234
- # expects(:adjust_volume).with(-5).when(power.is('on'))
235
- # expects(:switch_off).then(power.is('off'))
236
- # end
181
+ # radio = mock('radio')
182
+ # radio.expects(:switch_on).then(power.is('on'))
183
+ # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on'))
184
+ # radio.expects(:adjust_volume).with(+5).when(power.is('on'))
185
+ # radio.expects(:select_channel).with('BBC World Service').when(power.is('on'))
186
+ # radio.expects(:adjust_volume).with(-5).when(power.is('on'))
187
+ # radio.expects(:switch_off).then(power.is('off'))
237
188
  def states(name)
238
189
  Mockery.instance.new_state_machine(name)
239
190
  end