mocha 1.11.2 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -1
  3. data/README.md +28 -30
  4. data/RELEASE.md +25 -0
  5. data/Rakefile +6 -1
  6. data/lib/mocha/cardinality.rb +30 -27
  7. data/lib/mocha/expectation.rb +24 -24
  8. data/lib/mocha/mock.rb +1 -1
  9. data/lib/mocha/mockery.rb +9 -22
  10. data/lib/mocha/state_machine.rb +30 -38
  11. data/lib/mocha/version.rb +1 -1
  12. data/mocha.gemspec +3 -1
  13. metadata +5 -192
  14. data/docs/CNAME +0 -1
  15. data/docs/Mocha.html +0 -254
  16. data/docs/Mocha/API.html +0 -1285
  17. data/docs/Mocha/ClassMethods.html +0 -264
  18. data/docs/Mocha/Configuration.html +0 -1525
  19. data/docs/Mocha/Expectation.html +0 -2862
  20. data/docs/Mocha/ExpectationError.html +0 -152
  21. data/docs/Mocha/ExpectationErrorFactory.html +0 -260
  22. data/docs/Mocha/Hooks.html +0 -370
  23. data/docs/Mocha/Integration.html +0 -125
  24. data/docs/Mocha/Integration/MiniTest.html +0 -123
  25. data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -164
  26. data/docs/Mocha/Integration/TestUnit.html +0 -123
  27. data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -164
  28. data/docs/Mocha/Mock.html +0 -1210
  29. data/docs/Mocha/ObjectMethods.html +0 -765
  30. data/docs/Mocha/ParameterMatchers.html +0 -2949
  31. data/docs/Mocha/ParameterMatchers/AllOf.html +0 -153
  32. data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -153
  33. data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
  34. data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
  35. data/docs/Mocha/ParameterMatchers/Base.html +0 -441
  36. data/docs/Mocha/ParameterMatchers/Equals.html +0 -153
  37. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
  38. data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -153
  39. data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -153
  40. data/docs/Mocha/ParameterMatchers/HasKey.html +0 -153
  41. data/docs/Mocha/ParameterMatchers/HasValue.html +0 -153
  42. data/docs/Mocha/ParameterMatchers/Includes.html +0 -153
  43. data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -153
  44. data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
  45. data/docs/Mocha/ParameterMatchers/KindOf.html +0 -153
  46. data/docs/Mocha/ParameterMatchers/Not.html +0 -153
  47. data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
  48. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -153
  49. data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -153
  50. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -153
  51. data/docs/Mocha/Sequence.html +0 -149
  52. data/docs/Mocha/StateMachine.html +0 -527
  53. data/docs/Mocha/StateMachine/State.html +0 -140
  54. data/docs/Mocha/StateMachine/StatePredicate.html +0 -140
  55. data/docs/Mocha/StubbingError.html +0 -150
  56. data/docs/_index.html +0 -519
  57. data/docs/class_list.html +0 -51
  58. data/docs/css/common.css +0 -1
  59. data/docs/css/full_list.css +0 -58
  60. data/docs/css/style.css +0 -496
  61. data/docs/file.COPYING.html +0 -81
  62. data/docs/file.MIT-LICENSE.html +0 -85
  63. data/docs/file.README.html +0 -448
  64. data/docs/file.RELEASE.html +0 -1028
  65. data/docs/file_list.html +0 -71
  66. data/docs/frames.html +0 -17
  67. data/docs/index.html +0 -448
  68. data/docs/js/app.js +0 -303
  69. data/docs/js/full_list.js +0 -216
  70. data/docs/js/jquery.js +0 -4
  71. data/docs/method_list.html +0 -651
  72. data/docs/top-level-namespace.html +0 -118
  73. data/test/acceptance/acceptance_test_helper.rb +0 -42
  74. data/test/acceptance/bug_18914_test.rb +0 -37
  75. data/test/acceptance/bug_21465_test.rb +0 -31
  76. data/test/acceptance/bug_21563_test.rb +0 -22
  77. data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +0 -69
  78. data/test/acceptance/exception_rescue_test.rb +0 -53
  79. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
  80. data/test/acceptance/expected_invocation_count_test.rb +0 -229
  81. data/test/acceptance/failure_messages_test.rb +0 -77
  82. data/test/acceptance/issue_272_test.rb +0 -50
  83. data/test/acceptance/issue_457_test.rb +0 -31
  84. data/test/acceptance/issue_65_test.rb +0 -64
  85. data/test/acceptance/issue_70_test.rb +0 -53
  86. data/test/acceptance/mocha_example_test.rb +0 -106
  87. data/test/acceptance/mocha_test_result_test.rb +0 -83
  88. data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -98
  89. data/test/acceptance/mock_test.rb +0 -191
  90. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
  91. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
  92. data/test/acceptance/multiple_yielding_test.rb +0 -59
  93. data/test/acceptance/optional_parameters_test.rb +0 -67
  94. data/test/acceptance/parameter_matcher_test.rb +0 -299
  95. data/test/acceptance/partial_mocks_test.rb +0 -44
  96. data/test/acceptance/prepend_test.rb +0 -86
  97. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -76
  98. data/test/acceptance/raise_exception_test.rb +0 -36
  99. data/test/acceptance/return_value_test.rb +0 -49
  100. data/test/acceptance/sequence_test.rb +0 -189
  101. data/test/acceptance/states_test.rb +0 -71
  102. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -64
  103. data/test/acceptance/stub_any_instance_method_test.rb +0 -301
  104. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -105
  105. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
  106. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -73
  107. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -144
  108. data/test/acceptance/stub_everything_test.rb +0 -53
  109. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -91
  110. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -67
  111. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -67
  112. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -136
  113. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -76
  114. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
  115. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -67
  116. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -70
  117. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -38
  118. data/test/acceptance/stub_module_method_test.rb +0 -200
  119. data/test/acceptance/stub_test.rb +0 -49
  120. data/test/acceptance/stubba_example_test.rb +0 -103
  121. data/test/acceptance/stubba_test_result_test.rb +0 -71
  122. data/test/acceptance/stubbing_error_backtrace_test.rb +0 -63
  123. data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
  124. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -52
  125. data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
  126. data/test/acceptance/stubbing_nil_test.rb +0 -60
  127. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -157
  128. data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
  129. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
  130. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
  131. data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
  132. data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
  133. data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
  134. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -33
  135. data/test/acceptance/throw_test.rb +0 -42
  136. data/test/acceptance/unexpected_invocation_test.rb +0 -23
  137. data/test/acceptance/unstubbing_test.rb +0 -194
  138. data/test/acceptance/yielding_test.rb +0 -80
  139. data/test/assertions.rb +0 -8
  140. data/test/deprecation_disabler.rb +0 -15
  141. data/test/execution_point.rb +0 -36
  142. data/test/integration/mini_test_test.rb +0 -8
  143. data/test/integration/shared_tests.rb +0 -178
  144. data/test/integration/test_unit_test.rb +0 -8
  145. data/test/method_definer.rb +0 -16
  146. data/test/mini_test_result.rb +0 -96
  147. data/test/minitest_result.rb +0 -48
  148. data/test/simple_counter.rb +0 -11
  149. data/test/test_helper.rb +0 -58
  150. data/test/test_runner.rb +0 -58
  151. data/test/test_unit_result.rb +0 -22
  152. data/test/unit/any_instance_method_test.rb +0 -175
  153. data/test/unit/array_inspect_test.rb +0 -14
  154. data/test/unit/backtrace_filter_test.rb +0 -17
  155. data/test/unit/cardinality_test.rb +0 -72
  156. data/test/unit/central_test.rb +0 -98
  157. data/test/unit/change_state_side_effect_test.rb +0 -37
  158. data/test/unit/class_methods_test.rb +0 -69
  159. data/test/unit/configuration_test.rb +0 -37
  160. data/test/unit/date_time_inspect_test.rb +0 -19
  161. data/test/unit/exception_raiser_test.rb +0 -45
  162. data/test/unit/expectation_list_test.rb +0 -82
  163. data/test/unit/expectation_test.rb +0 -504
  164. data/test/unit/hash_inspect_test.rb +0 -14
  165. data/test/unit/hooks_test.rb +0 -35
  166. data/test/unit/in_state_ordering_constraint_test.rb +0 -39
  167. data/test/unit/instance_method_test.rb +0 -282
  168. data/test/unit/method_matcher_test.rb +0 -26
  169. data/test/unit/mock_test.rb +0 -372
  170. data/test/unit/mockery_test.rb +0 -171
  171. data/test/unit/module_methods_test.rb +0 -16
  172. data/test/unit/object_inspect_test.rb +0 -60
  173. data/test/unit/object_methods_test.rb +0 -63
  174. data/test/unit/parameter_matchers/all_of_test.rb +0 -24
  175. data/test/unit/parameter_matchers/any_of_test.rb +0 -24
  176. data/test/unit/parameter_matchers/anything_test.rb +0 -19
  177. data/test/unit/parameter_matchers/equals_test.rb +0 -23
  178. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -41
  179. data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
  180. data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
  181. data/test/unit/parameter_matchers/has_key_test.rb +0 -54
  182. data/test/unit/parameter_matchers/has_value_test.rb +0 -55
  183. data/test/unit/parameter_matchers/includes_test.rb +0 -106
  184. data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
  185. data/test/unit/parameter_matchers/is_a_test.rb +0 -23
  186. data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
  187. data/test/unit/parameter_matchers/not_test.rb +0 -24
  188. data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
  189. data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
  190. data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
  191. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
  192. data/test/unit/parameters_matcher_test.rb +0 -119
  193. data/test/unit/receivers_test.rb +0 -96
  194. data/test/unit/return_values_test.rb +0 -66
  195. data/test/unit/sequence_test.rb +0 -100
  196. data/test/unit/single_return_value_test.rb +0 -17
  197. data/test/unit/state_machine_test.rb +0 -96
  198. data/test/unit/string_inspect_test.rb +0 -9
  199. data/test/unit/thrower_test.rb +0 -23
  200. data/test/unit/yield_parameters_test.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 398d43b17f224be63c21bcd24cbe4d1bff6b90267e1a870eb4f2a3432515da88
