mocha 1.7.0 → 1.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.rubocop_todo.yml +7 -30
  4. data/CONTRIBUTING.md +4 -9
  5. data/README.md +55 -27
  6. data/RELEASE.md +89 -0
  7. data/Rakefile +15 -16
  8. data/bin/build-matrix +15 -2
  9. data/docs/CNAME +1 -0
  10. data/docs/Mocha.html +254 -0
  11. data/docs/Mocha/API.html +1287 -0
  12. data/docs/Mocha/ClassMethods.html +264 -0
  13. data/docs/Mocha/Configuration.html +1525 -0
  14. data/docs/Mocha/Expectation.html +2654 -0
  15. data/docs/Mocha/ExpectationError.html +152 -0
  16. data/docs/Mocha/ExpectationErrorFactory.html +260 -0
  17. data/docs/Mocha/Hooks.html +370 -0
  18. data/docs/Mocha/Integration.html +125 -0
  19. data/docs/Mocha/Integration/MiniTest.html +123 -0
  20. data/docs/Mocha/Integration/MiniTest/Adapter.html +164 -0
  21. data/docs/Mocha/Integration/TestUnit.html +123 -0
  22. data/docs/Mocha/Integration/TestUnit/Adapter.html +164 -0
  23. data/docs/Mocha/Mock.html +1237 -0
  24. data/docs/Mocha/ObjectMethods.html +765 -0
  25. data/docs/Mocha/ParameterMatchers.html +2961 -0
  26. data/docs/Mocha/ParameterMatchers/AllOf.html +153 -0
  27. data/docs/Mocha/ParameterMatchers/AnyOf.html +153 -0
  28. data/docs/Mocha/ParameterMatchers/AnyParameters.html +153 -0
  29. data/docs/Mocha/ParameterMatchers/Anything.html +153 -0
  30. data/docs/Mocha/ParameterMatchers/Base.html +441 -0
  31. data/docs/Mocha/ParameterMatchers/Equals.html +153 -0
  32. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +153 -0
  33. data/docs/Mocha/ParameterMatchers/HasEntries.html +153 -0
  34. data/docs/Mocha/ParameterMatchers/HasEntry.html +153 -0
  35. data/docs/Mocha/ParameterMatchers/HasKey.html +153 -0
  36. data/docs/Mocha/ParameterMatchers/HasValue.html +153 -0
  37. data/docs/Mocha/ParameterMatchers/Includes.html +153 -0
  38. data/docs/Mocha/ParameterMatchers/InstanceOf.html +153 -0
  39. data/docs/Mocha/ParameterMatchers/IsA.html +153 -0
  40. data/docs/Mocha/ParameterMatchers/KindOf.html +153 -0
  41. data/docs/Mocha/ParameterMatchers/Not.html +153 -0
  42. data/docs/Mocha/ParameterMatchers/Optionally.html +153 -0
  43. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +153 -0
  44. data/docs/Mocha/ParameterMatchers/RespondsWith.html +153 -0
  45. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +153 -0
  46. data/docs/Mocha/Sequence.html +149 -0
  47. data/docs/Mocha/StateMachine.html +527 -0
  48. data/docs/Mocha/StateMachine/State.html +140 -0
  49. data/docs/Mocha/StateMachine/StatePredicate.html +140 -0
  50. data/docs/Mocha/StubbingError.html +150 -0
  51. data/docs/_index.html +519 -0
  52. data/docs/class_list.html +51 -0
  53. data/docs/css/common.css +1 -0
  54. data/docs/css/full_list.css +58 -0
  55. data/docs/css/style.css +496 -0
  56. data/docs/file.COPYING.html +81 -0
  57. data/docs/file.MIT-LICENSE.html +85 -0
  58. data/docs/file.README.html +448 -0
  59. data/docs/file.RELEASE.html +974 -0
  60. data/docs/file_list.html +71 -0
  61. data/docs/frames.html +17 -0
  62. data/docs/index.html +448 -0
  63. data/docs/js/app.js +303 -0
  64. data/docs/js/full_list.js +216 -0
  65. data/docs/js/jquery.js +4 -0
  66. data/docs/method_list.html +635 -0
  67. data/docs/top-level-namespace.html +118 -0
  68. data/gemfiles/Gemfile.minitest.5.11.3 +7 -0
  69. data/init.rb +1 -3
  70. data/lib/mocha.rb +8 -0
  71. data/lib/mocha/any_instance_method.rb +11 -53
  72. data/lib/mocha/api.rb +120 -56
  73. data/lib/mocha/cardinality.rb +26 -11
  74. data/lib/mocha/class_methods.rb +17 -15
  75. data/lib/mocha/configuration.rb +351 -67
  76. data/lib/mocha/deprecation.rb +2 -1
  77. data/lib/mocha/detection/test_unit.rb +1 -3
  78. data/lib/mocha/exception_raiser.rb +2 -1
  79. data/lib/mocha/expectation.rb +56 -58
  80. data/lib/mocha/expectation_error.rb +1 -3
  81. data/lib/mocha/expectation_list.rb +6 -6
  82. data/lib/mocha/inspect.rb +28 -26
  83. data/lib/mocha/instance_method.rb +19 -2
  84. data/lib/mocha/integration.rb +1 -3
  85. data/lib/mocha/integration/mini_test.rb +7 -0
  86. data/lib/mocha/integration/test_unit.rb +7 -0
  87. data/lib/mocha/invocation.rb +73 -0
  88. data/lib/mocha/macos_version.rb +5 -0
  89. data/lib/mocha/minitest.rb +6 -1
  90. data/lib/mocha/mock.rb +46 -31
  91. data/lib/mocha/mockery.rb +25 -61
  92. data/lib/mocha/names.rb +1 -1
  93. data/lib/mocha/object_methods.rb +13 -19
  94. data/lib/mocha/parameter_matchers.rb +1 -1
  95. data/lib/mocha/parameter_matchers/all_of.rb +1 -1
  96. data/lib/mocha/parameter_matchers/any_of.rb +1 -1
  97. data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -9
  98. data/lib/mocha/parameter_matchers/includes.rb +2 -0
  99. data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
  100. data/lib/mocha/raised_exception.rb +11 -0
  101. data/lib/mocha/return_values.rb +3 -3
  102. data/lib/mocha/setup.rb +5 -0
  103. data/lib/mocha/single_return_value.rb +2 -1
  104. data/lib/mocha/singleton_class.rb +9 -0
  105. data/lib/mocha/stubbed_method.rb +127 -0
  106. data/lib/mocha/test_unit.rb +6 -1
  107. data/lib/mocha/thrower.rb +2 -1
  108. data/lib/mocha/thrown_object.rb +12 -0
  109. data/lib/mocha/version.rb +1 -1
  110. data/mocha.gemspec +3 -6
  111. data/test/acceptance/acceptance_test_helper.rb +6 -0
  112. data/test/acceptance/bug_18914_test.rb +0 -1
  113. data/test/acceptance/bug_21465_test.rb +0 -1
  114. data/test/acceptance/bug_21563_test.rb +0 -1
  115. data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +69 -0
  116. data/test/acceptance/exception_rescue_test.rb +1 -2
  117. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -1
  118. data/test/acceptance/expected_invocation_count_test.rb +2 -3
  119. data/test/acceptance/failure_messages_test.rb +0 -1
  120. data/test/acceptance/issue_272_test.rb +1 -2
  121. data/test/acceptance/issue_65_test.rb +0 -1
  122. data/test/acceptance/issue_70_test.rb +0 -1
  123. data/test/acceptance/mocha_example_test.rb +0 -1
  124. data/test/acceptance/mocha_test_result_test.rb +0 -1
  125. data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +99 -0
  126. data/test/acceptance/mock_test.rb +47 -6
  127. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -1
  128. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -1
  129. data/test/acceptance/optional_parameters_test.rb +0 -1
  130. data/test/acceptance/parameter_matcher_test.rb +0 -1
  131. data/test/acceptance/partial_mocks_test.rb +0 -1
  132. data/test/acceptance/prepend_test.rb +0 -1
  133. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -1
  134. data/test/acceptance/raise_exception_test.rb +0 -1
  135. data/test/acceptance/return_value_test.rb +0 -1
  136. data/test/acceptance/sequence_test.rb +0 -1
  137. data/test/acceptance/states_test.rb +0 -1
  138. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +1 -2
  139. data/test/acceptance/stub_any_instance_method_test.rb +20 -1
  140. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -1
  141. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -1
  142. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -1
  143. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +1 -2
  144. data/test/acceptance/stub_everything_test.rb +0 -1
  145. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -1
  146. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -1
  147. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -1
  148. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -1
  149. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -1
  150. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -1
  151. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -1
  152. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -1
  153. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -1
  154. data/test/acceptance/stub_module_method_test.rb +0 -1
  155. data/test/acceptance/stub_test.rb +0 -1
  156. data/test/acceptance/stubba_example_test.rb +0 -1
  157. data/test/acceptance/stubba_test_result_test.rb +0 -1
  158. data/test/acceptance/stubbing_error_backtrace_test.rb +4 -5
  159. data/test/acceptance/stubbing_frozen_object_test.rb +0 -1
  160. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -1
  161. data/test/acceptance/stubbing_method_unnecessarily_test.rb +5 -5
  162. data/test/acceptance/stubbing_nil_test.rb +5 -5
  163. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +27 -11
  164. data/test/acceptance/stubbing_non_existent_class_method_test.rb +11 -11
  165. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +11 -11
  166. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +8 -8
  167. data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
  168. data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
  169. data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
  170. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -1
  171. data/test/acceptance/throw_test.rb +0 -1
  172. data/test/acceptance/unexpected_invocation_test.rb +0 -1
  173. data/test/acceptance/unstubbing_test.rb +0 -1
  174. data/test/integration/shared_tests.rb +5 -3
  175. data/test/method_definer.rb +11 -17
  176. data/test/test_runner.rb +2 -0
  177. data/test/unit/any_instance_method_test.rb +60 -35
  178. data/test/unit/cardinality_test.rb +41 -23
  179. data/test/unit/central_test.rb +0 -1
  180. data/test/unit/class_methods_test.rb +1 -1
  181. data/test/unit/configuration_test.rb +12 -12
  182. data/test/unit/exception_raiser_test.rb +10 -5
  183. data/test/unit/expectation_list_test.rb +13 -11
  184. data/test/unit/expectation_test.rb +103 -103
  185. data/test/unit/instance_method_test.rb +282 -0
  186. data/test/unit/mock_test.rb +28 -19
  187. data/test/unit/mockery_test.rb +8 -11
  188. data/test/unit/module_methods_test.rb +2 -3
  189. data/test/unit/object_inspect_test.rb +16 -4
  190. data/test/unit/object_methods_test.rb +3 -2
  191. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -9
  192. data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
  193. data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
  194. data/test/unit/parameter_matchers/has_key_test.rb +1 -1
  195. data/test/unit/parameter_matchers/has_value_test.rb +1 -1
  196. data/test/unit/parameter_matchers/includes_test.rb +1 -1
  197. data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
  198. data/test/unit/return_values_test.rb +25 -20
  199. data/test/unit/single_return_value_test.rb +6 -1
  200. data/test/unit/thrower_test.rb +7 -2
  201. data/yard-templates/default/layout/html/google_analytics.erb +6 -9
  202. metadata +78 -61
  203. data/lib/mocha/class_method.rb +0 -113
  204. data/lib/mocha/mini_test.rb +0 -5
  205. data/lib/mocha/module_method.rb +0 -6
  206. data/lib/mocha/module_methods.rb +0 -10
  207. data/lib/mocha/parameter_matchers/object.rb +0 -15
  208. data/lib/mocha/standalone.rb +0 -4
  209. data/lib/mocha/unexpected_invocation.rb +0 -24
  210. data/lib/mocha_standalone.rb +0 -4
  211. data/test/acceptance/mock_with_initializer_block_test.rb +0 -56
  212. data/test/unit/class_method_test.rb +0 -254
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a4829127b1767afd658a5e520e345b8ec4fcef1dd34c3ca5fb719aea017d1a4
4
- data.tar.gz: 2d37035d149af5d3bc3cfed12879ec4656cec21dd7145041be83df95ca86e694
3
+ metadata.gz: 0071e59a90a0d4f365ff5e19e4a0b5f74483d10c41fd77362d3414071fe4829b
4
+ data.tar.gz: 0a22b3a9cd04dce410fe6ef613e6c2a81fb905bbf60ac01228f8aa19852d6d8a
5
5
  SHA512:
