mocha 1.10.1 → 1.12.0

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 (218) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.yardopts +1 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/README.md +28 -30
  6. data/RELEASE.md +69 -0
  7. data/Rakefile +7 -5
  8. data/lib/mocha/api.rb +78 -19
  9. data/lib/mocha/block_matcher.rb +31 -0
  10. data/lib/mocha/cardinality.rb +30 -27
  11. data/lib/mocha/configuration.rb +57 -1
  12. data/lib/mocha/deprecation.rb +2 -1
  13. data/lib/mocha/expectation.rb +72 -31
  14. data/lib/mocha/invocation.rb +20 -4
  15. data/lib/mocha/mock.rb +43 -17
  16. data/lib/mocha/mockery.rb +17 -27
  17. data/lib/mocha/parameter_matchers/has_entries.rb +2 -3
  18. data/lib/mocha/parameter_matchers/has_entry.rb +2 -3
  19. data/lib/mocha/parameter_matchers/has_key.rb +2 -3
  20. data/lib/mocha/parameter_matchers/has_value.rb +2 -3
  21. data/lib/mocha/parameter_matchers/is_a.rb +2 -3
  22. data/lib/mocha/parameter_matchers/not.rb +2 -3
  23. data/lib/mocha/state_machine.rb +31 -40
  24. data/lib/mocha/stubbed_method.rb +4 -6
  25. data/lib/mocha/version.rb +1 -1
  26. data/lib/mocha/yield_parameters.rb +5 -11
  27. data/mocha.gemspec +3 -1
  28. metadata +7 -195
  29. data/docs/CNAME +0 -1
  30. data/docs/Mocha.html +0 -254
  31. data/docs/Mocha/API.html +0 -1153
  32. data/docs/Mocha/ClassMethods.html +0 -264
  33. data/docs/Mocha/Configuration.html +0 -1383
  34. data/docs/Mocha/Expectation.html +0 -2654
  35. data/docs/Mocha/ExpectationError.html +0 -152
  36. data/docs/Mocha/ExpectationErrorFactory.html +0 -260
  37. data/docs/Mocha/Hooks.html +0 -370
  38. data/docs/Mocha/Integration.html +0 -125
  39. data/docs/Mocha/Integration/MiniTest.html +0 -123
  40. data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -164
  41. data/docs/Mocha/Integration/TestUnit.html +0 -123
  42. data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -164
  43. data/docs/Mocha/Mock.html +0 -1237
  44. data/docs/Mocha/ObjectMethods.html +0 -765
  45. data/docs/Mocha/ParameterMatchers.html +0 -2961
  46. data/docs/Mocha/ParameterMatchers/AllOf.html +0 -153
  47. data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -153
  48. data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
  49. data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
  50. data/docs/Mocha/ParameterMatchers/Base.html +0 -441
  51. data/docs/Mocha/ParameterMatchers/Equals.html +0 -153
  52. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
  53. data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -153
  54. data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -153
  55. data/docs/Mocha/ParameterMatchers/HasKey.html +0 -153
  56. data/docs/Mocha/ParameterMatchers/HasValue.html +0 -153
  57. data/docs/Mocha/ParameterMatchers/Includes.html +0 -153
  58. data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -153
  59. data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
  60. data/docs/Mocha/ParameterMatchers/KindOf.html +0 -153
  61. data/docs/Mocha/ParameterMatchers/Not.html +0 -153
  62. data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
  63. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -153
  64. data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -153
  65. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -153
  66. data/docs/Mocha/Sequence.html +0 -149
  67. data/docs/Mocha/StateMachine.html +0 -527
  68. data/docs/Mocha/StateMachine/State.html +0 -140
  69. data/docs/Mocha/StateMachine/StatePredicate.html +0 -140
  70. data/docs/Mocha/StubbingError.html +0 -150
  71. data/docs/_index.html +0 -519
  72. data/docs/class_list.html +0 -51
  73. data/docs/css/common.css +0 -1
  74. data/docs/css/full_list.css +0 -58
  75. data/docs/css/style.css +0 -496
  76. data/docs/file.COPYING.html +0 -81
  77. data/docs/file.MIT-LICENSE.html +0 -85
  78. data/docs/file.README.html +0 -448
  79. data/docs/file.RELEASE.html +0 -963
  80. data/docs/file_list.html +0 -71
  81. data/docs/frames.html +0 -17
  82. data/docs/index.html +0 -448
  83. data/docs/js/app.js +0 -303
  84. data/docs/js/full_list.js +0 -216
  85. data/docs/js/jquery.js +0 -4
  86. data/docs/method_list.html +0 -627
  87. data/docs/top-level-namespace.html +0 -118
  88. data/lib/mocha/multiple_yields.rb +0 -15
  89. data/lib/mocha/no_yields.rb +0 -5
  90. data/lib/mocha/pretty_parameters.rb +0 -24
  91. data/lib/mocha/single_yield.rb +0 -13
  92. data/test/acceptance/acceptance_test_helper.rb +0 -41
  93. data/test/acceptance/bug_18914_test.rb +0 -37
  94. data/test/acceptance/bug_21465_test.rb +0 -31
  95. data/test/acceptance/bug_21563_test.rb +0 -22
  96. data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +0 -69
  97. data/test/acceptance/exception_rescue_test.rb +0 -53
  98. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
  99. data/test/acceptance/expected_invocation_count_test.rb +0 -229
  100. data/test/acceptance/failure_messages_test.rb +0 -61
  101. data/test/acceptance/issue_272_test.rb +0 -50
  102. data/test/acceptance/issue_65_test.rb +0 -64
  103. data/test/acceptance/issue_70_test.rb +0 -53
  104. data/test/acceptance/mocha_example_test.rb +0 -96
  105. data/test/acceptance/mocha_test_result_test.rb +0 -83
  106. data/test/acceptance/mock_test.rb +0 -139
  107. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
  108. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
  109. data/test/acceptance/optional_parameters_test.rb +0 -67
  110. data/test/acceptance/parameter_matcher_test.rb +0 -299
  111. data/test/acceptance/partial_mocks_test.rb +0 -44
  112. data/test/acceptance/prepend_test.rb +0 -86
  113. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -76
  114. data/test/acceptance/raise_exception_test.rb +0 -36
  115. data/test/acceptance/return_value_test.rb +0 -49
  116. data/test/acceptance/sequence_test.rb +0 -189
  117. data/test/acceptance/states_test.rb +0 -71
  118. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -64
  119. data/test/acceptance/stub_any_instance_method_test.rb +0 -301
  120. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -105
  121. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
  122. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -73
  123. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -144
  124. data/test/acceptance/stub_everything_test.rb +0 -53
  125. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -91
  126. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -67
  127. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -67
  128. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -136
  129. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -76
  130. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
  131. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -67
  132. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -70
  133. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -38
  134. data/test/acceptance/stub_module_method_test.rb +0 -200
  135. data/test/acceptance/stub_test.rb +0 -49
  136. data/test/acceptance/stubba_example_test.rb +0 -93
  137. data/test/acceptance/stubba_test_result_test.rb +0 -71
  138. data/test/acceptance/stubbing_error_backtrace_test.rb +0 -63
  139. data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
  140. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -52
  141. data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
  142. data/test/acceptance/stubbing_nil_test.rb +0 -60
  143. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -157
  144. data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
  145. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
  146. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
  147. data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
  148. data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
  149. data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
  150. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -33
  151. data/test/acceptance/throw_test.rb +0 -42
  152. data/test/acceptance/unexpected_invocation_test.rb +0 -23
  153. data/test/acceptance/unstubbing_test.rb +0 -194
  154. data/test/assertions.rb +0 -8
  155. data/test/deprecation_disabler.rb +0 -15
  156. data/test/execution_point.rb +0 -36
  157. data/test/integration/mini_test_test.rb +0 -8
  158. data/test/integration/shared_tests.rb +0 -178
  159. data/test/integration/test_unit_test.rb +0 -8
  160. data/test/method_definer.rb +0 -16
  161. data/test/mini_test_result.rb +0 -96
  162. data/test/minitest_result.rb +0 -48
  163. data/test/simple_counter.rb +0 -11
  164. data/test/test_helper.rb +0 -58
  165. data/test/test_runner.rb +0 -58
  166. data/test/test_unit_result.rb +0 -22
  167. data/test/unit/any_instance_method_test.rb +0 -175
  168. data/test/unit/array_inspect_test.rb +0 -14
  169. data/test/unit/backtrace_filter_test.rb +0 -17
  170. data/test/unit/cardinality_test.rb +0 -72
  171. data/test/unit/central_test.rb +0 -98
  172. data/test/unit/change_state_side_effect_test.rb +0 -37
  173. data/test/unit/class_methods_test.rb +0 -69
  174. data/test/unit/configuration_test.rb +0 -37
  175. data/test/unit/date_time_inspect_test.rb +0 -19
  176. data/test/unit/exception_raiser_test.rb +0 -45
  177. data/test/unit/expectation_list_test.rb +0 -82
  178. data/test/unit/expectation_test.rb +0 -477
  179. data/test/unit/hash_inspect_test.rb +0 -14
  180. data/test/unit/hooks_test.rb +0 -35
  181. data/test/unit/in_state_ordering_constraint_test.rb +0 -39
  182. data/test/unit/instance_method_test.rb +0 -282
  183. data/test/unit/method_matcher_test.rb +0 -26
  184. data/test/unit/mock_test.rb +0 -372
  185. data/test/unit/mockery_test.rb +0 -171
  186. data/test/unit/module_methods_test.rb +0 -16
  187. data/test/unit/multiple_yields_test.rb +0 -16
  188. data/test/unit/no_yields_test.rb +0 -16
  189. data/test/unit/object_inspect_test.rb +0 -60
  190. data/test/unit/object_methods_test.rb +0 -63
  191. data/test/unit/parameter_matchers/all_of_test.rb +0 -24
  192. data/test/unit/parameter_matchers/any_of_test.rb +0 -24
  193. data/test/unit/parameter_matchers/anything_test.rb +0 -19
  194. data/test/unit/parameter_matchers/equals_test.rb +0 -23
  195. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -41
  196. data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
  197. data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
  198. data/test/unit/parameter_matchers/has_key_test.rb +0 -54
  199. data/test/unit/parameter_matchers/has_value_test.rb +0 -55
  200. data/test/unit/parameter_matchers/includes_test.rb +0 -106
  201. data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
  202. data/test/unit/parameter_matchers/is_a_test.rb +0 -23
  203. data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
  204. data/test/unit/parameter_matchers/not_test.rb +0 -24
  205. data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
  206. data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
  207. data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
  208. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
  209. data/test/unit/parameters_matcher_test.rb +0 -119
  210. data/test/unit/receivers_test.rb +0 -96
  211. data/test/unit/return_values_test.rb +0 -66
  212. data/test/unit/sequence_test.rb +0 -100
  213. data/test/unit/single_return_value_test.rb +0 -17
  214. data/test/unit/single_yield_test.rb +0 -16
  215. data/test/unit/state_machine_test.rb +0 -96
  216. data/test/unit/string_inspect_test.rb +0 -9
  217. data/test/unit/thrower_test.rb +0 -23
  218. data/test/unit/yield_parameters_test.rb +0 -91
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37552b852159a54683d4acb532daa97dd5b4db6ba031399e07056d438b034717
4
- data.tar.gz: 86be70d9b97b96f30bda6122a056f79a6a93e9a5e7e657fda8df3ce60f5e55ac
3
+ metadata.gz: 3182f55b0e553eb0559fee7df5f5fd71f824e219480715de2f35e7bfacb5d9b2
4
+ data.tar.gz: 485677b5a3628ccee3730274697f27defb4fc087cc838d7c4ec8dac4e3cd589d
5
5
  SHA512:
6
- metadata.gz: 7d0dded9eac7033c2fdefeeca1045bc6616c2c3a6f4376b83adc43fdae7af5b2771b8a395570e6417cc3ae431de01fca6253a477be29aac86d2607cc37395744
7
- data.tar.gz: 44dd01735f61991c56031d85dd06c2f561ae518050daa17865714c25cdab70cfcc45a95b14220c8cb53656d2cc67c5b04660cbb7d47091bbd8b53a00e05c5093
6
+ metadata.gz: 1f782e0791e221f18081e35a298a039b96afd7a06caf4177a3d117e3803ee2165d9cd5dd6c19edde9334fda7dea973c105a5c3fe7070810dd0e7229901df056f
7
+ data.tar.gz: 8adf5cf18b21d7039c7c8f10b4c7a49ba4a215d9351cdd89a04d7a4371eda9863727b08e5bdbb240d92dd6cc93555306b13501370ecdadd4b6a74368213851c5
@@ -0,0 +1 @@
1
+ github: floehopper
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
@@ -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 [Travis CI](https://travis-ci.com/github/freerange/mocha/pull_requests).
7
7
  * Pull requests with failing tests will not be accepted.
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 [![Build Status](https://travis-ci.com/freerange/mocha.svg?branch=main)](https://travis-ci.com/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
 
@@ -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.
@@ -325,7 +323,7 @@ See this [list of contributors](https://github.com/freerange/mocha/graphs/contri
325
323
  * Update the RELEASE.md file with a summary of changes
326
324
  * Bump the version in `lib/mocha/version.rb`
327
325
  * Commit & push to GitHub
328
- * Check Travis CI build is passing - https://travis-ci.org/freerange/mocha
326
+ * Check Travis CI build is passing - https://travis-ci.com/github/freerange/mocha
329
327
 
330
328
  * Sign in to Google Analytics - https://analytics.google.com/analytics/web/
331
329
  * Find the web property ID for floehopper (625523) > Mocha Documentation (UA-625523-7)
data/RELEASE.md CHANGED
@@ -1,5 +1,74 @@
1
1
  # Release Notes
2
2
 
3
+ ## 1.12.0
4
+
5
+ ### External changes
6
+
7
+ * Various improvements to README inspired by #207 and #390 - thanks to @nitishr for his work on #390 (fed0eee6)
8
+ * Improve documentation related to `StateMachine` classes - thanks to @nitishr (#425 & #427)
9
+ * Fix regression in cardinality introduced in v1.10.0 (59454a8) and reported in #473 - thanks to @srvance for reporting and @nitishr for fixing (#474)
10
+ * Fix documentation for `Mocha::Expectation#when` - thanks to @olleolleolle (b4f59daa & #477)
11
+ * Remove `Mocha::Mock#respond_to?` from documentation - thanks to @nitishr (#480)
12
+ * Improvements to documentation for `Expectation#yields` & `#multiple_yields` - thanks to @andyw8 for reporting in #495 (1b6571c)
13
+ * Remove documentation & tests from gem to reduce its size by over 50% - thanks to @gabetax (#500)
14
+ * Update documentation to point to travis-ci.com instead of travis-ci.org
15
+
16
+ ### Internal changes
17
+
18
+ * Refactor `StateMachine`-related classes - thanks to @nitishr (#425 & #427)
19
+ * Remove redundant test - thanks to @nitishr (8e4f1a7c)
20
+ * Add Ruby 2.7 to Travis CI matrix - thanks to @bastelfreak (fc5ea2f2)
21
+ * Simplify `Mockery` - thanks to @nitishr (#449)
22
+ * Update Travis CI badge to point to main vs master branch (bd8028f8)
23
+ * Generate docs using newer version of yard (v0.9.25) (c619afac)
24
+ * Manually upgrade jquery in docs from v1.7.1 -> v1.9.0 to fix CVE-2017-16011 (211098a5, dd5eeedb & 1b76e4d5; also see #492)
25
+ * Remove reference to non-existent jquery source map to fix error in Chrome developer tools (20156555)
26
+ * Temporarily ignore Ruby v1.8.7 build failures (e5b9feef)
27
+
28
+ ## 1.11.2
29
+
30
+ ### External changes
31
+
32
+ * Fix regression introduced in v1.10.0 that meant `Object#inspect` was called unnecessarily (368abd98)
33
+ * Warn when mock object receives invocations in another test - thanks to @nitishr (#442)
34
+ * Avoid rubocop comments appearing in YARD-generated docs (d8019eed)
35
+
36
+ ### Internal changes
37
+
38
+ * Replace `StubbedMethod#original_method` & `#original_visibility` attribute reader methods with instance variables - thanks to @nitishr (d917f332)
39
+ * Set up `MochaExampleTest` & `StubbaExampleTest` as acceptance tests - thanks to @nitishr (4881cc58)
40
+ * Delete unused `PrettyParameters` class - thanks to @nitishr (314ea922)
41
+
42
+ ## 1.11.1
43
+
44
+ ### External changes
45
+
46
+ * 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)
47
+
48
+ ## 1.11.0
49
+
50
+ ### External changes
51
+
52
+ * Add `Expectation#with_block_given` & `Expectation#with_no_block_given` (#441).
53
+ * Allows non-deprecated solution for #382. Thanks to @yemartin for reporting and to @techbelly & @nitishr for feedback.
54
+ * Fix issue with non-Array arguments passed to `Expectation#multiple_yields` (#444).
55
+ * The undocumented behaviour is now properly supported and documented.
56
+
57
+ ### Internal changes
58
+
59
+ * Move static YARD options from Rake task to `.yardopts` file - thanks to @nitishr (#429)
60
+ * Simplify implementation of yielding functionality - thanks to @nitishr (#439)
61
+ * Add missing require statement to `acceptance_test_helper.rb` (1070fc02)
62
+ * Add some baseline acceptance tests for yielding behaviour (c2cac911)
63
+ * Display a sponsor button on GitHub repo page (9fc5911b)
64
+ * Use new Deprecation.warning behaviour in `Invocation#call` (932d1166)
65
+
66
+ ## 1.10.2
67
+
68
+ * 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):
69
+ * The behaviour of `API#mock`, `API#stub` and `API#stub_everything` when called with a symbol as the first argument.
70
+ * The behaviour of `Expectation#yields` and `Expectation#multiple_yields` when the stubbed method is called without a block.
71
+
3
72
  ## 1.10.1
4
73
 
5
74
  * Ensure ObjectMethods & ClassMethods included when API extended (43778756)
data/Rakefile CHANGED
@@ -138,18 +138,20 @@ if ENV['MOCHA_GENERATE_DOCS']
138
138
 
139
139
  desc 'Generate documentation'
140
140
  YARD::Rake::YardocTask.new('yardoc' => 'docs_environment') do |task|
141
- task.options = [
142
- '--title', "Mocha #{Mocha::VERSION}",
143
- '--output-dir', 'docs'
144
- ]
141
+ task.options = ['--title', "Mocha #{Mocha::VERSION}"]
145
142
  end
146
143
 
147
144
  task 'checkout_docs_cname' do
148
145
  `git checkout docs/CNAME`
149
146
  end
150
147
 
148
+ task 'checkout_docs_js' do
149
+ `git checkout docs/js/app.js`
150
+ `git checkout docs/js/jquery.js`
151
+ end
152
+
151
153
  desc 'Generate documentation'
152
- task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname]
154
+ task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname checkout_docs_js]
153
155
  end
154
156
 
155
157
  task 'release' => 'default'
@@ -51,7 +51,7 @@ module Mocha
51
51
  #
52
52
  # @overload def mock(name)
53
53
  # @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 stubbed the method identified by +name+. This was undocumented behaviour and it no longer exists.
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 = {})
@@ -65,8 +65,31 @@ module Mocha
65
65
  # assert motor.stop
66
66
  # # an error will be raised unless both Motor#start and Motor#stop have been called
67
67
  # end
68
- def mock(*arguments)
69
- create_mock(arguments) { |mock, expectations| mock.expects(expectations) }
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
89
+ expectations = arguments.shift || {}
90
+ mock = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
91
+ mock.expects(expectations)
92
+ mock
70
93
  end
71
94
 
72
95
  # Builds a new mock object
@@ -75,7 +98,7 @@ module Mocha
75
98
  #
76
99
  # @overload def stub(name)
77
100
  # @param [String, Symbol] name identifies mock object in error messages.
78
- # @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 no longer exists.
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=}.
79
102
  # @overload def stub(stubbed_methods_vs_return_values = {})
80
103
  # @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.
81
104
  # @overload def stub(name, stubbed_methods_vs_return_values = {})
@@ -88,9 +111,33 @@ module Mocha
88
111
  # assert motor.stop
89
112
  # # an error will not be raised even if either Motor#start or Motor#stop has not been called
90
113
  # end
114
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
91
115
  def stub(*arguments)
92
- create_mock(arguments) { |stub, expectations| stub.stubs(expectations) }
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
135
+ expectations = arguments.shift || {}
136
+ stub = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
137
+ stub.stubs(expectations)
138
+ stub
93
139
  end
140
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
94
141
 
95
142
  # Builds a mock object that accepts calls to any method. By default it will return +nil+ for any method call.
96
143
  #
@@ -98,7 +145,7 @@ module Mocha
98
145
  #
99
146
  # @overload def stub_everything(name)
100
147
  # @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 everything. This was undocumented behaviour and it no longer exists.
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=}.
102
149
  # @overload def stub_everything(stubbed_methods_vs_return_values = {})
103
150
  # @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
151
  # @overload def stub_everything(name, stubbed_methods_vs_return_values = {})
@@ -112,12 +159,34 @@ module Mocha
112
159
  # assert_nil motor.irrelevant_method_2 # => no error raised
113
160
  # assert motor.stop
114
161
  # end
162
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
115
163
  def stub_everything(*arguments)
116
- create_mock(arguments) do |stub, expectations|
117
- stub.stub_everything
118
- stub.stubs(expectations)
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
119
182
  end
183
+ expectations = arguments.shift || {}
184
+ stub = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
185
+ stub.stub_everything
186
+ stub.stubs(expectations)
187
+ stub
120
188
  end
189
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
121
190
 
122
191
  # Builds a new sequence which can be used to constrain the order in which expectations can occur.
123
192
  #
@@ -168,15 +237,5 @@ module Mocha
168
237
  def states(name)
169
238
  Mockery.instance.new_state_machine(name)
170
239
  end
171
-
172
- private
173
-
174
- def create_mock(arguments)
175
- name = arguments.shift.to_s if arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
176
- expectations = arguments.shift || {}
177
- mock = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
178
- yield mock, expectations
179
- mock
180
- end
181
240
  end
182
241
  end
@@ -0,0 +1,31 @@
1
+ module Mocha
2
+ module BlockMatchers
3
+ class OptionalBlock
4
+ def match?(_actual_block)
5
+ true
6
+ end
7
+
8
+ def mocha_inspect; end
9
+ end
10
+
11
+ class BlockGiven
12
+ def match?(actual_block)
13
+ !actual_block.nil?
14
+ end
15
+
16
+ def mocha_inspect
17
+ 'with block given'
18
+ end
19
+ end
20
+
21
+ class NoBlockGiven
22
+ def match?(actual_block)
23
+ actual_block.nil?
24
+ end
25
+
26
+ def mocha_inspect
27
+ 'with no block given'
28
+ end
29
+ end
30
+ end
31
+ end
@@ -2,31 +2,28 @@ module Mocha
2
2
  class Cardinality
3
3
  INFINITY = 1 / 0.0
4
4
 
5
- class << self
6
- def exactly(count)
7
- new(count, count)
8
- end
5
+ def initialize(required = 0, maximum = INFINITY)
6
+ update(required, maximum)
7
+ @invocations = []
8
+ end
9
9
 
10
- def at_least(count)
11
- new(count, INFINITY)
12
- end
10
+ def exactly(count)
11
+ update(count, count)
12
+ end
13
13
 
14
- def at_most(count)
15
- new(0, count)
16
- end
14
+ def at_least(count)
15
+ update(count, INFINITY)
16
+ end
17
17
 
18
- def times(range_or_count)
19
- case range_or_count
20
- when Range then new(range_or_count.first, range_or_count.last)
21
- else new(range_or_count, range_or_count)
22
- end
23
- end
18
+ def at_most(count)
19
+ update(0, count)
24
20
  end
25
21
 
26
- def initialize(required, maximum)
27
- @required = required
28
- @maximum = maximum
29
- @invocations = []
22
+ def times(range_or_count)
23
+ case range_or_count
24
+ when Range then update(range_or_count.first, range_or_count.last)
25
+ else update(range_or_count, range_or_count)
26
+ end
30
27
  end
31
28
 
32
29
  def <<(invocation)
@@ -62,21 +59,21 @@ module Mocha
62
59
  if allowed_any_number_of_times?
63
60
  'allowed any number of times'
64
61
  elsif required.zero? && maximum.zero?
65
- "expected #{times(maximum)}"
62
+ "expected #{count(maximum)}"
66
63
  elsif required == maximum
67
- "expected exactly #{times(required)}"
64
+ "expected exactly #{count(required)}"
68
65
  elsif infinite?(maximum)
69
- "expected at least #{times(required)}"
66
+ "expected at least #{count(required)}"
70
67
  elsif required.zero?
71
- "expected at most #{times(maximum)}"
68
+ "expected at most #{count(maximum)}"
72
69
  else
73
- "expected between #{required} and #{times(maximum)}"
70
+ "expected between #{required} and #{count(maximum)}"
74
71
  end
75
72
  end
76
73
  # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
77
74
 
78
75
  def invoked_times
79
- "invoked #{times(@invocations.size)}"
76
+ "invoked #{count(@invocations.size)}"
80
77
  end
81
78
 
82
79
  def actual_invocations
@@ -87,7 +84,7 @@ module Mocha
87
84
 
88
85
  attr_reader :required, :maximum
89
86
 
90
- def times(number)
87
+ def count(number)
91
88
  case number
92
89
  when 0 then 'never'
93
90
  when 1 then 'once'
@@ -96,6 +93,12 @@ module Mocha
96
93
  end
97
94
  end
98
95
 
96
+ def update(required, maximum)
97
+ @required = required
98
+ @maximum = maximum
99
+ self
100
+ end
101
+
99
102
  def infinite?(number)
100
103
  number.respond_to?(:infinite?) && number.infinite?
101
104
  end