4
- data.tar.gz: bd7c4a5ce95a20b5b403750982d63356e1553af54f45d538cc3e3c514f7fb079
3
+ metadata.gz: 3182f55b0e553eb0559fee7df5f5fd71f824e219480715de2f35e7bfacb5d9b2
4
+ data.tar.gz: 485677b5a3628ccee3730274697f27defb4fc087cc838d7c4ec8dac4e3cd589d
5
5
  SHA512:
6
- metadata.gz: 0b8a00e3b21f5761fede57f919785ac653e714d28151325980d6ae5bd5d0a7ec5ecdcbaf96d6e36c6659347852e414b3a1c10fb57e0c72b981e70348308174f1
7
- data.tar.gz: f85f050cbbb7bfa224420e8ad2f67f6b683576a1d8ef1d79f55acecda495febca0f6b0aae79721c0159028f752c2e19268f06c5dc8e27f40dd5449e8ea5b96ae
6
+ metadata.gz: 1f782e0791e221f18081e35a298a039b96afd7a06caf4177a3d117e3803ee2165d9cd5dd6c19edde9334fda7dea973c105a5c3fe7070810dd0e7229901df056f
7
+ data.tar.gz: 8adf5cf18b21d7039c7c8f10b4c7a49ba4a215d9351cdd89a04d7a4371eda9863727b08e5bdbb240d92dd6cc93555306b13501370ecdadd4b6a74368213851c5
@@ -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,30 @@
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
+
3
28
  ## 1.11.2