6
- metadata.gz: 01b91e4eae791aea7ad59d9170ad532ce610f2abd038594347e125f29e8e25614f0036a90690b15a3ffbf7ef603ca379f07507238f3820e315b9cec72bd3a730
7
- data.tar.gz: 7cc96b39e8d553c69afcf4fc9186b2c2fbe38006f4bd0cee621e00eae81ed8621a3aac2f2e2b977ab36d8fd328b7297957d861bba2ad2a02f27113a2539c5472
6
+ metadata.gz: 91678a1e05d7516e2079604c19a97c0b67d6127e4efb1e152ae81735c12561b80c32f28d7318270247b9fa0cc659f976067c1baf074293c060f05db2090b4203
7
+ data.tar.gz: 298befb4573b09e6c597c03af24f083a5de24be1ccebc172f8efa4ac5debf6d5bfbc6da062edd2f2925b0864b020faf55644ba88ffaa55161c806613d6a0b6dd
@@ -8,6 +8,9 @@ AllCops:
8
8
  Style/Alias:
9
9
  EnforcedStyle: prefer_alias_method
10
10
 
11
+ Style/Documentation:
12
+ Enabled: false
13
+
11
14
  # Enumerable#each_with_object only available since Ruby v1.9
12
15
  Style/EachWithObject:
13
16
  Enabled: false
@@ -1,49 +1,26 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-07-26 12:42:35 +0100 using RuboCop version 0.58.2.
3
+ # on 2019-11-16 18:15:36 +0000 using RuboCop version 0.58.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 53
9
+ # Offense count: 57
10
10
  Metrics/AbcSize:
11
- Max: 39
11
+ Max: 26
12
12
 
13
- # Offense count: 2
14
- # Configuration parameters: CountComments, ExcludedMethods.
15
- # ExcludedMethods: refine
16
- Metrics/BlockLength:
17
- Max: 48
18
-
19
- # Offense count: 22
13
+ # Offense count: 23
20
14
  # Configuration parameters: CountComments.
21
15
  Metrics/ClassLength:
22
- Max: 368
23
-
24
- # Offense count: 4
25
- Metrics/CyclomaticComplexity:
26
- Max: 9
16
+ Max: 366
27
17
 
28
- # Offense count: 173
18
+ # Offense count: 172
29
19
  # Configuration parameters: CountComments.
30
20
  Metrics/MethodLength:
31
21
  Max: 31
32
22
 
33
- # Offense count: 1
34
- # Configuration parameters: CountComments.
35
- Metrics/ModuleLength:
36
- Max: 158
37
-
38
- # Offense count: 5
39
- Metrics/PerceivedComplexity:
40
- Max: 11
41
-
42
- # Offense count: 105
43
- Style/Documentation:
44
- Enabled: false
45
-
46
- # Offense count: 501
23
+ # Offense count: 545
47
24
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
48
25
  # URISchemes: http, https
