mocha-macruby 0.9.8.20100129120100

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. data/COPYING +3 -0
  2. data/MIT-LICENSE +7 -0
  3. data/README +39 -0
  4. data/RELEASE +294 -0
  5. data/Rakefile +214 -0
  6. data/examples/misc.rb +43 -0
  7. data/examples/mocha.rb +25 -0
  8. data/examples/stubba.rb +64 -0
  9. data/lib/mocha.rb +3 -0
  10. data/lib/mocha/any_instance_method.rb +59 -0
  11. data/lib/mocha/api.rb +173 -0
  12. data/lib/mocha/argument_iterator.rb +21 -0
  13. data/lib/mocha/backtrace_filter.rb +17 -0
  14. data/lib/mocha/cardinality.rb +95 -0
  15. data/lib/mocha/central.rb +27 -0
  16. data/lib/mocha/change_state_side_effect.rb +19 -0
  17. data/lib/mocha/class_method.rb +117 -0
  18. data/lib/mocha/configuration.rb +79 -0
  19. data/lib/mocha/deprecation.rb +22 -0
  20. data/lib/mocha/exception_raiser.rb +17 -0
  21. data/lib/mocha/expectation.rb +476 -0
  22. data/lib/mocha/expectation_error.rb +15 -0
  23. data/lib/mocha/expectation_list.rb +50 -0
  24. data/lib/mocha/in_state_ordering_constraint.rb +19 -0
  25. data/lib/mocha/inspect.rb +67 -0
  26. data/lib/mocha/instance_method.rb +16 -0
  27. data/lib/mocha/integration.rb +38 -0
  28. data/lib/mocha/integration/mini_test.rb +21 -0
  29. data/lib/mocha/integration/mini_test/assertion_counter.rb +23 -0
  30. data/lib/mocha/integration/mini_test/version_131_and_above.rb +50 -0
  31. data/lib/mocha/integration/test_unit.rb +40 -0
  32. data/lib/mocha/integration/test_unit/assertion_counter.rb +23 -0
  33. data/lib/mocha/integration/test_unit/gem_version_200.rb +49 -0
  34. data/lib/mocha/integration/test_unit/gem_version_201_and_above.rb +49 -0
  35. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +48 -0
  36. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +50 -0
  37. data/lib/mocha/is_a.rb +9 -0
  38. data/lib/mocha/logger.rb +15 -0
  39. data/lib/mocha/metaclass.rb +13 -0
  40. data/lib/mocha/method_matcher.rb +21 -0
  41. data/lib/mocha/mock.rb +200 -0
  42. data/lib/mocha/mockery.rb +181 -0
  43. data/lib/mocha/module_method.rb +16 -0
  44. data/lib/mocha/multiple_yields.rb +20 -0
  45. data/lib/mocha/names.rb +53 -0
  46. data/lib/mocha/no_yields.rb +11 -0
  47. data/lib/mocha/object.rb +187 -0
  48. data/lib/mocha/parameter_matchers.rb +27 -0
  49. data/lib/mocha/parameter_matchers/all_of.rb +42 -0
  50. data/lib/mocha/parameter_matchers/any_of.rb +47 -0
  51. data/lib/mocha/parameter_matchers/any_parameters.rb +40 -0
  52. data/lib/mocha/parameter_matchers/anything.rb +33 -0
  53. data/lib/mocha/parameter_matchers/base.rb +15 -0
  54. data/lib/mocha/parameter_matchers/equals.rb +42 -0
  55. data/lib/mocha/parameter_matchers/has_entries.rb +45 -0
  56. data/lib/mocha/parameter_matchers/has_entry.rb +57 -0
  57. data/lib/mocha/parameter_matchers/has_key.rb +43 -0
  58. data/lib/mocha/parameter_matchers/has_value.rb +43 -0
  59. data/lib/mocha/parameter_matchers/includes.rb +41 -0
  60. data/lib/mocha/parameter_matchers/instance_of.rb +42 -0
  61. data/lib/mocha/parameter_matchers/is_a.rb +42 -0
  62. data/lib/mocha/parameter_matchers/kind_of.rb +42 -0
  63. data/lib/mocha/parameter_matchers/not.rb +42 -0
  64. data/lib/mocha/parameter_matchers/object.rb +15 -0
  65. data/lib/mocha/parameter_matchers/optionally.rb +55 -0
  66. data/lib/mocha/parameter_matchers/regexp_matches.rb +44 -0
  67. data/lib/mocha/parameter_matchers/responds_with.rb +43 -0
  68. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +43 -0
  69. data/lib/mocha/parameters_matcher.rb +37 -0
  70. data/lib/mocha/pretty_parameters.rb +28 -0
  71. data/lib/mocha/return_values.rb +31 -0
  72. data/lib/mocha/sequence.rb +42 -0
  73. data/lib/mocha/single_return_value.rb +17 -0
  74. data/lib/mocha/single_yield.rb +18 -0
  75. data/lib/mocha/standalone.rb +1 -0
  76. data/lib/mocha/state_machine.rb +91 -0
  77. data/lib/mocha/stubbing_error.rb +16 -0
  78. data/lib/mocha/unexpected_invocation.rb +18 -0
  79. data/lib/mocha/yield_parameters.rb +31 -0
  80. data/lib/mocha_standalone.rb +2 -0
  81. data/lib/stubba.rb +4 -0
  82. data/test/acceptance/acceptance_test_helper.rb +38 -0
  83. data/test/acceptance/api_test.rb +139 -0
  84. data/test/acceptance/bug_18914_test.rb +43 -0
  85. data/test/acceptance/bug_21465_test.rb +34 -0
  86. data/test/acceptance/bug_21563_test.rb +25 -0
  87. data/test/acceptance/expected_invocation_count_test.rb +196 -0
  88. data/test/acceptance/failure_messages_test.rb +64 -0
  89. data/test/acceptance/minitest_test.rb +153 -0
  90. data/test/acceptance/mocha_example_test.rb +98 -0
  91. data/test/acceptance/mocha_test_result_test.rb +84 -0
  92. data/test/acceptance/mock_test.rb +100 -0
  93. data/test/acceptance/mock_with_initializer_block_test.rb +51 -0
  94. data/test/acceptance/mocked_methods_dispatch_test.rb +78 -0
  95. data/test/acceptance/optional_parameters_test.rb +70 -0
  96. data/test/acceptance/parameter_matcher_test.rb +209 -0
  97. data/test/acceptance/partial_mocks_test.rb +47 -0
  98. data/test/acceptance/return_value_test.rb +52 -0
  99. data/test/acceptance/sequence_test.rb +186 -0
  100. data/test/acceptance/states_test.rb +70 -0
  101. data/test/acceptance/stub_any_instance_method_test.rb +195 -0
  102. data/test/acceptance/stub_class_method_test.rb +203 -0
  103. data/test/acceptance/stub_everything_test.rb +56 -0
  104. data/test/acceptance/stub_instance_method_test.rb +203 -0
  105. data/test/acceptance/stub_module_method_test.rb +163 -0
  106. data/test/acceptance/stub_test.rb +52 -0
  107. data/test/acceptance/stubba_example_test.rb +102 -0
  108. data/test/acceptance/stubba_test.rb +15 -0
  109. data/test/acceptance/stubba_test_result_test.rb +66 -0
  110. data/test/acceptance/stubbing_error_backtrace_test.rb +64 -0
  111. data/test/acceptance/stubbing_method_unnecessarily_test.rb +65 -0
  112. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +130 -0
  113. data/test/acceptance/stubbing_non_existent_class_method_test.rb +157 -0
  114. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +147 -0
  115. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +130 -0
  116. data/test/acceptance/stubbing_non_public_class_method_test.rb +163 -0
  117. data/test/acceptance/stubbing_non_public_instance_method_test.rb +143 -0
  118. data/test/acceptance/stubbing_on_non_mock_object_test.rb +64 -0
  119. data/test/deprecation_disabler.rb +15 -0
  120. data/test/execution_point.rb +36 -0
  121. data/test/method_definer.rb +24 -0
  122. data/test/simple_counter.rb +13 -0
  123. data/test/test_helper.rb +25 -0
  124. data/test/test_runner.rb +33 -0
  125. data/test/unit/any_instance_method_test.rb +126 -0
  126. data/test/unit/array_inspect_test.rb +16 -0
  127. data/test/unit/backtrace_filter_test.rb +19 -0
  128. data/test/unit/cardinality_test.rb +56 -0
  129. data/test/unit/central_test.rb +65 -0
  130. data/test/unit/change_state_side_effect_test.rb +41 -0
  131. data/test/unit/class_method_test.rb +295 -0
  132. data/test/unit/configuration_test.rb +38 -0
  133. data/test/unit/date_time_inspect_test.rb +21 -0
  134. data/test/unit/exception_raiser_test.rb +42 -0
  135. data/test/unit/expectation_list_test.rb +57 -0
  136. data/test/unit/expectation_test.rb +480 -0
  137. data/test/unit/hash_inspect_test.rb +16 -0
  138. data/test/unit/in_state_ordering_constraint_test.rb +43 -0
  139. data/test/unit/metaclass_test.rb +22 -0
  140. data/test/unit/method_matcher_test.rb +23 -0
  141. data/test/unit/mock_test.rb +302 -0
  142. data/test/unit/mockery_test.rb +149 -0
  143. data/test/unit/multiple_yields_test.rb +18 -0
  144. data/test/unit/no_yields_test.rb +18 -0
  145. data/test/unit/object_inspect_test.rb +37 -0
  146. data/test/unit/object_test.rb +82 -0
  147. data/test/unit/parameter_matchers/all_of_test.rb +26 -0
  148. data/test/unit/parameter_matchers/any_of_test.rb +26 -0
  149. data/test/unit/parameter_matchers/anything_test.rb +21 -0
  150. data/test/unit/parameter_matchers/equals_test.rb +25 -0
  151. data/test/unit/parameter_matchers/has_entries_test.rb +51 -0
  152. data/test/unit/parameter_matchers/has_entry_test.rb +82 -0
  153. data/test/unit/parameter_matchers/has_key_test.rb +55 -0
  154. data/test/unit/parameter_matchers/has_value_test.rb +57 -0
  155. data/test/unit/parameter_matchers/includes_test.rb +44 -0
  156. data/test/unit/parameter_matchers/instance_of_test.rb +25 -0
  157. data/test/unit/parameter_matchers/is_a_test.rb +25 -0
  158. data/test/unit/parameter_matchers/kind_of_test.rb +25 -0
  159. data/test/unit/parameter_matchers/not_test.rb +26 -0
  160. data/test/unit/parameter_matchers/regexp_matches_test.rb +46 -0
  161. data/test/unit/parameter_matchers/responds_with_test.rb +25 -0
  162. data/test/unit/parameter_matchers/stub_matcher.rb +27 -0
  163. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +25 -0
  164. data/test/unit/parameters_matcher_test.rb +121 -0
  165. data/test/unit/return_values_test.rb +63 -0
  166. data/test/unit/sequence_test.rb +104 -0
  167. data/test/unit/single_return_value_test.rb +14 -0
  168. data/test/unit/single_yield_test.rb +18 -0
  169. data/test/unit/state_machine_test.rb +98 -0
  170. data/test/unit/string_inspect_test.rb +11 -0
  171. data/test/unit/yield_parameters_test.rb +93 -0
  172. metadata +240 -0