4
29
 
5
30
  ### External changes
data/Rakefile CHANGED
@@ -145,8 +145,13 @@ if ENV['MOCHA_GENERATE_DOCS']
145
145
  `git checkout docs/CNAME`
146
146
  end
147
147
 
148
+ task 'checkout_docs_js' do
149
+ `git checkout docs/js/app.js`
150
+ `git checkout docs/js/jquery.js`
151
+ end
152
+
148
153
  desc 'Generate documentation'
149
- task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname]
154
+ task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname checkout_docs_js]
150
155
  end
151
156
 
152
157
  task 'release' => 'default'
@@ -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
@@ -42,7 +42,7 @@ module Mocha
42
42
  # object.expected_method
43
43
  # # => verify fails
44
44
  def times(range)
45
- @cardinality = Cardinality.times(range)
45
+ @cardinality.times(range)
46
46
  self
47
47
  end
48
48
 
@@ -68,7 +68,7 @@ module Mocha
68
68
  # object.expected_method
69
69
  # # => verify fails
70
70
  def twice
71
- @cardinality = Cardinality.exactly(2)
71
+ @cardinality.exactly(2)
72
72
  self
73
73
  end
74
74
 
@@ -93,7 +93,7 @@ module Mocha
93
93
  # object.expects(:expected_method).once