49
26
  Metrics/LineLength:
@@ -1,12 +1,7 @@
1
1
  * Pull requests are welcomed.
2
2
  * Fork the repository.
3
3
  * Make your changes in a branch.
4
- * Add tests for new behaviour. Modify/remove existing tests for changes to existing behaviour.
5
- * Run `bin/build-matrix` from the root directory and ensure all the tests pass.
6
- * This script depends on `rbenv` being installed.
7
- * You must have all the ruby versions listed in `.travis.yml` under the `rvm` key installed (currently 1.8.7, 1.9.3 & 2.0.0).
8
- * I use `rbenv-aliases` to alias the patch versions.
9
- * Note that the build matrix takes quite a while to run.
10
- * Send us a pull request from your fork/branch.
11
- * Wait for your pull request to build on [Travis CI](https://travis-ci.org/freerange/mocha).
12
- * I will not accept pull requests with failing tests.
4
+ * Add/modify/remove tests as appropriate.
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).
7
+ * Pull requests with failing tests will not be accepted.
data/README.md CHANGED
@@ -3,11 +3,14 @@
3
3
 
4
4
  ### Description
5
5
 
6
- * A Ruby library for mocking and stubbing.
6
+ * A Ruby library for [mocking](http://xunitpatterns.com/Mock%20Object.html) and [stubbing](http://xunitpatterns.com/Test%20Stub.html) - but deliberately not (yet) [faking](http://xunitpatterns.com/Fake%20Object.html) or [spying](http://xunitpatterns.com/Test%20Spy.html).
7
7
  * A unified, simple and readable syntax for both full & partial mocking.
8
8
  * Built-in support for MiniTest and Test::Unit.
9
9
  * Supported by many other test frameworks.
10
10
 
11
+ ### Intended Usage
12
+ Mocha is intended to be used in unit tests for the [Mock Object](http://xunitpatterns.com/Mock%20Object.html) or [Test Stub](http://xunitpatterns.com/Test%20Stub.html) types of [Test Double](http://xunitpatterns.com/Test%20Double.html), not the [Fake Object](http://xunitpatterns.com/Fake%20Object.html) or [Test Spy](http://xunitpatterns.com/Test%20Spy.html) types. Although it would be possible to extend Mocha to allow the implementation of fakes and spies, we have chosen to keep it focused on mocks and stubs.
13
+
11
14
  ### Installation
12
15
 
13
16
  #### Gem
@@ -92,14 +95,6 @@ end
92
95
 
93
96
  Note: There is no need to use a require statement to setup Mocha; RSpec does this itself.
94
97
 
95
- #### Rails Plugin
96
-
97
- Install the Rails plugin...
98
-
99
- $ rails plugin install git://github.com/freerange/mocha.git
100
-
101
- Note: As of version 0.9.8, the Mocha plugin is not automatically setup at plugin load time. Instead it must be manually setup e.g. at the bottom of your `test_helper.rb`.
102
-
103
98
  ##### MiniTest
104
99
 
105
100
  ```ruby
@@ -107,15 +102,34 @@ Note: As of version 0.9.8, the Mocha plugin is not automatically setup at plugin
107
102
  require 'mocha/minitest'
108
103
  ```
109
104
 
105
+ ##### Cucumber
106
+
107
+ ```ruby
108
+ # In e.g. features/support/mocha.rb
109
+ require 'mocha/api'
110
+
111
+ World(Mocha::API)
112
+
113
+ Around do |scenario, block|
114
+ begin
115
+ mocha_setup
116
+ block.call
117
+ mocha_verify
118
+ ensure
119
+ mocha_teardown
120
+ end
121
+ end
122
+ ```
123
+
110
124
  #### Known Issues
111
125
 
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.
112
127
  * In Mocha v1.2.0 there is a scenario where stubbing a class method originally defined in a module hangs the Ruby interpreter due to [a bug in Ruby v2.3.1](https://bugs.ruby-lang.org/issues/12832). See #272. This was fixed in Mocha v1.2.1.
113
128
  * Since v1.1.0 Mocha has used prepended modules internally for stubbing methods. There is [an obscure Ruby bug](https://bugs.ruby-lang.org/issues/12876) in many (but not all) versions of Ruby between v2.0 & v2.3 which under certain circumstances may cause your Ruby interpreter to hang. See the Ruby bug report for more details. The bug has been fixed in Ruby v2.3.3 & v2.4.0.
114
129
  * Stubbing an aliased class method, where the original method is defined in a module that's used to `extend` the class doesn't work in Ruby 1.8.x. See stub_method_defined_on_module_and_aliased_test.rb for an example of this behaviour.
115
130
  * 0.13.x versions cause a harmless, but annoying, deprecation warning when used with Rails 3.2.0-3.2.12, 3.1.0-3.1.10 & 3.0.0-3.0.19.
116
131
  * 0.11.x versions don't work with Rails 3.2.13 (`TypeError: superclass mismatch for class ExpectationError`). See #115.
117
132
  * Versions 0.10.2, 0.10.3 & 0.11.0 of the Mocha gem were broken. Please do not use these versions.
118
- * Versions 0.9.6 & 0.9.7 of the Mocha Rails plugin were broken. Please do not use these versions.
119
133
 
120
134
  ### Usage
121
135
 
@@ -256,7 +270,15 @@ end
256
270
 
257
271
  ### Thread safety
258
272
 
259
- Mocha is currently *not* thread-safe. There are two main reasons for this: (a) in multi-threaded code Mocha exceptions may be raised in a thread other than the one which is running the test and thus a Mocha exception may not be correctly intercepted by Mocha exception handling code; and (b) partial mocking changes the state of objects in the `ObjectSpace` which is shared across all threads in the Ruby process and this access to what is effectively global state is not synchronized.
273
+ Mocha currently *does not* attempt to be thread-safe.
274
+
275
+ #### Can I test multi-threaded code with Mocha?
276
+
277
+ The short answer is no. In multi-threaded code Mocha exceptions may be raised in a thread other than the one which is running the test and thus a Mocha exception may not be correctly intercepted by Mocha exception handling code.
278
+
279
+ #### Can I run my tests across multiple threads?
280
+
281
+ Maybe, but probably not. Partial mocking changes the state of objects in the `ObjectSpace` which is shared across all threads in the Ruby process and this access to what is effectively global state is not synchronized. So, for example, if two tests are running concurrently and one uses `#any_instance` to modify a class, both tests will see those changes immediately.
260
282
 
261
283
  ### Expectation matching / invocation order
262
284
 
@@ -264,7 +286,7 @@ Stubs and expectations are basically the same thing. A stub is just an expectati
264
286
 
265
287
  When a method is invoked on a mock object, the mock object searches through its expectations from newest to oldest to find one that matches the invocation. After the invocation, the matching expectation might stop matching further invocations.
266
288
 
267
- See the [documentation](http://gofreerange.com/mocha/docs/Mocha/Mock.html) for `Mocha::Mock` for further details.
289
+ See the [documentation](https://mocha.jamesmead.org/Mocha/Mock.html) for `Mocha::Mock` for further details.
268
290
 
269
291
  ### Configuration
270
292
 
@@ -275,11 +297,16 @@ If you want, Mocha can generate a warning or raise an exception when:
275
297
  * stubbing a non-existent method
276
298
  * stubbing a non-public method
277
299
 
278
- See the [documentation](http://gofreerange.com/mocha/docs/Mocha/Configuration.html) for `Mocha::Configuration` for further details.
300
+ See the [documentation](https://mocha.jamesmead.org/Mocha/Configuration.html) for `Mocha::Configuration` for further details.
301
+
302
+ ##### MOCHA_OPTIONS
303
+ `MOCHA_OPTIONS` is an environment variable whose value can be set to a comma-separated list, so that we can specify multiple options e.g. `MOCHA_OPTIONS=debug,use_test_unit_gem`.
304
+ Only the following values are currently recognized and have an effect:
305
+ * `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.
279
306
 
280
307
  ### Useful Links
281
308
 
282
- * [Official Documentation](http://gofreerange.com/mocha/docs/)
309
+ * [Official Documentation](https://mocha.jamesmead.org)
283
310
  * [Source Code](http://github.com/freerange/mocha)
284
311
  * [Mailing List](http://groups.google.com/group/mocha-developer)
285
312
  * [James Mead's Blog](http://jamesmead.org/blog/)
@@ -293,37 +320,38 @@ See the [documentation](http://gofreerange.com/mocha/docs/Mocha/Configuration.ht
293
320
 
294
321
  See this [list of contributors](https://github.com/freerange/mocha/graphs/contributors).
295
322
 
296
- ### Translations
297
-
298
- * [Serbo-Croatian](http://science.webhostinggeeks.com/mocha) by [WHG Team](http://webhostinggeeks.com/). (may be out-of-date)
299
-
300
323
  ### Releasing a new version
301
324
 
302
325
  * Update the RELEASE.md file with a summary of changes
303
326
  * Bump the version in `lib/mocha/version.rb`
304
- * Commit & push to Github
327
+ * Commit & push to GitHub
305
328
  * Check Travis CI build is passing - https://travis-ci.org/freerange/mocha
306
329
 
330
+ * Sign in to Google Analytics - https://analytics.google.com/analytics/web/
331
+ * Find the web property ID for floehopper (625523) > Mocha Documentation (UA-625523-7)
332
+ * Generate documentation:
333
+
334
+ ```bash
335
+ $ MOCHA_GENERATE_DOCS=true bundle install
336
+
337
+ $ MOCHA_GENERATE_DOCS=true GOOGLE_ANALYTICS_WEB_PROPERTY_ID=UA-625523-7 rake generate_docs
338
+ ```
339
+ * Commit documentation & push to GitHub
307
340
  * Sign in to rubygems.org and find API key - https://rubygems.org/profile/edit
308
341
 
309
342
  ```bash
310
343
  $ curl -u james@floehopper.org https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials`
311
344
  ```
312
345
 
313
- * Sign in to Google Analytics - https://analytics.google.com/analytics/web/
314
- * Find the web property ID for Go Free Range Ltd > Mocha Documentation (UA-45002715-2)
346
+ * Release gem to Rubygems:
315
347
 
316
348
  ```bash
317
- $ MOCHA_GENERATE_DOCS=true bundle install
318
-
319
- $ MOCHA_GENERATE_DOCS=true GOOGLE_ANALYTICS_WEB_PROPERTY_ID=UA-45002715-2 rake release
349
+ $ rake release
350
+ [runs tests]
320
351
  mocha 1.2.0 built to pkg/mocha-1.2.0.gem.
321
352
  Tagged v1.2.0.
322
353
  Pushed git commits and tags.
323
354
  Pushed mocha 1.2.0 to rubygems.org.
324
- [runs tests]
325
- [generates docs]
326
- [deploys docs]
327
355
  ```
328
356
 
329
357
  ### History
data/RELEASE.md CHANGED
@@ -1,5 +1,94 @@
1
1
  # Release Notes
2
2
 
3
+ ## 1.10.2
4
+
5
+ * 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):
6
+ * The behaviour of `API#mock`, `API#stub` and `API#stub_everything` when called with a symbol as the first argument.
7
+ * The behaviour of `Expectation#yields` and `Expectation#multiple_yields` when the stubbed method is called without a block.
8
+
9
+ ## 1.10.1
10
+
11
+ * Ensure ObjectMethods & ClassMethods included when API extended (43778756)
12
+ * Fix regression in `any_instance` stubbing of methods on object which has an implementation of `#respond_to?` that depends on the object's internal state - thanks to @rafaelfranca for reporting & @nitishr for fixing (#432, #434, 469d4b17)
13
+
14
+ ## 1.10.0
15
+
16
+ * Improve deprecation warning when requiring 'mocha/setup' (388f44d7)
17
+ * Add documentation for Cucumber integration (13ab797b)
18
+ * Add documentation about an undocumented feature of `API#mock`, `API#stub` & `API#stub_everything` being changed (7ed2e4e7, d30c1717)
19
+
20
+ ## 1.10.0.beta.1
21
+
22
+ * Hide `ClassMethods#method_visibility` & `#method_exists?` methods to avoid clash with Rails (#428)
23
+
24
+ ## 1.10.0.alpha
25
+
26
+ ### External changes
27
+
28
+ * Remove dependency on metaclass gem (#49, #365)
29
+ * Accept symbol (as well as a string) as mock/stub name - thanks to @nitishr (#347, #353, #377)
30
+ * More realistic examples in documentation for `Expectation#yields` and `#multiple_yields` - thanks to @nitishr (#352, #383)
31
+ * Improve documentation for `Mock#responds_like` & `#responds_like_instance_of` - thanks to @nitishr (#337, #384)
32
+ * Make `Expectation#yields` & `Expectation#multiple_yields` fail when the caller of the stubbed method does not provide a block. This is a change to an undocumented aspect of the public API's behaviour. If this causes your tests to fail, then fix it by removing the unnecessary call to `Expectation#yields` or `Expectation#multiple_yields` - thanks to @nitishr (#382)
33
+ * Document `MOCHA_OPTIONS` in README - thanks to @nitishr (#311, #386)
34
+ * Add documentation to explain how Mocha is intended to be used - thanks to @nitishr (#330, #385)
35
+ * Deprecation warning if integration using 'mocha/test_unit' or 'mocha/minitest' fails - thanks to @nitishr (#229, #389, c6032d0b)
36
+ * Require at least one specified sequence for `Expectation#in_sequence` - thanks to @nitishr (#79, #396, 9020248a)
37
+ * Make signatures of `Mock#unstub` & `ObjectMethods#unstub` consistent - thanks to @nitishr (#397, f04d437)
38
+ * Deprecate requiring 'mocha/setup' (36adf880)
39
+ * Optionally display matching invocations alongside expectations - thanks to @nitishr (#178, #394, 00f0540, #410)
40
+ * Put deprecations into effect (#400, #418):
41
+ * Remove deprecated 'mocha_standalone.rb' & 'mocha/standalone.rb'
42
+ * Fail fast if no test library loaded
43
+ * Removed optional block for `Mocha::API#mock`, `#stub` & `#stub_everything`
44
+ * Remove deprecated `ParameterMatchers#has_equivalent_query_string` method
45
+ * Remove deprecated 'mocha/mini_test.rb'
46
+ * Fix typo in docs for `Mocha::Configuration.prevent` (266ce71c)
47
+ * New-style configuration (see documentation for `Mocha::Configuration`) (#407, #421)
48
+ * Deprecate support for Ruby versions earlier than v1.9 (#325, c5f8496d)
49
+ * Deprecate support for versions of test-unit & minitest which need monkey-patching (a34e1a88)
50
+ * Deprecate old-style Rails plugin (#403, 2df77134)
51
+ * Documentation fixes & improvements which also fix YARD warnings (472d5416, a2c0d64a)
52
+
53
+ ### Internal changes
54
+
55
+ * Pin minitest to v5.11.3 for Ruby v1.8.7 to fix build; minitest no longer supports Ruby v1.8.7 (4a0a580)
56
+ * Upgrade JRuby to v9.2.8.0 in Travis CI builds (aa29b3f)
57
+ * Only run rubocop for MRI Ruby versions & non-integration test builds (8f1c6af)
58
+ * Reduce duplication in any instance method class - thanks to @nitishr (#378)
59
+ * Simplify `AnyInstanceMethod`, `ClassMethod`, `InstanceMethod`, `ModuleMethod` class hierarchy - thanks to @nitishr (#381)
60
+ * Simplify `ClassMethods#method_exists?` & `ObjectMethods#method_exists?` making them consistent - thanks to @nitishr (#270, #362, #370)
61
+ * Don't override definition of `singleton_class` in `ClassMethods` - thanks to @nitishr (#391, #392)
62
+ * Do not include 'method_definer' methods into all objects (#268, #402)
63
+ * Distinguish different `ObjectMethods` modules (#268, #404)
64
+ * Pass invocation to expectation list methods - thanks to @nitishr (#408, #409, #411)
65
+ * Consistently use `assert_raises` - thanks to @nitishr (#405, #412, a66b7bed)
66
+ * Update Ruby & JRuby versions in Travis CI config (18cb1a93, eb061c53)
67
+ * Rubocop improvements (aa16ea67...6f4db70b, 2a1240e6...e95716ae)
68
+ * Fix inconsistency in CardinalityTest (aa10e0a8)
69
+ * Fix test failures on Mac OSX Catalina - thanks to @nitishr (#413, #417, #419, 8a0f2535)
70
+ * Remove default argument in `Expectation#invoke` - thanks to @nitishr (#414, #420)
71
+
72
+ ## 1.9.0
73
+
74
+ * Add TruffleRuby to Travis CI build matrix - thanks to @deepj (#354)
75
+ * Explicitly set Travis CI OS to Ubuntu Trusty 14.04 (ded1fa45)
76
+ * Expand explanation of thread-safety concerns - thanks to @techbelly (#357)
77
+ * Refactor class method and any instance method - thanks to @chrisroos (#358)
78
+ * Rely on default bundler version in Travis CI builds (3352e9c5)
79
+ * Fix local build-matrix script (11abe231)
80
+ * No need to install latest bundler in build-matrix script (8247a894)
81
+
82
+ ## 1.8.0
83
+
84
+ * Constrain rubocop version to avoid breaking Travis CI builds (05e507f5)
85
+ * Avoid calling Kernel#format from ObjectMethods#mocha_inspect - thanks to @hoffmanilya (#345)
86
+ * Fix build matrix script (#346)
87
+ * Avoid deprecation warning in gemspec (4976e0bc)
88
+ * Removed link to documentation translation (ef428ea2)
89
+ * Don't use the new bundler v2 in builds (683ded9b)
90
+ * Moved documentation from https://gofreerange.com/mocha/docs to https://mocha.jamesmead.org/ [683ded...a17fde](https://github.com/freerange/mocha/compare/683ded...a17fde)
91
+
3
92
  ## 1.7.0
4
93
 
5
94
  * Update Ruby & JRuby versions in Travis CI config (9bf55631 & 3883af7e)
data/Rakefile CHANGED
@@ -2,8 +2,6 @@ require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
  require 'bundler/setup'
4
4
 
5
- MOCHA_DOCS_HOST = ENV['MOCHA_DOCS_HOST'] || 'gofreerange.com'
6
-
7
5
  require 'rake/testtask'
8
6
 
9
7
  desc 'Run all tests'
@@ -19,7 +17,7 @@ task 'test' do
19
17
  end
20
18
  end
21
19
 
22
- namespace 'test' do
20
+ namespace 'test' do # rubocop:disable Metrics/BlockLength
23
21
  unit_tests = FileList['test/unit/**/*_test.rb']
24
22
  all_acceptance_tests = FileList['test/acceptance/*_test.rb']
25
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']
@@ -87,13 +85,14 @@ end
87
85
 
88
86
  begin
89
87
  require 'rubocop/rake_task'
90
- if RUBY_VERSION >= '2.2.0'
88
+ if RUBY_VERSION >= '2.2.0' && (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby') && ENV['MOCHA_RUN_INTEGRATION_TESTS'].nil?
91
89
  RuboCop::RakeTask.new
92
90
  task 'test' => 'rubocop'
93
91
  end
94
92
  rescue LoadError # rubocop:disable Lint/HandleExceptions
95
93
  end
96
94
 
95
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
97
96
  def benchmark_test_case(klass, iterations)
98
97
  require 'benchmark'
99
98
  require 'mocha/detection/mini_test'
@@ -121,13 +120,14 @@ def benchmark_test_case(klass, iterations)
121
120
  Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, @silent_option) } }
122
121
  end
123
122
  end
123
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
124
124
 
125
125
  if ENV['MOCHA_GENERATE_DOCS']
126
126
  require 'yard'
127
127
 
128
128
  desc 'Remove generated documentation'
129
129
  task 'clobber_yardoc' do
130
- `rm -rf ./doc`
130
+ `rm -rf ./docs`
131
131
  end
132
132
 
133
133
  task 'docs_environment' do
@@ -138,19 +138,18 @@ 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 = ['--title', "Mocha #{Mocha::VERSION}"]
141
+ task.options = [
142
+ '--title', "Mocha #{Mocha::VERSION}",
143
+ '--output-dir', 'docs'
144
+ ]
142
145
  end
143
146
 
144
- desc 'Generate documentation'
145
- task 'generate_docs' => %w[clobber_yardoc yardoc]
146
-
147
- desc "Publish docs to #{MOCHA_DOCS_HOST}/docs/mocha"
148
- task 'publish_docs' => 'generate_docs' do
149
- path = '/home/freerange/docs/mocha'
150
- system %(ssh #{MOCHA_DOCS_HOST} "sudo rm -fr #{path} && mkdir -p #{path}" && scp -r doc/* #{MOCHA_DOCS_HOST}:#{path})
147
+ task 'checkout_docs_cname' do
148
+ `git checkout docs/CNAME`
151
149
  end
152
- end
153
150
 
154
- task 'release' => 'default' do
155
- Rake::Task['publish_docs'].invoke
151
+ desc 'Generate documentation'
152
+ task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname]
156
153
  end
154
+
155
+ task 'release' => 'default'
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'yaml'
4
+ require 'set'
5
+ require 'English'
4
6
 
5
7
  def execute(*commands)
6
8
  commands.each do |command|
@@ -39,6 +41,8 @@ def run(ruby_version, gemfile, task = 'test')
39
41
  )
40
42
  end
41
43
 
44
+ AVAILABLE_RUBY_VERSIONS = `rbenv versions --bare`.split("\n")
45
+
42
46
  travis_config = YAML.safe_load(File.read('.travis.yml'))
43
47
  build_configs = travis_config['matrix']['include']
44
48
  travis_config['rvm'].each do |ruby_version|
@@ -49,6 +53,8 @@ travis_config['rvm'].each do |ruby_version|
49
53
  end
50
54
  end
51
55
 
56
+ missing_ruby_versions = Set.new
57
+
52
58
  build_configs.each do |config|
53
59
  ruby_version = config['rvm']
54
60
  gemfile = config['gemfile']
@@ -59,11 +65,18 @@ build_configs.each do |config|
59
65
  original_environment_variables[k] = ENV[k]
60
66
  ENV[k] = v
61
67
  end
62
- p [ruby_version, gemfile, environment_variables]
63
- run(ruby_version, gemfile)
68
+ if AVAILABLE_RUBY_VERSIONS.include?(ruby_version)
69
+ puts
70
+ puts "Ruby v#{ruby_version}; Gemfile path: #{gemfile}; Environment: #{environment_variables}"
71
+ run(ruby_version, gemfile)
72
+ else
73
+ missing_ruby_versions << ruby_version
74
+ end
64
75
  ensure
65
76
  original_environment_variables.each do |k, v|
66
77
  ENV[k] = v
67
78
  end
68
79
  end
69
80
  end
81
+
82
+ puts "Missing Ruby versions: #{missing_ruby_versions.to_a.join(', ')}"