data/COPYING ADDED
@@ -0,0 +1,3 @@
1
+ Copyright Revieworld Ltd. 2006
2
+
3
+ You may use, copy and redistribute this library under the same terms as Ruby itself (see http://www.ruby-lang.org/en/LICENSE.txt) or under the MIT license (see MIT-LICENSE file).
data/MIT-LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2006 Revieworld Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,39 @@
1
+ = Mocha
2
+
3
+ Mocha is a library for mocking and stubbing using a syntax like that of JMock[http://www.jmock.org].
4
+
5
+ It can be used with many testing frameworks e.g. Test::Unit[http://www.ruby-doc.org/core/classes/Test/Unit.html], RSpec[http://rspec.info/], test/spec[http://chneukirchen.org/repos/testspec/README], expectations[http://expectations.rubyforge.org/], Dust[http://dust.rubyforge.org/], MiniTest[http://rubyforge.org/projects/bfts] and even JtestR[http://jtestr.codehaus.org/].
6
+
7
+ Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking.
8
+
9
+ Mocha was harvested from projects at Reevoo[http://www.reevoo.com] by me (James[http://blog.floehopper.org]) and my (then) colleagues Ben[http://www.techbelly.com/], Chris[http://chrisroos.co.uk] and Paul[http://po-ru.com].
10
+
11
+ == Download and Installation
12
+
13
+ Install the gem with the following command...
14
+
15
+ $ gem install mocha
16
+
17
+ Or install the Rails[http://www.rubyonrails.org] plugin...
18
+
19
+ $ script/plugin install git://github.com/floehopper/mocha.git
20
+
21
+ Note that versions 0.9.6 & 0.9.7 of the Rails plugin were broken. As of version 0.9.8, you need to explicitly load Mocha after the test framework e.g. by adding "require 'mocha'" at the bottom of test/test_helper.rb.
22
+
23
+ Or download Mocha...
24
+
25
+ http://rubyforge.org/frs/?group_id=1917
26
+
27
+ == Examples
28
+
29
+ * Quick Start - {Usage Examples}[link:examples/misc.html]
30
+ * Traditional mocking - {Star Trek Example}[link:examples/mocha.html]
31
+ * Setting expectations on real classes - {Order Example}[link:examples/stubba.html]
32
+ * More examples on {Floehopper's Blog}[http://blog.floehopper.org]
33
+ * {Mailing List Archives}[http://groups.google.com/group/mocha-developer]
34
+
35
+ == License
36
+
37
+ Copyright Revieworld Ltd. 2006
38
+
39
+ You may use, copy and redistribute this library under the same terms as {Ruby itself}[http://www.ruby-lang.org/en/LICENSE.txt] or under the {MIT license}[http://mocha.rubyforge.org/files/MIT-LICENSE.html].
data/RELEASE ADDED
@@ -0,0 +1,294 @@
1
+ = 0.9.8 (645024765b2d92018efc511652e1174163844e39)
2
+ * Fixed bug "NameError raised when using Mocha as a Rails plug-in" - http://floehopper.lighthouseapp.com/projects/22289/tickets/53. Since 0.9.6 the Rails plugin has been broken. See bug report for details. You will need to explicitly load Mocha *after* the test framework has been loaded, e.g. by adding "require 'mocha'" at the bottom of test/test_helper.rb.
3
+ * Make Mocha::ParameterMatchers#regexp_matches, #includes, #has_value, #has_key more robust. Thanks to Sander Hartlage.
4
+ * Allow passing a block to Mocha::Configuration methods to only change configuration for the duration of the block. Thanks to Dan Manges.
5
+ * Fixed bug "doc generation fails in 0.9.7 gem" - http://floehopper.lighthouseapp.com/projects/22289/tickets/51.
6
+ * Remove rdoc template incorporating google analytics from source control. The file just needs to exist locally and be ignored by source control. This should stop the warning showing up on e.g. RunCodeRun build results.
7
+
8
+ = 0.9.7 (80d816f250dc13aaf856f3f9cbd97ebe9c371839)
9
+ * Although I had provided a deprecation warning for people using Mocha::Standalone, I had assumed people wouldn't be explicitly loading the mocha/standalone.rb file. It turns out this assumption was incorrect at least in the case of Rspec. This is now fixed.
10
+
11
+ = 0.9.6 (57f8f77d715b7f1d9efee2e1a9438f7905c0006b)
12
+ * Version 2.0.1 of the test-unit gem introduced a private 'run_test' method on TestCase which clashed with the public TestRunner#run_test method. So this latter method has been renamed to 'run_as_test'.
13
+ * Stop requiring rubygems - this should be an environmental choice for the user. http://gist.github.com/54177 - describes why requiring rubygems in your library code is a bad idea.
14
+ * It seems like overkill to vendorize coderay and meta_project when they're only needed to generate the examples for documentation and for publishing files on RubyForge. So I'm removing them and installing them locally as gems when I need them.
15
+ * Added support for 'test-unit' gem (version >= 2.0). Note that as with other versions of Test::Unit I'm completely replacing the TestCase#run method. Unfortunately in version 2.0.0 this method differs slightly from the same method in version 2.0.1 & 2.0.2, so we have to provide different implementations to ensure that the internal working of Test::Unit are not compromised by Mocha. Note also that unless the 'test-unit' gem is loaded, requiring 'test/unit' leads to a mixture of stdlib and gem classes being loaded causing errors. To avoid a dependency on rubygems, the gem is loaded only if MOCHA_OPTIONS is set to 'use_test_unit_gem' - this option is only intended for use in running Mocha's own tests. It might be worthwhile to create a shim gem like minitest_tu_shim to allow the test-unit gem to completely replace the stdlib, but that's a job for another day. The changes in the Rakefile are to make the default task run with the 'test-unit' gem (version >= 2.0).
16
+ * Renamed Mocha::Standalone to Mocha::API to better reflect its purpose. Added a deprecation warning for those who are referencing Mocha::Standalone.
17
+ * Fix exception raised by HasEntry#matches? if first param is not a Hash (thanks to Taylor Barstow).
18
+ * Ken Collins reported [1] that Mocha is always loading MiniTest if it is available and loading it causes some Rails/ActionPack tests to break. I've removed the loading of MiniTest, but this now means the user has to ensure that if they want to use MiniTest in conjunction with Mocha, he must load MiniTest before loading Mocha. [1] http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2060
19
+ * Implemented Bacon integration (thanks to Ubiratan Pires Alberton), but this was then removed after deciding only to maintain integration with Test::Unit and MiniTest which are both Ruby standard libraries. See mailing list for details.
20
+ * Don't monkey-patch MiniTest if it's already been monkey-patched by Mocha.
21
+ * Fixed bug: MiniTest integration was counting ExpectationErrors as errors not failures. http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/41.
22
+ * Fixed bug: Some Bacon tests were failing in Ruby 1.9.1. http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/43.
23
+ * Chad Humphries pointed out that in Ruby 1.9.1, if you are not using Test::Unit or MiniTest, Mocha will attempt to load and monkey-patch Test::Unit. Mocha will now only monkey-patch Test::Unit and/or MiniTest if they have already been loaded. MiniTest tests will now run in both Ruby 1.8.6 (with MiniTest gem) and in Ruby 1.9.1 (with MiniTest std lib). See Ligthouse ticket - http://floehopper.lighthouseapp.com/projects/22289/tickets/49.
24
+ * Made Mocha compatible with minitest 1.4.0 and above (thanks to Denis Defreyne).
25
+
26
+ = 0.9.5 (93cad010345ce5d68f31422cfc32ed9dd6de13ec)
27
+ * Fixed Lighthouse bug #32 - stub_everything should mean mock responds to anything.
28
+ * Added Expectation#twice to improve readability. Thanks to pull request from Celestino Gomes.
29
+ * In Ruby 1.9.1, requiring 'test/unit' loads a thin wrapper around MiniTest and Test::Unit::TestCase ends up inheriting from MiniTest::Unit::TestCase. So we need to avoid including the Mocha modules more than once to avoid nasty consequences. Thanks to Matthias Hennemeyer for help with this.
30
+ * Ruby 1.9 includes rake, but not rake/contrib. For the moment I've moved the sshpublisher require into the only rake task that needs it, so that I can at least run the tests in Ruby 1.9. It looks like I will need to build a rake/contrib gem or similar to get this working properly - http://intertwingly.net/blog/2008/01/07/Rake-Contrib-for-1-9
31
+
32
+ = 0.9.4 (8a59c6ff0f99f34b02bd99f19536a7893be2b340)
33
+ * Added mocha.gemspec file generated with Chad Woolley's new rake task, so that a floehopper-mocha gem will get built on GitHub.
34
+ * Add rake task to update mocha.gemspec with unique version, which will cause gem to be auto-built on github
35
+ * As Tobias Crawley correctly pointed out in feature request #23055 "stubs(with_hash) not working with existing object" [1], following the principle of least surprise, it should be possible to call ObjectMethods#expects & ObjectMethods#stubs with a Hash of method_names vs return_values like you can with Mock#expects & Mock#stubs. I've also updated & improved the docs to reflect the changes. [1] http://rubyforge.org/tracker/index.php?func=detail&aid=23055&group_id=1917&atid=7480
36
+ * Removed deprecated gem autorequire.
37
+
38
+ = 0.9.3 (8219bb2d2881c8529c93fc21e97a11d01203c759)
39
+ * Added support for MiniTest thanks to Jeff Smick.
40
+ * Fixed a possible bug with some of the non-default Configuration options relating to the argument to Object#respond_to?
41
+ * As per Jay Fields recommendations [1] and with further impetus from a talk at Ruby Manor, any methods added to core classes are now added by including a module. This means that Mocha is a better citizen of the Ruby world and it's behaviour is more easily extended. [1] http://blog.jayfields.com/2008/07/ruby-underuse-of-modules.html & http://blog.jayfields.com/2008/07/ruby-redefine-method-behavior.html
42
+ * Removed deprecated gem autorequire.
43
+
44
+ = 0.9.2 (r355)
45
+ * Improved documentation to address [#22530] 'Mock methods with multiple return values not possible?'
46
+ * respond_with parameter matcher was not available in tests.
47
+ * Patch [#22630] Fix for a bug in running Rails tests with Ruby 1.8.7. Array#flatten was being called which in turn was checking whether each element responded to #to_ary. This check was using the two parameter version of #respond_to?, but Mock was only defining a one parameter version.
48
+
49
+ = 0.9.1 (r349)
50
+
51
+ * Fixed bug #21465 - expects & stubs should support method names as strings (as well as symbols) or fail fast. Convert all expectation method names to a symbol in case they were supplied as a string.
52
+ * By removing Mock#unexpected_method_called we reduce the number of methods vulnerable to the problem that surfaced in bug #21563.
53
+ * Fix bug #21563 - stubbing 'verified?' method is unsafe. Instance method names on the Mock class should be more obscure.
54
+ * Performance improvement. StubbaExampleTest goes twice as fast on my local machine.
55
+ * Added primitive performance test to default rake task.
56
+ * Fix format of case statements which don't work in Ruby 1.9 and make others consistent.
57
+ * There is no point in running (potentially expensive) checks if configuration is set to allow such checks to fail. This is a relatively quick fix in response to Chris McGrath's performance problems.
58
+ * Fix for bug #21161 - 'uninitialized constant Deprecation in stubba.rb'.
59
+ * It's more readable to talk about 'once' and 'twice' rather than '1 time' and '2 times'.
60
+ * Fix bug #20883 - never should raise when called to prevent follow up errors. Fail fast when there are no matching invokable expectations and handle the stub_everything case sensibly. This might not be entirely backwards compatible, but I think the benefits outweigh the risks. The most likely change is that a test that was already failing will now fail faster, which doesn't seem so awful.
61
+
62
+ = 0.9.0 (r316)
63
+
64
+ * Configurable warnings or errors
65
+ * when a method on a non-public method is stubbed
66
+ * when a method on a non-existent method is stubbed
67
+ * when a method on a non-mock object is stubbed
68
+ * when a method is stubbed unnecessarily (i.e. the stubbed method is not called during the test)
69
+
70
+ * Improved error messages
71
+ * User-friendly list of unsatisfied expectations, satisfied expectations and state machines.
72
+ * Improved readability of cardinality description.
73
+ * Display sensible failure message for any_instance expectations e.g. "#<AnyInstance:Foo>.bar - expected calls: 1, actual calls: 0"
74
+
75
+ * Parameter matchers
76
+ * New to this release
77
+ * optionally (allows matching of optional parameters if available)
78
+ * yaml_equivalent (allows matching of YAML that represents the specified object)
79
+ * responds_with (tests the quack not the duck)
80
+ * Nesting of parameter matchers is now supported.
81
+
82
+ * Optional block passed into mock initializer is evaluated in the context of the new mock instance and can be used as a shortcut to set up expectations.
83
+
84
+ * Added JMock-style sequences for constraining the order of expected invocations. See Standalone#sequence and Expectation#in_sequence.
85
+
86
+ * Added JMock-style states for constraining the order of expected invocations. See Standalone#states, Expectation#then, Expectation#when and StateMachine.
87
+
88
+ * Compatibility with versions of Ruby
89
+ * Compatibility with Ruby v1.9. All test errors and warnings fixed.
90
+ * Nasty fix so that TestCaseAdaptor works consistently with earlier versions of Test::Unit as well as more recent versions.
91
+ * Added platform to gem specification to avoid bug in rubygems 0.9.5 - see http://www.dcmanges.com/blog/rubygems-0-9-5-platform-bug and http://rubygems.org/read/chapter/20#platform.
92
+ * Make ExpectationRaiser deal with subclasses of Interrupt which seem to need a message supplied in the raise statement in Ruby 1.8.6 (but not 1.8.4 or 1.9). Not sure this is really Mocha's responsibility.
93
+
94
+ * Added deprecation warning in stubba.rb which is no longer needed and will be removed.
95
+
96
+ * Supply positioning information to evals to improve any error messages. See http://ola-bini.blogspot.com/2008/01/ruby-antipattern-using-eval-without.html
97
+
98
+ * Bug fixes
99
+ * 18914 in revision 296 - http://rubyforge.org/tracker/index.php?func=detail&aid=18914&group_id=1917&atid=7477
100
+ * 18917 in revision 295 - http://rubyforge.org/tracker/index.php?func=detail&aid=18917&group_id=1917&atid=7477
101
+ * 18336 in revision 287 - http://rubyforge.org/tracker/index.php?func=detail&aid=18336&group_id=1917&atid=7477
102
+ * 17835 in revision 255 - http://rubyforge.org/tracker/index.php?func=detail&aid=17835&group_id=1917&atid=7477
103
+ * 17412 in revision 242 - http://rubyforge.org/tracker/index.php?func=detail&aid=17412&group_id=1917&atid=7477
104
+ * 15977 in revision 198 - http://rubyforge.org/tracker/index.php?func=detail&aid=15977&group_id=1917&atid=7477
105
+ * 11885 in revision 156 - http://rubyforge.org/tracker/index.php?func=detail&aid=11885&group_id=1917&atid=7477
106
+
107
+ = 0.5.5 (r167)
108
+
109
+ - Renamed Matches parameter matcher to RegexpMatches for clarity.
110
+ - Added noframes tag to rdoc index to assist Google.
111
+
112
+ = 0.5.4 (r166)
113
+
114
+ - Added matches parameter matcher for matching regular expressions.
115
+
116
+ = 0.5.3 (r165)
117
+
118
+ - Attempt to fix packaging problems by switching to newer version (1.15.1) of gnutar and setting COPY_EXTENDED_ATTRIBUTES_DISABLE environment variable.
119
+ - Removed unused ExpectationSequenceError exception.
120
+ - Added instance_of and kind_of parameter matchers.
121
+ - Added Google Webmaster meta tag to rdoc template header.
122
+ - Put Google Webmaster meta tag in the right header i.e. the one for the index page.
123
+
124
+ = 0.5.2 (r159)
125
+
126
+ - Fix bug 11885 - "never doesn't work with stub_everything" submitted by Alexander Lang. In fixing this bug, also fixed undiscoverd bug where expected & actual invocation counts were being incorrectly reported which seems to have been introduced when fixes were added for invocation dispatch (see MockedMethodDispatchAcceptanceTest).
127
+ - Previously when an expectation did not allow more invocations, it was treated as not matching. Now we prefer matching expectations which allow more invocations, but still match expectations which cannot allow more invocations. I think this may be overcomplicating things, but let's see how it goes.
128
+
129
+ = 0.5.1 (r149)
130
+
131
+ - Fixed bug #11583 "Mocha 0.5.0 throwing unexpected warnings". Also switched on ruby warning for all rake test tasks. Fixed majority of warnings, but some left to fix.
132
+
133
+ = 0.5.0 (r147)
134
+
135
+ - Parameter Matchers - I’ve added a few Hamcrest-style parameter matchers which are designed to be used inside Expectation#with. The following matchers are currently available: anything(), includes(), has_key(), has_value(), has_entry(), all_of() & any_of(). More to follow soon. The idea is eventually to get rid of the nasty parameter_block option on Expectation#with.
136
+
137
+ object = mock()
138
+ object.expects(:method).with(has_key('key_1'))
139
+ object.method('key_1' => 1, 'key_2' => 2)
140
+ # no verification error raised
141
+
142
+ object = mock()
143
+ object.expects(:method).with(has_key('key_1'))
144
+ object.method('key_2' => 2)
145
+ # verification error raised, because method was not called with Hash containing key: 'key_1'
146
+
147
+ - Values Returned and Exceptions Raised on Consecutive Invocations - Allow multiple calls to Expectation#returns and Expectation#raises to build up a sequence of responses to invocations on the mock. Added syntactic sugar method Expectation#then to allow more readable expectations.
148
+
149
+ object = mock()
150
+ object.stubs(:method).returns(1, 2).then.raises(Exception).then.returns(4)
151
+ object.method # => 1
152
+ object.method # => 2
153
+ object.method # => raises exception of class Exception
154
+ object.method # => 4
155
+
156
+ - Yields on Consecutive Invocations - Allow multiple calls to yields on single expectation to allow yield parameters to be specified for consecutive invocations.
157
+
158
+ object = mock()
159
+ object.stubs(:method).yields(1, 2).then.yields(3)
160
+ object.method { |*values| p values } # => [1, 2]
161
+ object.method { |*values| p values } # => [3]
162
+
163
+ - Multiple Yields on Single Invocation - Added Expectation#multiple_yields to allow a mocked or stubbed method to yield multiple times for a single invocation.
164
+
165
+ object = mock()
166
+ object.stubs(:method).multiple_yields([1, 2], [3])
167
+ object.method { |*values| p values } # => [1, 2] # => [3]
168
+
169
+ - Invocation Dispatch - Expectations were already being matched in reverse order i.e. the most recently defined one was being found first. This is still the case, but we now stop matching an expectation when its maximum number of expected invocations is reached. c.f. JMock v1. A stub will never stop matching by default. Hopefully this means we can soon get rid of the need to pass a Proc to Expectation#returns.
170
+
171
+ object = mock()
172
+ object.stubs(:method).returns(2)
173
+ object.expects(:method).once.returns(1)
174
+ object.method # => 1
175
+ object.method # => 2
176
+ object.method # => 2
177
+ # no verification error raised
178
+
179
+ # The following should still work...
180
+
181
+ Time.stubs(:now).returns(Time.parse('Mon Jan 01 00:00:00 UTC 2007'))
182
+ Time.now # => Mon Jan 01 00:00:00 UTC 2007
183
+ Time.stubs(:now).returns(Time.parse('Thu Feb 01 00:00:00 UTC 2007'))
184
+ Time.now # => Thu Feb 01 00:00:00 UTC 2007
185
+
186
+ - Deprecate passing an instance of Proc to Expectation#returns.
187
+ - Explicitly include all Rakefile dependencies in project.
188
+ - Fixed old Stubba example.
189
+ - Fix so that it is possible for a stubbed method to raise an Interrupt exception without a message in Ruby 1.8.6
190
+ - Added responds_like and quacks_like.
191
+ - Capture standard object methods before Mocha adds any.
192
+ - Added Expectation#once method to make interface less surprising.
193
+ - Use Rake::TestTask to run tests. Created three separate tasks to run unit, integration & acceptance tests. Split inspect_test into one file per TestCase. Deleted superfluous all_tests file.
194
+ - Fiddled with mocha_inspect and tests to give more sensible results on x86 platform.
195
+ - Fixed bug #7834 "infinite_range.rb makes incorrect assumption about to_f" logged by James Moore.
196
+
197
+ = 0.4.0 (r92)
198
+
199
+ - Allow naming of mocks (patch from Chris Roos).
200
+ - Specify multiple return values for consecutive calls.
201
+ - Improved consistency of expectation error messages.
202
+ - Allow mocking of Object instance methods e.g. kind_of?, type.
203
+ - Provide aliased versions of #expects and #stubs to allow mocking of these methods.
204
+ - Added at_least, at_most, at_most_once methods to expectation.
205
+ - Allow expects and stubs to take a hash of method and return values.
206
+ - Eliminate warning: "instance variable @yield not initialized" (patch from Xavier Shay).
207
+ - Restore instance methods on partial mocks (patch from Chris Roos).
208
+ - Allow stubbing of a method with non-word characters in its name (patch from Paul Battley).
209
+ - Removed coupling to Test::Unit.
210
+ - Allow specified exception instance to be raised (patch from Chris Roos).
211
+ - Make mock object_id appear in hex like normal Ruby inspect (patch from Paul Battley).
212
+ - Fix path to object.rb in rdoc rake task (patch from Tomas Pospisek).
213
+ - Reverse order in which expectations are matched, so that last expectation is matched first. This allows e.g. a call to #stubs to be effectively overridden by a call to #expects (patch from Tobias Lutke).
214
+ - Stubba & SmartTestCase modules incorporated into Mocha module so only need to require 'mocha' - no longer need to require 'stubba'.
215
+ - AutoMocha removed.
216
+
217
+ = 0.3.3
218
+
219
+ - Quick bug fix to restore instance methods on partial mocks (for Kevin Clark).
220
+
221
+ = 0.3.2
222
+
223
+ - Examples added.
224
+
225
+ = 0.3.1
226
+
227
+ - Dual licensing with MIT license added.
228
+
229
+ = 0.3.0
230
+
231
+ * Rails plugin.
232
+ * Auto-verify for expectations on concrete classes.
233
+ * Include each expectation verification in the test result assertion count.
234
+ * Filter out noise from assertion backtraces.
235
+ * Point assertion backtrace to line where failing expectation was created.
236
+ * New yields method for expectations.
237
+ * Create stubs which stub all method calls.
238
+ * Mocks now respond_to? expected methods.
239
+
240
+ = 0.2.1
241
+
242
+ * Rename MochaAcceptanceTest::Rover#move method to avoid conflict with Rake (in Ruby 1.8.4 only?)
243
+
244
+ = 0.2.0
245
+
246
+ * Small change to SetupAndTeardown#teardown_stubs suggested by Luke Redpath (http://www.lukeredpath.co.uk) to allow use of Stubba with RSpec (http://rspec.rubyforge.org).
247
+ * Reorganized directory structure and extracted addition of setup and teardown methods into SmartTestCase mini-library.
248
+ * Addition of auto-verify for Mocha (but not Stubba). This means there is more significance in the choice of expects or stubs in that any expects on a mock will automatically get verified.
249
+
250
+ So instead of...
251
+
252
+ wotsit = Mocha.new
253
+ wotsit.expects(:thingummy).with(5).returns(10)
254
+ doobrey = Doobrey.new(wotsit)
255
+ doobrey.hoojamaflip
256
+ wotsit.verify
257
+
258
+ you need to do...
259
+
260
+ wotsit = mock()
261
+ wotsit.expects(:thingummy).with(5).returns(10)
262
+ doobrey = Doobrey.new(wotsit)
263
+ doobrey.hoojamaflip
264
+ # no need to verify
265
+
266
+ There are also shortcuts as follows...
267
+
268
+ instead of...
269
+
270
+ wotsit = Mocha.new
271
+ wotsit.expects(:thingummy).returns(10)
272
+ wotsit.expects(:summat).returns(25)
273
+
274
+ you can have...
275
+
276
+ wotsit = mock(:thingummy => 5, :summat => 25)
277
+
278
+ and instead of...
279
+
280
+ wotsit = Mocha.new
281
+ wotsit.stubs(:thingummy).returns(10)
282
+ wotsit.stubs(:summat).returns(25)
283
+
284
+ you can have...
285
+
286
+ wotsit = stub(:thingummy => 5, :summat => 25)
287
+
288
+ = 0.1.2
289
+
290
+ * Minor tweaks
291
+
292
+ = 0.1.1
293
+
294
+ * Initial release.
data/Rakefile ADDED
@@ -0,0 +1,214 @@
1
+ require 'rake/rdoctask'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+
5
+ module Mocha
6
+ VERSION = "0.9.8"
7
+ end
8
+
9
+ desc "Run all tests"
10
+ task 'default' => ['test:units', 'test:acceptance', 'test:performance']
11
+
12
+ namespace 'test' do
13
+
14
+ unit_tests = FileList['test/unit/**/*_test.rb']
15
+ acceptance_tests = FileList['test/acceptance/*_test.rb']
16
+
17
+ desc "Run unit tests"
18
+ Rake::TestTask.new('units') do |t|
19
+ t.libs << 'test'
20
+ t.test_files = unit_tests
21
+ t.verbose = true
22
+ t.warning = true
23
+ end
24
+
25
+ desc "Run acceptance tests"
26
+ Rake::TestTask.new('acceptance') do |t|
27
+ t.libs << 'test'
28
+ t.test_files = acceptance_tests
29
+ t.verbose = true
30
+ t.warning = true
31
+ end
32
+
33
+ # require 'rcov/rcovtask'
34
+ # Rcov::RcovTask.new('coverage') do |t|
35
+ # t.libs << 'test'
36
+ # t.test_files = unit_tests + acceptance_tests
37
+ # t.verbose = true
38
+ # t.warning = true
39
+ # t.rcov_opts << '--sort coverage'
40
+ # t.rcov_opts << '--xref'
41
+ # end
42
+
43
+ desc "Run performance tests"
44
+ task 'performance' do
45
+ require 'test/acceptance/stubba_example_test'
46
+ require 'test/acceptance/mocha_example_test'
47
+ iterations = 1000
48
+ puts "\nBenchmarking with #{iterations} iterations..."
49
+ [MochaExampleTest, StubbaExampleTest].each do |test_case|
50
+ puts "#{test_case}: #{benchmark_test_case(test_case, iterations)} seconds."
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ def benchmark_test_case(klass, iterations)
57
+ require 'benchmark'
58
+ require 'test/unit/ui/console/testrunner'
59
+ begin
60
+ require 'test/unit/ui/console/outputlevel'
61
+ silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT }
62
+ rescue LoadError
63
+ silent_option = Test::Unit::UI::SILENT
64
+ end
65
+ time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, silent_option) } }
66
+ end
67
+
68
+ desc 'Generate RDoc'
69
+ Rake::RDocTask.new('rdoc') do |task|
70
+ task.main = 'README'
71
+ task.title = "Mocha #{Mocha::VERSION}"
72
+ task.rdoc_dir = 'doc'
73
+ template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics.rb"))
74
+ if File.exist?(template)
75
+ puts "*** Using RDoc template incorporating Google Analytics"
76
+ task.template = template
77
+ end
78
+ task.rdoc_files.include(
79
+ 'README',
80
+ 'RELEASE',
81
+ 'COPYING',
82
+ 'MIT-LICENSE',
83
+ 'agiledox.txt',
84
+ 'lib/mocha/api.rb',
85
+ 'lib/mocha/mock.rb',
86
+ 'lib/mocha/expectation.rb',
87
+ 'lib/mocha/object.rb',
88
+ 'lib/mocha/parameter_matchers.rb',
89
+ 'lib/mocha/parameter_matchers',
90
+ 'lib/mocha/state_machine.rb',
91
+ 'lib/mocha/configuration.rb',
92
+ 'lib/mocha/stubbing_error.rb'
93
+ )
94
+ end
95
+
96
+ desc "Generate all documentation"
97
+ task 'generate_docs' => ['clobber_rdoc', 'rdoc', 'examples', 'agiledox.txt']
98
+
99
+ desc "Upload RDoc to RubyForge"
100
+ task 'publish_docs' do
101
+ require 'rake/contrib/sshpublisher'
102
+ Rake::SshDirPublisher.new("jamesmead@rubyforge.org", "/var/www/gforge-projects/mocha", "doc").upload
103
+ end
104
+
105
+ desc "Generate agiledox-like documentation for tests"
106
+ file 'agiledox.txt' do
107
+ File.open('agiledox.txt', 'w') do |output|
108
+ tests = FileList['test/**/*_test.rb']
109
+ tests.each do |file|
110
+ m = %r".*/([^/].*)_test.rb".match(file)
111
+ output << m[1]+" should:\n"
112
+ test_definitions = File::readlines(file).select {|line| line =~ /.*def test.*/}
113
+ test_definitions.sort.each do |definition|
114
+ m = %r"test_(should_)?(.*)".match(definition)
115
+ output << " - "+m[2].gsub(/_/," ") << "\n"
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ desc "Convert example ruby files to syntax-highlighted html"
122
+ task 'examples' do
123
+ require 'coderay'
124
+ mkdir_p 'doc/examples'
125
+ File.open('doc/examples/coderay.css', 'w') do |output|
126
+ output << CodeRay::Encoders[:html]::CSS.new.stylesheet
127
+ end
128
+ ['mocha', 'stubba', 'misc'].each do |filename|
129
+ File.open("doc/examples/#{filename}.html", 'w') do |file|
130
+ file << "<html>"
131
+ file << "<head>"
132
+ file << %q(<link rel="stylesheet" media="screen" href="coderay.css" type="text/css">)
133
+ file << "</head>"
134
+ file << "<body>"
135
+ file << CodeRay.scan_file("examples/#{filename}.rb").html.div
136
+ file << "</body>"
137
+ file << "</html>"
138
+ end
139
+ end
140
+ end
141
+
142
+ Gem.manage_gems if Gem::RubyGemsVersion < '1.2.0'
143
+
144
+ def build_specification(version = Mocha::VERSION)
145
+ Gem::Specification.new do |s|
146
+ s.name = "mocha"
147
+ s.summary = "Mocking and stubbing library"
148
+ s.version = version
149
+ s.platform = Gem::Platform::RUBY
150
+ s.author = 'James Mead'
151
+ s.description = <<-EOF
152
+ Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
153
+ EOF
154
+ s.email = 'mocha-developer@googlegroups.com'
155
+ s.homepage = 'http://mocha.rubyforge.org'
156
+ s.rubyforge_project = 'mocha'
157
+
158
+ s.has_rdoc = true
159
+ s.extra_rdoc_files = ['README', 'COPYING']
160
+ s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers'
161
+
162
+ s.add_dependency('rake')
163
+ s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
164
+ end
165
+ end
166
+
167
+ specification = build_specification
168
+
169
+ Rake::GemPackageTask.new(specification) do |package|
170
+ package.need_zip = true
171
+ package.need_tar = true
172
+ end
173
+
174
+ desc 'Generate updated gemspec with unique version, which will cause gem to be auto-built on github.'
175
+ task :update_gemspec do
176
+ File.open('mocha.gemspec', 'w') do |output|
177
+ output << build_specification(Mocha::VERSION + '.' + Time.now.strftime('%Y%m%d%H%M%S')).to_ruby
178
+ end
179
+ end
180
+
181
+ task 'verify_user' do
182
+ raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
183
+ end
184
+
185
+ task 'verify_password' do
186
+ raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
187
+ end
188
+
189
+ desc "Publish package files on RubyForge."
190
+ task 'publish_packages' => ['verify_user', 'verify_password', 'clobber_package', 'package'] do
191
+ require 'meta_project'
192
+ require 'rake/contrib/xforge'
193
+ release_files = FileList[
194
+ "pkg/mocha-#{Mocha::VERSION}.gem",
195
+ "pkg/mocha-#{Mocha::VERSION}.tgz",
196
+ "pkg/mocha-#{Mocha::VERSION}.zip"
197
+ ]
198
+
199
+ Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new('mocha')) do |release|
200
+ release.user_name = ENV['RUBYFORGE_USER']
201
+ release.password = ENV['RUBYFORGE_PASSWORD']
202
+ release.files = release_files.to_a
203
+ release.release_name = "Mocha #{Mocha::VERSION}"
204
+ release.release_changes = ''
205
+ release.release_notes = ''
206
+ end
207
+ end
208
+
209
+ desc "Do a full release."
210
+ task 'release' => ['default', 'generate_docs', 'publish_packages', 'publish_docs', 'update_gemspec'] do
211
+ puts
212
+ puts "*** Remember to commit newly generated gemspec after release ***"
213
+ puts
214
+ end