94
94
  # # => verify fails
95
95
  def once
96
- @cardinality = Cardinality.exactly(1)
96
+ @cardinality.exactly(1)
97
97
  self
98
98
  end
99
99
 
@@ -110,7 +110,7 @@ module Mocha
110
110
  # object.expects(:expected_method).never
111
111
  # # => verify succeeds
112
112
  def never
113
- @cardinality = Cardinality.exactly(0)
113
+ @cardinality.exactly(0)
114
114
  self
115
115
  end
116
116
 
@@ -130,7 +130,7 @@ module Mocha
130
130
  # object.expected_method
131
131
  # # => verify fails
132
132
  def at_least(minimum_number_of_times)
133
- @cardinality = Cardinality.at_least(minimum_number_of_times)
133
+ @cardinality.at_least(minimum_number_of_times)
134
134
  self
135
135
  end
136
136
 
@@ -149,7 +149,6 @@ module Mocha
149
149
  # # => verify fails
150
150
  def at_least_once
151
151
  at_least(1)
152
- self
153
152
  end
154
153
 
155
154
  # Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+.
@@ -167,7 +166,7 @@ module Mocha
167
166
  # object.expects(:expected_method).at_most(2)
168
167
  # 3.times { object.expected_method } # => unexpected invocation
169
168
  def at_most(maximum_number_of_times)
170
- @cardinality = Cardinality.at_most(maximum_number_of_times)
169
+ @cardinality.at_most(maximum_number_of_times)
171
170
  self
172
171
  end
173
172
 
@@ -186,7 +185,6 @@ module Mocha
186
185
  # 2.times { object.expected_method } # => unexpected invocation
187
186
  def at_most_once
188
187
  at_most(1)
189
- self
190
188
  end
191
189
 
192
190
  # Modifies expectation so that the expected method must be called with +expected_parameters+.
@@ -263,7 +261,11 @@ module Mocha
263
261
  self
264
262
  end
265
263
 
266
- # Modifies expectation so that when the expected method is called, it yields with the specified +parameters+ (even if no block is provided, in which case yielding will result in a +LocalJumpError+).
264
+ # Modifies expectation so that when the expected method is called, it yields to the block with the specified +parameters+.
265
+ #
266
+ # If no +parameters+ are specified, it yields to the block without any parameters.
267
+ #
268
+ # If no block is provided, the method will still attempt to yield resulting in a +LocalJumpError+. Note that this is what would happen if a "real" (non-mock) method implementation tried to yield to a non-existent block.
267
269
  #
