thewoolleyman-mocha 0.9.3.20081219131457

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/COPYING +3 -0
  2. data/MIT-LICENSE +7 -0
  3. data/README +35 -0
  4. data/RELEASE +257 -0
  5. data/Rakefile +199 -0
  6. data/examples/misc.rb +44 -0
  7. data/examples/mocha.rb +26 -0
  8. data/examples/stubba.rb +65 -0
  9. data/lib/mocha.rb +47 -0
  10. data/lib/mocha/any_instance_method.rb +54 -0
  11. data/lib/mocha/argument_iterator.rb +21 -0
  12. data/lib/mocha/backtrace_filter.rb +17 -0
  13. data/lib/mocha/cardinality.rb +95 -0
  14. data/lib/mocha/central.rb +27 -0
  15. data/lib/mocha/change_state_side_effect.rb +19 -0
  16. data/lib/mocha/class_method.rb +86 -0
  17. data/lib/mocha/configuration.rb +60 -0
  18. data/lib/mocha/deprecation.rb +22 -0
  19. data/lib/mocha/exception_raiser.rb +17 -0
  20. data/lib/mocha/expectation.rb +451 -0
  21. data/lib/mocha/expectation_error.rb +15 -0
  22. data/lib/mocha/expectation_list.rb +50 -0
  23. data/lib/mocha/in_state_ordering_constraint.rb +19 -0
  24. data/lib/mocha/inspect.rb +67 -0
  25. data/lib/mocha/instance_method.rb +16 -0
  26. data/lib/mocha/is_a.rb +9 -0
  27. data/lib/mocha/logger.rb +15 -0
  28. data/lib/mocha/metaclass.rb +13 -0
  29. data/lib/mocha/method_matcher.rb +21 -0
  30. data/lib/mocha/mini_test_adapter.rb +50 -0
  31. data/lib/mocha/mock.rb +200 -0
  32. data/lib/mocha/mockery.rb +181 -0
  33. data/lib/mocha/module_method.rb +16 -0
  34. data/lib/mocha/multiple_yields.rb +20 -0
  35. data/lib/mocha/names.rb +53 -0
  36. data/lib/mocha/no_yields.rb +11 -0
  37. data/lib/mocha/object.rb +187 -0
  38. data/lib/mocha/parameter_matchers.rb +27 -0
  39. data/lib/mocha/parameter_matchers/all_of.rb +42 -0
  40. data/lib/mocha/parameter_matchers/any_of.rb +47 -0
  41. data/lib/mocha/parameter_matchers/any_parameters.rb +40 -0
  42. data/lib/mocha/parameter_matchers/anything.rb +33 -0
  43. data/lib/mocha/parameter_matchers/base.rb +15 -0
  44. data/lib/mocha/parameter_matchers/equals.rb +42 -0
  45. data/lib/mocha/parameter_matchers/has_entries.rb +45 -0
  46. data/lib/mocha/parameter_matchers/has_entry.rb +56 -0
  47. data/lib/mocha/parameter_matchers/has_key.rb +42 -0
  48. data/lib/mocha/parameter_matchers/has_value.rb +42 -0
  49. data/lib/mocha/parameter_matchers/includes.rb +40 -0
  50. data/lib/mocha/parameter_matchers/instance_of.rb +42 -0
  51. data/lib/mocha/parameter_matchers/is_a.rb +42 -0
  52. data/lib/mocha/parameter_matchers/kind_of.rb +42 -0
  53. data/lib/mocha/parameter_matchers/not.rb +42 -0
  54. data/lib/mocha/parameter_matchers/object.rb +15 -0
  55. data/lib/mocha/parameter_matchers/optionally.rb +55 -0
  56. data/lib/mocha/parameter_matchers/regexp_matches.rb +43 -0
  57. data/lib/mocha/parameter_matchers/responds_with.rb +43 -0
  58. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +43 -0
  59. data/lib/mocha/parameters_matcher.rb +37 -0
  60. data/lib/mocha/pretty_parameters.rb +28 -0
  61. data/lib/mocha/return_values.rb +31 -0
  62. data/lib/mocha/sequence.rb +42 -0
  63. data/lib/mocha/single_return_value.rb +17 -0
  64. data/lib/mocha/single_yield.rb +18 -0
  65. data/lib/mocha/standalone.rb +166 -0
  66. data/lib/mocha/state_machine.rb +91 -0
  67. data/lib/mocha/stubbing_error.rb +16 -0
  68. data/lib/mocha/test_case_adapter.rb +103 -0
  69. data/lib/mocha/unexpected_invocation.rb +18 -0
  70. data/lib/mocha/yield_parameters.rb +31 -0
  71. data/lib/mocha_standalone.rb +2 -0
  72. data/lib/stubba.rb +4 -0
  73. data/test/acceptance/acceptance_test_helper.rb +38 -0
  74. data/test/acceptance/bug_18914_test.rb +43 -0
  75. data/test/acceptance/bug_21465_test.rb +34 -0
  76. data/test/acceptance/bug_21563_test.rb +25 -0
  77. data/test/acceptance/expected_invocation_count_test.rb +196 -0
  78. data/test/acceptance/failure_messages_test.rb +64 -0
  79. data/test/acceptance/minitest_test.rb +130 -0
  80. data/test/acceptance/mocha_example_test.rb +98 -0
  81. data/test/acceptance/mocha_test_result_test.rb +84 -0
  82. data/test/acceptance/mock_test.rb +100 -0
  83. data/test/acceptance/mock_with_initializer_block_test.rb +51 -0
  84. data/test/acceptance/mocked_methods_dispatch_test.rb +78 -0
  85. data/test/acceptance/optional_parameters_test.rb +70 -0
  86. data/test/acceptance/parameter_matcher_test.rb +209 -0
  87. data/test/acceptance/partial_mocks_test.rb +47 -0
  88. data/test/acceptance/return_value_test.rb +52 -0
  89. data/test/acceptance/sequence_test.rb +186 -0
  90. data/test/acceptance/standalone_test.rb +139 -0
  91. data/test/acceptance/states_test.rb +70 -0
  92. data/test/acceptance/stub_any_instance_method_test.rb +195 -0
  93. data/test/acceptance/stub_class_method_test.rb +203 -0
  94. data/test/acceptance/stub_everything_test.rb +56 -0
  95. data/test/acceptance/stub_instance_method_test.rb +203 -0
  96. data/test/acceptance/stub_module_method_test.rb +163 -0
  97. data/test/acceptance/stub_test.rb +52 -0
  98. data/test/acceptance/stubba_example_test.rb +102 -0
  99. data/test/acceptance/stubba_test.rb +15 -0
  100. data/test/acceptance/stubba_test_result_test.rb +66 -0
  101. data/test/acceptance/stubbing_error_backtrace_test.rb +64 -0
  102. data/test/acceptance/stubbing_method_unnecessarily_test.rb +65 -0
  103. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +130 -0
  104. data/test/acceptance/stubbing_non_existent_class_method_test.rb +157 -0
  105. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +147 -0
  106. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +130 -0
  107. data/test/acceptance/stubbing_non_public_class_method_test.rb +163 -0
  108. data/test/acceptance/stubbing_non_public_instance_method_test.rb +143 -0
  109. data/test/acceptance/stubbing_on_non_mock_object_test.rb +64 -0
  110. data/test/deprecation_disabler.rb +15 -0
  111. data/test/execution_point.rb +36 -0
  112. data/test/method_definer.rb +24 -0
  113. data/test/simple_counter.rb +13 -0
  114. data/test/test_helper.rb +11 -0
  115. data/test/test_runner.rb +33 -0
  116. data/test/unit/any_instance_method_test.rb +126 -0
  117. data/test/unit/array_inspect_test.rb +16 -0
  118. data/test/unit/backtrace_filter_test.rb +19 -0
  119. data/test/unit/cardinality_test.rb +56 -0
  120. data/test/unit/central_test.rb +65 -0
  121. data/test/unit/change_state_side_effect_test.rb +41 -0
  122. data/test/unit/class_method_test.rb +237 -0
  123. data/test/unit/date_time_inspect_test.rb +21 -0
  124. data/test/unit/exception_raiser_test.rb +42 -0
  125. data/test/unit/expectation_list_test.rb +57 -0
  126. data/test/unit/expectation_test.rb +459 -0
  127. data/test/unit/hash_inspect_test.rb +16 -0
  128. data/test/unit/in_state_ordering_constraint_test.rb +43 -0
  129. data/test/unit/metaclass_test.rb +22 -0
  130. data/test/unit/method_matcher_test.rb +23 -0
  131. data/test/unit/mock_test.rb +295 -0
  132. data/test/unit/mockery_test.rb +149 -0
  133. data/test/unit/multiple_yields_test.rb +18 -0
  134. data/test/unit/no_yields_test.rb +18 -0
  135. data/test/unit/object_inspect_test.rb +37 -0
  136. data/test/unit/object_test.rb +82 -0
  137. data/test/unit/parameter_matchers/all_of_test.rb +26 -0
  138. data/test/unit/parameter_matchers/any_of_test.rb +26 -0
  139. data/test/unit/parameter_matchers/anything_test.rb +21 -0
  140. data/test/unit/parameter_matchers/equals_test.rb +25 -0
  141. data/test/unit/parameter_matchers/has_entries_test.rb +51 -0
  142. data/test/unit/parameter_matchers/has_entry_test.rb +62 -0
  143. data/test/unit/parameter_matchers/has_key_test.rb +36 -0
  144. data/test/unit/parameter_matchers/has_value_test.rb +37 -0
  145. data/test/unit/parameter_matchers/includes_test.rb +25 -0
  146. data/test/unit/parameter_matchers/instance_of_test.rb +25 -0
  147. data/test/unit/parameter_matchers/is_a_test.rb +25 -0
  148. data/test/unit/parameter_matchers/kind_of_test.rb +25 -0
  149. data/test/unit/parameter_matchers/not_test.rb +26 -0
  150. data/test/unit/parameter_matchers/regexp_matches_test.rb +25 -0
  151. data/test/unit/parameter_matchers/responds_with_test.rb +25 -0
  152. data/test/unit/parameter_matchers/stub_matcher.rb +27 -0
  153. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +25 -0
  154. data/test/unit/parameters_matcher_test.rb +121 -0
  155. data/test/unit/return_values_test.rb +63 -0
  156. data/test/unit/sequence_test.rb +104 -0
  157. data/test/unit/single_return_value_test.rb +14 -0
  158. data/test/unit/single_yield_test.rb +18 -0
  159. data/test/unit/state_machine_test.rb +98 -0
  160. data/test/unit/string_inspect_test.rb +11 -0
  161. data/test/unit/yield_parameters_test.rb +93 -0
  162. metadata +226 -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,35 @@
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 colleagues Ben[http://www.techbelly.com/], Chris[http://blog.seagul.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 svn://rubyforge.org/var/svn/mocha/trunk
20
+
21
+ Or download Mocha from here - http://rubyforge.org/projects/mocha
22
+
23
+ == Examples
24
+
25
+ * Quick Start - {Usage Examples}[link:examples/misc.html]
26
+ * Traditional mocking - {Star Trek Example}[link:examples/mocha.html]
27
+ * Setting expectations on real classes - {Order Example}[link:examples/stubba.html]
28
+ * More examples on {Floehopper's Blog}[http://blog.floehopper.org]
29
+ * {Mailing List Archives}[http://groups.google.com/group/mocha-developer]
30
+
31
+ == License
32
+
33
+ Copyright Revieworld Ltd. 2006
34
+
35
+ 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,257 @@
1
+ = 0.9.3 (8219bb2d2881c8529c93fc21e97a11d01203c759)
2
+ * Added support for MiniTest thanks to sprsquish.
3
+ * Fixed a possible bug with some of the non-default Configuration options relating to the argument to Object#respond_to?
4
+ * 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
5
+ * Removed deprecated gem autorequire.
6
+
7
+ = 0.9.2 (r355)
8
+ * Improved documentation to address [#22530] 'Mock methods with multiple return values not possible?'
9
+ * respond_with parameter matcher was not available in tests.
10
+ * 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.
11
+
12
+ = 0.9.1 (r349)
13
+
14
+ * 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.
15
+ * By removing Mock#unexpected_method_called we reduce the number of methods vulnerable to the problem that surfaced in bug #21563.
16
+ * Fix bug #21563 - stubbing 'verified?' method is unsafe. Instance method names on the Mock class should be more obscure.
17
+ * Performance improvement. StubbaExampleTest goes twice as fast on my local machine.
18
+ * Added primitive performance test to default rake task.
19
+ * Fix format of case statements which don't work in Ruby 1.9 and make others consistent.
20
+ * 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.
21
+ * Fix for bug #21161 - 'uninitialized constant Deprecation in stubba.rb'.
22
+ * It's more readable to talk about 'once' and 'twice' rather than '1 time' and '2 times'.
23
+ * 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.
24
+
25
+ = 0.9.0 (r316)
26
+
27
+ * Configurable warnings or errors
28
+ * when a method on a non-public method is stubbed
29
+ * when a method on a non-existent method is stubbed
30
+ * when a method on a non-mock object is stubbed
31
+ * when a method is stubbed unnecessarily (i.e. the stubbed method is not called during the test)
32
+
33
+ * Improved error messages
34
+ * User-friendly list of unsatisfied expectations, satisfied expectations and state machines.
35
+ * Improved readability of cardinality description.
36
+ * Display sensible failure message for any_instance expectations e.g. "#<AnyInstance:Foo>.bar - expected calls: 1, actual calls: 0"
37
+
38
+ * Parameter matchers
39
+ * New to this release
40
+ * optionally (allows matching of optional parameters if available)
41
+ * yaml_equivalent (allows matching of YAML that represents the specified object)
42
+ * responds_with (tests the quack not the duck)
43
+ * Nesting of parameter matchers is now supported.
44
+
45
+ * 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.
46
+
47
+ * Added JMock-style sequences for constraining the order of expected invocations. See Standalone#sequence and Expectation#in_sequence.
48
+
49
+ * Added JMock-style states for constraining the order of expected invocations. See Standalone#states, Expectation#then, Expectation#when and StateMachine.
50
+
51
+ * Compatibility with versions of Ruby
52
+ * Compatibility with Ruby v1.9. All test errors and warnings fixed.
53
+ * Nasty fix so that TestCaseAdaptor works consistently with earlier versions of Test::Unit as well as more recent versions.
54
+ * 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.
55
+ * 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.
56
+
57
+ * Added deprecation warning in stubba.rb which is no longer needed and will be removed.
58
+
59
+ * Supply positioning information to evals to improve any error messages. See http://ola-bini.blogspot.com/2008/01/ruby-antipattern-using-eval-without.html
60
+
61
+ * Bug fixes
62
+ * 18914 in revision 296 - http://rubyforge.org/tracker/index.php?func=detail&aid=18914&group_id=1917&atid=7477
63
+ * 18917 in revision 295 - http://rubyforge.org/tracker/index.php?func=detail&aid=18917&group_id=1917&atid=7477
64
+ * 18336 in revision 287 - http://rubyforge.org/tracker/index.php?func=detail&aid=18336&group_id=1917&atid=7477
65
+ * 17835 in revision 255 - http://rubyforge.org/tracker/index.php?func=detail&aid=17835&group_id=1917&atid=7477
66
+ * 17412 in revision 242 - http://rubyforge.org/tracker/index.php?func=detail&aid=17412&group_id=1917&atid=7477
67
+ * 15977 in revision 198 - http://rubyforge.org/tracker/index.php?func=detail&aid=15977&group_id=1917&atid=7477
68
+ * 11885 in revision 156 - http://rubyforge.org/tracker/index.php?func=detail&aid=11885&group_id=1917&atid=7477
69
+
70
+ = 0.5.5 (r167)
71
+
72
+ - Renamed Matches parameter matcher to RegexpMatches for clarity.
73
+ - Added noframes tag to rdoc index to assist Google.
74
+
75
+ = 0.5.4 (r166)
76
+
77
+ - Added matches parameter matcher for matching regular expressions.
78
+
79
+ = 0.5.3 (r165)
80
+
81
+ - Attempt to fix packaging problems by switching to newer version (1.15.1) of gnutar and setting COPY_EXTENDED_ATTRIBUTES_DISABLE environment variable.
82
+ - Removed unused ExpectationSequenceError exception.
83
+ - Added instance_of and kind_of parameter matchers.
84
+ - Added Google Webmaster meta tag to rdoc template header.
85
+ - Put Google Webmaster meta tag in the right header i.e. the one for the index page.
86
+
87
+ = 0.5.2 (r159)
88
+
89
+ - 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).
90
+ - 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.
91
+
92
+ = 0.5.1 (r149)
93
+
94
+ - 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.
95
+
96
+ = 0.5.0 (r147)
97
+
98
+ - 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.
99
+
100
+ object = mock()
101
+ object.expects(:method).with(has_key('key_1'))
102
+ object.method('key_1' => 1, 'key_2' => 2)
103
+ # no verification error raised
104
+
105
+ object = mock()
106
+ object.expects(:method).with(has_key('key_1'))
107
+ object.method('key_2' => 2)
108
+ # verification error raised, because method was not called with Hash containing key: 'key_1'
109
+
110
+ - 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.
111
+
112
+ object = mock()
113
+ object.stubs(:method).returns(1, 2).then.raises(Exception).then.returns(4)
114
+ object.method # => 1
115
+ object.method # => 2
116
+ object.method # => raises exception of class Exception
117
+ object.method # => 4
118
+
119
+ - Yields on Consecutive Invocations - Allow multiple calls to yields on single expectation to allow yield parameters to be specified for consecutive invocations.
120
+
121
+ object = mock()
122
+ object.stubs(:method).yields(1, 2).then.yields(3)
123
+ object.method { |*values| p values } # => [1, 2]
124
+ object.method { |*values| p values } # => [3]
125
+
126
+ - Multiple Yields on Single Invocation - Added Expectation#multiple_yields to allow a mocked or stubbed method to yield multiple times for a single invocation.
127
+
128
+ object = mock()
129
+ object.stubs(:method).multiple_yields([1, 2], [3])
130
+ object.method { |*values| p values } # => [1, 2] # => [3]
131
+
132
+ - 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.
133
+
134
+ object = mock()
135
+ object.stubs(:method).returns(2)
136
+ object.expects(:method).once.returns(1)
137
+ object.method # => 1
138
+ object.method # => 2
139
+ object.method # => 2
140
+ # no verification error raised
141
+
142
+ # The following should still work...
143
+
144
+ Time.stubs(:now).returns(Time.parse('Mon Jan 01 00:00:00 UTC 2007'))
145
+ Time.now # => Mon Jan 01 00:00:00 UTC 2007
146
+ Time.stubs(:now).returns(Time.parse('Thu Feb 01 00:00:00 UTC 2007'))
147
+ Time.now # => Thu Feb 01 00:00:00 UTC 2007
148
+
149
+ - Deprecate passing an instance of Proc to Expectation#returns.
150
+ - Explicitly include all Rakefile dependencies in project.
151
+ - Fixed old Stubba example.
152
+ - Fix so that it is possible for a stubbed method to raise an Interrupt exception without a message in Ruby 1.8.6
153
+ - Added responds_like and quacks_like.
154
+ - Capture standard object methods before Mocha adds any.
155
+ - Added Expectation#once method to make interface less surprising.
156
+ - 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.
157
+ - Fiddled with mocha_inspect and tests to give more sensible results on x86 platform.
158
+ - Fixed bug #7834 "infinite_range.rb makes incorrect assumption about to_f" logged by James Moore.
159
+
160
+ = 0.4.0 (r92)
161
+
162
+ - Allow naming of mocks (patch from Chris Roos).
163
+ - Specify multiple return values for consecutive calls.
164
+ - Improved consistency of expectation error messages.
165
+ - Allow mocking of Object instance methods e.g. kind_of?, type.
166
+ - Provide aliased versions of #expects and #stubs to allow mocking of these methods.
167
+ - Added at_least, at_most, at_most_once methods to expectation.
168
+ - Allow expects and stubs to take a hash of method and return values.
169
+ - Eliminate warning: "instance variable @yield not initialized" (patch from Xavier Shay).
170
+ - Restore instance methods on partial mocks (patch from Chris Roos).
171
+ - Allow stubbing of a method with non-word characters in its name (patch from Paul Battley).
172
+ - Removed coupling to Test::Unit.
173
+ - Allow specified exception instance to be raised (patch from Chris Roos).
174
+ - Make mock object_id appear in hex like normal Ruby inspect (patch from Paul Battley).
175
+ - Fix path to object.rb in rdoc rake task (patch from Tomas Pospisek).
176
+ - 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).
177
+ - Stubba & SmartTestCase modules incorporated into Mocha module so only need to require 'mocha' - no longer need to require 'stubba'.
178
+ - AutoMocha removed.
179
+
180
+ = 0.3.3
181
+
182
+ - Quick bug fix to restore instance methods on partial mocks (for Kevin Clark).
183
+
184
+ = 0.3.2
185
+
186
+ - Examples added.
187
+
188
+ = 0.3.1
189
+
190
+ - Dual licensing with MIT license added.
191
+
192
+ = 0.3.0
193
+
194
+ * Rails plugin.
195
+ * Auto-verify for expectations on concrete classes.
196
+ * Include each expectation verification in the test result assertion count.
197
+ * Filter out noise from assertion backtraces.
198
+ * Point assertion backtrace to line where failing expectation was created.
199
+ * New yields method for expectations.
200
+ * Create stubs which stub all method calls.
201
+ * Mocks now respond_to? expected methods.
202
+
203
+ = 0.2.1
204
+
205
+ * Rename MochaAcceptanceTest::Rover#move method to avoid conflict with Rake (in Ruby 1.8.4 only?)
206
+
207
+ = 0.2.0
208
+
209
+ * 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).
210
+ * Reorganized directory structure and extracted addition of setup and teardown methods into SmartTestCase mini-library.
211
+ * 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.
212
+
213
+ So instead of...
214
+
215
+ wotsit = Mocha.new
216
+ wotsit.expects(:thingummy).with(5).returns(10)
217
+ doobrey = Doobrey.new(wotsit)
218
+ doobrey.hoojamaflip
219
+ wotsit.verify
220
+
221
+ you need to do...
222
+
223
+ wotsit = mock()
224
+ wotsit.expects(:thingummy).with(5).returns(10)
225
+ doobrey = Doobrey.new(wotsit)
226
+ doobrey.hoojamaflip
227
+ # no need to verify
228
+
229
+ There are also shortcuts as follows...
230
+
231
+ instead of...
232
+
233
+ wotsit = Mocha.new
234
+ wotsit.expects(:thingummy).returns(10)
235
+ wotsit.expects(:summat).returns(25)
236
+
237
+ you can have...
238
+
239
+ wotsit = mock(:thingummy => 5, :summat => 25)
240
+
241
+ and instead of...
242
+
243
+ wotsit = Mocha.new
244
+ wotsit.stubs(:thingummy).returns(10)
245
+ wotsit.stubs(:summat).returns(25)
246
+
247
+ you can have...
248
+
249
+ wotsit = stub(:thingummy => 5, :summat => 25)
250
+
251
+ = 0.1.2
252
+
253
+ * Minor tweaks
254
+
255
+ = 0.1.1
256
+
257
+ * Initial release.
data/Rakefile ADDED
@@ -0,0 +1,199 @@
1
+ require 'rubygems'
2
+ require 'rake/rdoctask'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/testtask'
5
+ require 'rake/contrib/sshpublisher'
6
+
7
+ module Mocha
8
+ VERSION = "0.9.3"
9
+ end
10
+
11
+ desc "Run all tests"
12
+ task 'default' => ['test:units', 'test:acceptance', 'test:performance']
13
+
14
+ namespace 'test' do
15
+
16
+ unit_tests = FileList['test/unit/**/*_test.rb']
17
+ acceptance_tests = FileList['test/acceptance/*_test.rb']
18
+
19
+ desc "Run unit tests"
20
+ Rake::TestTask.new('units') do |t|
21
+ t.libs << 'test'
22
+ t.test_files = unit_tests
23
+ t.verbose = true
24
+ t.warning = true
25
+ end
26
+
27
+ desc "Run acceptance tests"
28
+ Rake::TestTask.new('acceptance') do |t|
29
+ t.libs << 'test'
30
+ t.test_files = acceptance_tests
31
+ t.verbose = true
32
+ t.warning = true
33
+ end
34
+
35
+ # require 'rcov/rcovtask'
36
+ # Rcov::RcovTask.new('coverage') do |t|
37
+ # t.libs << 'test'
38
+ # t.test_files = unit_tests + acceptance_tests
39
+ # t.verbose = true
40
+ # t.warning = true
41
+ # t.rcov_opts << '--sort coverage'
42
+ # t.rcov_opts << '--xref'
43
+ # end
44
+
45
+ desc "Run performance tests"
46
+ task 'performance' do
47
+ require 'test/acceptance/stubba_example_test'
48
+ require 'test/acceptance/mocha_example_test'
49
+ iterations = 1000
50
+ puts "\nBenchmarking with #{iterations} iterations..."
51
+ [MochaExampleTest, StubbaExampleTest].each do |test_case|
52
+ puts "#{test_case}: #{benchmark_test_case(test_case, iterations)} seconds."
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ def benchmark_test_case(klass, iterations)
59
+ require 'test/unit/ui/console/testrunner'
60
+ require 'benchmark'
61
+ time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, Test::Unit::UI::SILENT) } }
62
+ end
63
+
64
+ desc 'Generate RDoc'
65
+ Rake::RDocTask.new('rdoc') do |task|
66
+ task.main = 'README'
67
+ task.title = "Mocha #{Mocha::VERSION}"
68
+ task.rdoc_dir = 'doc'
69
+ task.template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics"))
70
+ task.rdoc_files.include(
71
+ 'README',
72
+ 'RELEASE',
73
+ 'COPYING',
74
+ 'MIT-LICENSE',
75
+ 'agiledox.txt',
76
+ 'lib/mocha/standalone.rb',
77
+ 'lib/mocha/mock.rb',
78
+ 'lib/mocha/expectation.rb',
79
+ 'lib/mocha/object.rb',
80
+ 'lib/mocha/parameter_matchers.rb',
81
+ 'lib/mocha/parameter_matchers',
82
+ 'lib/mocha/state_machine.rb',
83
+ 'lib/mocha/configuration.rb',
84
+ 'lib/mocha/stubbing_error.rb'
85
+ )
86
+ end
87
+ task 'rdoc' => 'examples'
88
+
89
+ desc "Upload RDoc to RubyForge"
90
+ task 'publish_rdoc' => ['rdoc', 'examples'] do
91
+ Rake::SshDirPublisher.new("jamesmead@rubyforge.org", "/var/www/gforge-projects/mocha", "doc").upload
92
+ end
93
+
94
+ desc "Generate agiledox-like documentation for tests"
95
+ file 'agiledox.txt' do
96
+ File.open('agiledox.txt', 'w') do |output|
97
+ tests = FileList['test/**/*_test.rb']
98
+ tests.each do |file|
99
+ m = %r".*/([^/].*)_test.rb".match(file)
100
+ output << m[1]+" should:\n"
101
+ test_definitions = File::readlines(file).select {|line| line =~ /.*def test.*/}
102
+ test_definitions.sort.each do |definition|
103
+ m = %r"test_(should_)?(.*)".match(definition)
104
+ output << " - "+m[2].gsub(/_/," ") << "\n"
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ desc "Convert example ruby files to syntax-highlighted html"
111
+ task 'examples' do
112
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "vendor", "coderay-0.7.4.215", "lib"))
113
+ require 'coderay'
114
+ mkdir_p 'doc/examples'
115
+ File.open('doc/examples/coderay.css', 'w') do |output|
116
+ output << CodeRay::Encoders[:html]::CSS.new.stylesheet
117
+ end
118
+ ['mocha', 'stubba', 'misc'].each do |filename|
119
+ File.open("doc/examples/#{filename}.html", 'w') do |file|
120
+ file << "<html>"
121
+ file << "<head>"
122
+ file << %q(<link rel="stylesheet" media="screen" href="coderay.css" type="text/css">)
123
+ file << "</head>"
124
+ file << "<body>"
125
+ file << CodeRay.scan_file("examples/#{filename}.rb").html.div
126
+ file << "</body>"
127
+ file << "</html>"
128
+ end
129
+ end
130
+ end
131
+
132
+ Gem.manage_gems if Gem::RubyGemsVersion < '1.2.0'
133
+
134
+ def build_specification(version = Mocha::VERSION)
135
+ Gem::Specification.new do |s|
136
+ s.name = "mocha"
137
+ s.summary = "Mocking and stubbing library"
138
+ s.version = version
139
+ s.platform = Gem::Platform::RUBY
140
+ s.author = 'James Mead'
141
+ s.description = <<-EOF
142
+ Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
143
+ EOF
144
+ s.email = 'mocha-developer@rubyforge.org'
145
+ s.homepage = 'http://mocha.rubyforge.org'
146
+ s.rubyforge_project = 'mocha'
147
+
148
+ s.has_rdoc = true
149
+ s.extra_rdoc_files = ['README', 'COPYING']
150
+ s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers'
151
+
152
+ s.add_dependency('rake')
153
+ s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
154
+ end
155
+ end
156
+
157
+ specification = build_specification
158
+
159
+ Rake::GemPackageTask.new(specification) do |package|
160
+ package.need_zip = true
161
+ package.need_tar = true
162
+ end
163
+
164
+ desc 'Generate updated gemspec with unique version, which will cause gem to be auto-built on github.'
165
+ task :update_gemspec do
166
+ File.open('mocha.gemspec', 'w') do |output|
167
+ output << build_specification(Mocha::VERSION + '.' + Time.now.strftime('%Y%m%d%H%M%S')).to_ruby
168
+ end
169
+ end
170
+
171
+
172
+ task 'verify_user' do
173
+ raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
174
+ end
175
+
176
+ task 'verify_password' do
177
+ raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
178
+ end
179
+
180
+ desc "Publish package files on RubyForge."
181
+ task 'publish_packages' => ['verify_user', 'verify_password', 'package'] do
182
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "vendor", "meta_project-0.4.15", "lib"))
183
+ require 'meta_project'
184
+ require 'rake/contrib/xforge'
185
+ release_files = FileList[
186
+ "pkg/mocha-#{Mocha::VERSION}.gem",
187
+ "pkg/mocha-#{Mocha::VERSION}.tgz",
188
+ "pkg/mocha-#{Mocha::VERSION}.zip"
189
+ ]
190
+
191
+ Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new('mocha')) do |release|
192
+ release.user_name = ENV['RUBYFORGE_USER']
193
+ release.password = ENV['RUBYFORGE_PASSWORD']
194
+ release.files = release_files.to_a
195
+ release.release_name = "Mocha #{Mocha::VERSION}"
196
+ release.release_changes = ''
197
+ release.release_notes = ''
198
+ end
199
+ end