268
270
  # May be called multiple times on the same expectation for consecutive invocations.
269
271
  #
@@ -273,11 +275,10 @@ module Mocha
273
275
  #
274
276
  # @example Yield when expected method is invoked.
275
277
  # benchmark = mock()
276
- # benchmark.expects(:measure).yields.then.returns('0.350000 0.400000 0.750000 ( 0.835234)')
278
+ # benchmark.expects(:measure).yields
277
279
  # yielded = false
278
- # returned_value = benchmark.measure { yielded = true }
280
+ # benchmark.measure { yielded = true }
279
281
  # yielded # => true
280
- # returned_value # => '0.350000 0.400000 0.750000 ( 0.835234)'
281
282
  #
282
283
  # @example Yield parameters when expected method is invoked.
283
284
  # fibonacci = mock()
@@ -298,7 +299,9 @@ module Mocha
298
299
  multiple_yields(parameters)
299
300
  end
300
301
 
301
- # Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+ (even if no block is provided, in which case yielding will result in a +LocalJumpError+).
302
+ # Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+.
303
+ #
304
+ # If no block is provided, the method will still attempt to yield resulting in a +LocalJumpError+. Note that this is what would happen if a "real" (non-mock) method implementation tried to yield to a non-existent block.
302
305
  #
303
306
  # @param [*Array<Array>] parameter_groups each element of +parameter_groups+ should iself be an +Array+ representing the parameters to be passed to the block for a single yield. Any element of +parameter_groups+ that is not an +Array+ is wrapped in an +Array+.
304
307
  # @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
@@ -453,9 +456,9 @@ module Mocha
453
456
 
454
457
  # @overload def then
455
458
  # Used as syntactic sugar to improve readability. It has no effect on state of the expectation.
456
- # @overload def then(state_machine.is(state_name))
457
- # Used to change the +state_machine+ to the state specified by +state_name+ when the expected invocation occurs.
458
- # @param [StateMachine::State] state_machine.is(state_name) provides a mechanism to change the +state_machine+ into the state specified by +state_name+ when the expected method is invoked.
459
+ # @overload def then(state)
460
+ # Used to change the +state_machine+ to the specified state when the expected invocation occurs.
461
+ # @param [StateMachine::State] state state_machine.is(state_name) provides a mechanism to change the +state_machine+ into the state specified by +state_name+ when the expected method is invoked.
459
462
  #
460
463
  # @see API#states
461
464
  # @see StateMachine
@@ -481,17 +484,14 @@ module Mocha
481
484
  # radio.expects(:select_channel).with('BBC World Service').when(power.is('on'))
482
485
  # radio.expects(:adjust_volume).with(-5).when(power.is('on'))
483
486
  # radio.expects(:switch_off).then(power.is('off'))
484
- def then(*parameters)
485
- if parameters.length == 1
486
- state = parameters.first
487
- add_side_effect(ChangeStateSideEffect.new(state))
488
- end
487
+ def then(state = nil)
488
+ add_side_effect(ChangeStateSideEffect.new(state)) if state
489
489
  self
490
490
  end
491
491
 
492
- # Constrains the expectation to occur only when the +state_machine+ is in the state specified by +state_name+.
492
+ # Constrains the expectation to occur only when the +state_machine+ is in the state specified by +state_predicate+.
493
493
  #
494
- # @param [StateMachine::StatePredicate] state_machine.is(state_name) provides a mechanism to determine whether the +state_machine+ is in the state specified by +state_name+ when the expected method is invoked.
494
+ # @param [StateMachine::StatePredicate] state_predicate +state_machine.is(state_name)+ provides a mechanism to determine whether the +state_machine+ is in the state specified by +state_predicate+ when the expected method is invoked.
495
495
  # @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
496
496
  #
497
497
  # @see API#states
@@ -552,7 +552,7 @@ module Mocha
552
552
  @block_matcher = BlockMatchers::OptionalBlock.new
553
553
  @ordering_constraints = []
554
554
  @side_effects = []
555
- @cardinality = Cardinality.exactly(1)
555
+ @cardinality = Cardinality.new.exactly(1)
556
556
  @return_values = ReturnValues.new
557
557
  @yield_parameters = YieldParameters.new
558
558
  @backtrace = backtrace || caller
@@ -330,8 +330,8 @@ module Mocha
330
330
  end
331
331
  end
332
332
 
333
- # @private
334
333
  if PRE_RUBY_V19
334
+ # @private
335
335
  def respond_to?(symbol, include_private = false)
336
336
  respond_to_missing?(symbol, include_private)
337
337
  end
@@ -35,12 +35,13 @@ module Mocha
35
35
 
36
36
  class << self
37
37
  def instance
38
- instances.last || Null.new
38
+ @instances.last || Null.new
39
39
  end
40
40
 
41
41
  def setup
42
+ @instances ||= []
42
43
  mockery = new
43
- mockery.logger = instance.logger unless instances.empty?
44
+ mockery.logger = instance.logger unless @instances.empty?
44
45
  @instances.push(mockery)
45
46
  end
46
47
 
@@ -52,13 +53,6 @@ module Mocha
52
53
  instance.teardown
53
54
  ensure
54
55
  @instances.pop
55
- @instances = nil if instances.empty?
56
- end
57
-
58
- private
59
-
60
- def instances
61
- @instances ||= []
62
56
  end
63
57
  end
64
58
 
@@ -92,11 +86,9 @@ module Mocha
92
86
  end
93
87
  raise ExpectationErrorFactory.build(message, backtrace)
94
88
  end
95
- expectations.each do |e|
96
- unless Mocha.configuration.stubbing_method_unnecessarily == :allow
97
- next if e.used?
98
- on_stubbing_method_unnecessarily(e)
99
- end
89
+ expectations.reject(&:used?).each do |expectation|
90
+ signature_proc = lambda { expectation.method_signature }
91
+ check(:stubbing_method_unnecessarily, 'method unnecessarily', signature_proc, expectation.backtrace)
100
92
  end
101
93
  end
102
94
 
@@ -120,9 +112,9 @@ module Mocha
120
112
 
121
113
  def mocha_inspect
122
114
  message = ''
123
- message << "unsatisfied expectations:\n- #{unsatisfied_expectations.map(&:mocha_inspect).join("\n- ")}\n" unless unsatisfied_expectations.empty?
124
- message << "satisfied expectations:\n- #{satisfied_expectations.map(&:mocha_inspect).join("\n- ")}\n" unless satisfied_expectations.empty?
125
- message << "states:\n- #{state_machines.map(&:mocha_inspect).join("\n- ")}" unless state_machines.empty?
115
+ message << "unsatisfied expectations:\n- #{unsatisfied_expectations.map(&:mocha_inspect).join("\n- ")}\n" if unsatisfied_expectations.any?
116
+ message << "satisfied expectations:\n- #{satisfied_expectations.map(&:mocha_inspect).join("\n- ")}\n" if satisfied_expectations.any?
117
+ message << "states:\n- #{state_machines.map(&:mocha_inspect).join("\n- ")}\n" if state_machines.any?
126
118
  message
127
119
  end
128
120
 
@@ -139,11 +131,6 @@ module Mocha
139
131
  check(:stubbing_method_on_non_mock_object, 'method on non-mock object', signature_proc)
140
132
  end
141
133
 
142
- def on_stubbing_method_unnecessarily(expectation)
143
- signature_proc = lambda { expectation.method_signature }
144
- check(:stubbing_method_unnecessarily, 'method unnecessarily', signature_proc, expectation.backtrace)
145
- end
146
-
147
134
  attr_writer :logger
148
135
 
149
136
  def logger