Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tagging 0.5.2 release again after previously removing it.

  • Loading branch information...
commit 42e586753376b77f6a33a6c08dd346dc8c75352c 2 parents 8190023 + e3cb50a
@floehopper floehopper authored
Showing with 2 additions and 19,762 deletions.
  1. +2 −0  lib/mocha/mock.rb
  2. +0 −39 lib/mocha/parameter_matchers/instance_of.rb
  3. +0 −39 lib/mocha/parameter_matchers/kind_of.rb
  4. +0 −25 test/unit/parameter_matchers/instance_of_test.rb
  5. +0 −25 test/unit/parameter_matchers/kind_of_test.rb
  6. +0 −3  trunk/COPYING
  7. +0 −7 trunk/MIT-LICENSE
  8. +0 −35 trunk/README
  9. +0 −233 trunk/RELEASE
  10. +0 −171 trunk/Rakefile
  11. +0 −50 trunk/TODO
  12. +0 −44 trunk/examples/misc.rb
  13. +0 −26 trunk/examples/mocha.rb
  14. +0 −65 trunk/examples/stubba.rb
  15. +0 −3  trunk/init.rb
  16. +0 −20 trunk/lib/mocha.rb
  17. +0 −55 trunk/lib/mocha/any_instance_method.rb
  18. +0 −17 trunk/lib/mocha/backtrace_filter.rb
  19. +0 −92 trunk/lib/mocha/cardinality.rb
  20. +0 −27 trunk/lib/mocha/central.rb
  21. +0 −19 trunk/lib/mocha/change_state_side_effect.rb
  22. +0 −86 trunk/lib/mocha/class_method.rb
  23. +0 −60 trunk/lib/mocha/configuration.rb
  24. +0 −22 trunk/lib/mocha/deprecation.rb
  25. +0 −17 trunk/lib/mocha/exception_raiser.rb
  26. +0 −445 trunk/lib/mocha/expectation.rb
  27. +0 −15 trunk/lib/mocha/expectation_error.rb
  28. +0 −42 trunk/lib/mocha/expectation_list.rb
  29. +0 −19 trunk/lib/mocha/in_state_ordering_constraint.rb
  30. +0 −39 trunk/lib/mocha/inspect.rb
  31. +0 −17 trunk/lib/mocha/instance_method.rb
  32. +0 −9 trunk/lib/mocha/is_a.rb
  33. +0 −15 trunk/lib/mocha/logger.rb
  34. +0 −7 trunk/lib/mocha/metaclass.rb
  35. +0 −21 trunk/lib/mocha/method_matcher.rb
  36. +0 −207 trunk/lib/mocha/mock.rb
  37. +0 −166 trunk/lib/mocha/mockery.rb
  38. +0 −17 trunk/lib/mocha/module_method.rb
  39. +0 −20 trunk/lib/mocha/multiple_yields.rb
  40. +0 −53 trunk/lib/mocha/names.rb
  41. +0 −11 trunk/lib/mocha/no_yields.rb
  42. +0 −127 trunk/lib/mocha/object.rb
  43. +0 −26 trunk/lib/mocha/parameter_matchers.rb
  44. +0 −42 trunk/lib/mocha/parameter_matchers/all_of.rb
  45. +0 −47 trunk/lib/mocha/parameter_matchers/any_of.rb
  46. +0 −40 trunk/lib/mocha/parameter_matchers/any_parameters.rb
  47. +0 −33 trunk/lib/mocha/parameter_matchers/anything.rb
  48. +0 −15 trunk/lib/mocha/parameter_matchers/base.rb
  49. +0 −42 trunk/lib/mocha/parameter_matchers/equals.rb
  50. +0 −45 trunk/lib/mocha/parameter_matchers/has_entries.rb
  51. +0 −56 trunk/lib/mocha/parameter_matchers/has_entry.rb
  52. +0 −42 trunk/lib/mocha/parameter_matchers/has_key.rb
  53. +0 −42 trunk/lib/mocha/parameter_matchers/has_value.rb
  54. +0 −40 trunk/lib/mocha/parameter_matchers/includes.rb
  55. +0 −42 trunk/lib/mocha/parameter_matchers/instance_of.rb
  56. +0 −42 trunk/lib/mocha/parameter_matchers/is_a.rb
  57. +0 −42 trunk/lib/mocha/parameter_matchers/kind_of.rb
  58. +0 −42 trunk/lib/mocha/parameter_matchers/not.rb
  59. +0 −9 trunk/lib/mocha/parameter_matchers/object.rb
  60. +0 −55 trunk/lib/mocha/parameter_matchers/optionally.rb
  61. +0 −43 trunk/lib/mocha/parameter_matchers/regexp_matches.rb
  62. +0 −43 trunk/lib/mocha/parameter_matchers/responds_with.rb
  63. +0 −43 trunk/lib/mocha/parameter_matchers/yaml_equivalent.rb
  64. +0 −37 trunk/lib/mocha/parameters_matcher.rb
  65. +0 −28 trunk/lib/mocha/pretty_parameters.rb
  66. +0 −34 trunk/lib/mocha/return_values.rb
  67. +0 −42 trunk/lib/mocha/sequence.rb
  68. +0 −17 trunk/lib/mocha/single_return_value.rb
  69. +0 −18 trunk/lib/mocha/single_yield.rb
  70. +0 −166 trunk/lib/mocha/standalone.rb
  71. +0 −91 trunk/lib/mocha/state_machine.rb
  72. +0 −16 trunk/lib/mocha/stubbing_error.rb
  73. +0 −103 trunk/lib/mocha/test_case_adapter.rb
  74. +0 −31 trunk/lib/mocha/yield_parameters.rb
  75. +0 −2  trunk/lib/mocha_standalone.rb
  76. +0 −3  trunk/lib/stubba.rb
  77. +0 −746 trunk/templates/html_with_google_analytics.rb
  78. +0 −38 trunk/test/acceptance/acceptance_test_helper.rb
  79. +0 −43 trunk/test/acceptance/bug_18914_test.rb
  80. +0 −196 trunk/test/acceptance/expected_invocation_count_test.rb
  81. +0 −64 trunk/test/acceptance/failure_messages_test.rb
  82. +0 −98 trunk/test/acceptance/mocha_example_test.rb
  83. +0 −84 trunk/test/acceptance/mocha_test_result_test.rb
  84. +0 −100 trunk/test/acceptance/mock_test.rb
  85. +0 −51 trunk/test/acceptance/mock_with_initializer_block_test.rb
  86. +0 −78 trunk/test/acceptance/mocked_methods_dispatch_test.rb
  87. +0 −70 trunk/test/acceptance/optional_parameters_test.rb
  88. +0 −179 trunk/test/acceptance/parameter_matcher_test.rb
  89. +0 −47 trunk/test/acceptance/partial_mocks_test.rb
  90. +0 −52 trunk/test/acceptance/return_value_test.rb
  91. +0 −186 trunk/test/acceptance/sequence_test.rb
  92. +0 −139 trunk/test/acceptance/standalone_test.rb
  93. +0 −70 trunk/test/acceptance/states_test.rb
  94. +0 −195 trunk/test/acceptance/stub_any_instance_method_test.rb
  95. +0 −203 trunk/test/acceptance/stub_class_method_test.rb
  96. +0 −56 trunk/test/acceptance/stub_everything_test.rb
  97. +0 −165 trunk/test/acceptance/stub_instance_method_test.rb
  98. +0 −163 trunk/test/acceptance/stub_module_method_test.rb
  99. +0 −52 trunk/test/acceptance/stub_test.rb
  100. +0 −102 trunk/test/acceptance/stubba_example_test.rb
  101. +0 −66 trunk/test/acceptance/stubba_test_result_test.rb
  102. +0 −64 trunk/test/acceptance/stubbing_error_backtrace_test.rb
  103. +0 −65 trunk/test/acceptance/stubbing_method_unnecessarily_test.rb
  104. +0 −130 trunk/test/acceptance/stubbing_non_existent_any_instance_method_test.rb
  105. +0 −155 trunk/test/acceptance/stubbing_non_existent_class_method_test.rb
  106. +0 −145 trunk/test/acceptance/stubbing_non_existent_instance_method_test.rb
  107. +0 −130 trunk/test/acceptance/stubbing_non_public_any_instance_method_test.rb
  108. +0 −161 trunk/test/acceptance/stubbing_non_public_class_method_test.rb
  109. +0 −141 trunk/test/acceptance/stubbing_non_public_instance_method_test.rb
  110. +0 −64 trunk/test/acceptance/stubbing_on_non_mock_object_test.rb
  111. +0 −36 trunk/test/active_record_test_case.rb
  112. +0 −15 trunk/test/deprecation_disabler.rb
  113. +0 −36 trunk/test/execution_point.rb
  114. +0 −18 trunk/test/method_definer.rb
  115. +0 −13 trunk/test/simple_counter.rb
  116. +0 −11 trunk/test/test_helper.rb
  117. +0 −33 trunk/test/test_runner.rb
  118. +0 −126 trunk/test/unit/any_instance_method_test.rb
  119. +0 −16 trunk/test/unit/array_inspect_test.rb
  120. +0 −19 trunk/test/unit/backtrace_filter_test.rb
  121. +0 −56 trunk/test/unit/cardinality_test.rb
  122. +0 −65 trunk/test/unit/central_test.rb
  123. +0 −41 trunk/test/unit/change_state_side_effect_test.rb
  124. +0 −237 trunk/test/unit/class_method_test.rb
  125. +0 −21 trunk/test/unit/date_time_inspect_test.rb
  126. +0 −42 trunk/test/unit/exception_raiser_test.rb
  127. +0 −57 trunk/test/unit/expectation_list_test.rb
  128. +0 −459 trunk/test/unit/expectation_test.rb
  129. +0 −16 trunk/test/unit/hash_inspect_test.rb
  130. +0 −43 trunk/test/unit/in_state_ordering_constraint_test.rb
  131. +0 −22 trunk/test/unit/metaclass_test.rb
  132. +0 −23 trunk/test/unit/method_matcher_test.rb
  133. +0 −302 trunk/test/unit/mock_test.rb
  134. +0 −149 trunk/test/unit/mockery_test.rb
  135. +0 −18 trunk/test/unit/multiple_yields_test.rb
  136. +0 −18 trunk/test/unit/no_yields_test.rb
  137. +0 −37 trunk/test/unit/object_inspect_test.rb
  138. +0 −82 trunk/test/unit/object_test.rb
  139. +0 −26 trunk/test/unit/parameter_matchers/all_of_test.rb
  140. +0 −26 trunk/test/unit/parameter_matchers/any_of_test.rb
  141. +0 −21 trunk/test/unit/parameter_matchers/anything_test.rb
  142. +0 −25 trunk/test/unit/parameter_matchers/equals_test.rb
  143. +0 −51 trunk/test/unit/parameter_matchers/has_entries_test.rb
  144. +0 −62 trunk/test/unit/parameter_matchers/has_entry_test.rb
  145. +0 −36 trunk/test/unit/parameter_matchers/has_key_test.rb
  146. +0 −37 trunk/test/unit/parameter_matchers/has_value_test.rb
  147. +0 −25 trunk/test/unit/parameter_matchers/includes_test.rb
  148. +0 −25 trunk/test/unit/parameter_matchers/instance_of_test.rb
  149. +0 −25 trunk/test/unit/parameter_matchers/is_a_test.rb
  150. +0 −25 trunk/test/unit/parameter_matchers/kind_of_test.rb
  151. +0 −26 trunk/test/unit/parameter_matchers/not_test.rb
  152. +0 −25 trunk/test/unit/parameter_matchers/regexp_matches_test.rb
  153. +0 −25 trunk/test/unit/parameter_matchers/responds_with_test.rb
  154. +0 −27 trunk/test/unit/parameter_matchers/stub_matcher.rb
  155. +0 −25 trunk/test/unit/parameter_matchers/yaml_equivalent_test.rb
  156. +0 −121 trunk/test/unit/parameters_matcher_test.rb
  157. +0 −63 trunk/test/unit/return_values_test.rb
  158. +0 −104 trunk/test/unit/sequence_test.rb
  159. +0 −14 trunk/test/unit/single_return_value_test.rb
  160. +0 −18 trunk/test/unit/single_yield_test.rb
  161. +0 −98 trunk/test/unit/state_machine_test.rb
  162. +0 −11 trunk/test/unit/string_inspect_test.rb
  163. +0 −93 trunk/test/unit/yield_parameters_test.rb
  164. +0 −53 trunk/vendor/coderay-0.7.4.215/FOLDERS
  165. +0 −340 trunk/vendor/coderay-0.7.4.215/LICENSE
  166. +0 −117 trunk/vendor/coderay-0.7.4.215/README
  167. +0 −77 trunk/vendor/coderay-0.7.4.215/bin/coderay
  168. +0 −4 trunk/vendor/coderay-0.7.4.215/bin/coderay_stylesheet
  169. +0 −319 trunk/vendor/coderay-0.7.4.215/lib/coderay.rb
  170. +0 −29 trunk/vendor/coderay-0.7.4.215/lib/coderay/duo.rb
  171. +0 −173 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoder.rb
  172. +0 −8 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/_map.rb
  173. +0 −21 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/count.rb
  174. +0 −46 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/debug.rb
  175. +0 −20 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/div.rb
  176. +0 −260 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/html.rb
  177. +0 −77 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/classes.rb
  178. +0 −65 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/css.rb
  179. +0 −122 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/numerization.rb
  180. +0 −195 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/output.rb
  181. +0 −26 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/null.rb
  182. +0 −21 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/page.rb
  183. +0 −20 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/span.rb
  184. +0 −81 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/statistic.rb
  185. +0 −33 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/text.rb
  186. +0 −44 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/tokens.rb
  187. +0 −71 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/xml.rb
  188. +0 −22 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/yaml.rb
  189. +0 −182 trunk/vendor/coderay-0.7.4.215/lib/coderay/helpers/file_type.rb
  190. +0 −122 trunk/vendor/coderay-0.7.4.215/lib/coderay/helpers/gzip_simple.rb
  191. +0 −326 trunk/vendor/coderay-0.7.4.215/lib/coderay/helpers/plugin.rb
  192. +0 −119 trunk/vendor/coderay-0.7.4.215/lib/coderay/helpers/word_list.rb
  193. +0 −238 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanner.rb
  194. +0 −15 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/_map.rb
  195. +0 −163 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/c.rb
  196. +0 −60 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/debug.rb
  197. +0 −149 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/delphi.rb
  198. +0 −177 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/html.rb
  199. +0 −133 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/nitro_xhtml.rb
  200. +0 −16 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/plaintext.rb
  201. +0 −73 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/rhtml.rb
  202. +0 −367 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/ruby.rb
  203. +0 −230 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/ruby/patterns.rb
  204. +0 −18 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/xml.rb
  205. +0 −20 trunk/vendor/coderay-0.7.4.215/lib/coderay/style.rb
  206. +0 −7 trunk/vendor/coderay-0.7.4.215/lib/coderay/styles/_map.rb
  207. +0 −125 trunk/vendor/coderay-0.7.4.215/lib/coderay/styles/cycnus.rb
  208. +0 −119 trunk/vendor/coderay-0.7.4.215/lib/coderay/styles/murphy.rb
  209. +0 −368 trunk/vendor/coderay-0.7.4.215/lib/coderay/tokens.rb
  210. +0 −295 trunk/vendor/meta_project-0.4.15/CHANGES
  211. +0 −21 trunk/vendor/meta_project-0.4.15/MIT-LICENSE
  212. +0 −129 trunk/vendor/meta_project-0.4.15/README
  213. +0 −152 trunk/vendor/meta_project-0.4.15/Rakefile
  214. +0 −2  trunk/vendor/meta_project-0.4.15/doc/base_attrs.rdoc
  215. +0 −19 trunk/vendor/meta_project-0.4.15/lib/meta_project.rb
  216. +0 −22 trunk/vendor/meta_project-0.4.15/lib/meta_project/core_ext/open_uri.rb
  217. +0 −36 trunk/vendor/meta_project-0.4.15/lib/meta_project/core_ext/pathname.rb
  218. +0 −5 trunk/vendor/meta_project-0.4.15/lib/meta_project/core_ext/string.rb
  219. +0 −32 trunk/vendor/meta_project-0.4.15/lib/meta_project/http/multipart.rb
  220. +0 −1  trunk/vendor/meta_project-0.4.15/lib/meta_project/patois.rb
  221. +0 −99 trunk/vendor/meta_project-0.4.15/lib/meta_project/patois/parser.rb
  222. +0 −4 trunk/vendor/meta_project-0.4.15/lib/meta_project/project.rb
  223. +0 −9 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/base.rb
  224. +0 −1  trunk/vendor/meta_project-0.4.15/lib/meta_project/project/codehaus.rb
  225. +0 −31 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/codehaus/codehaus_project_svn.rb
  226. +0 −1  trunk/vendor/meta_project-0.4.15/lib/meta_project/project/trac.rb
  227. +0 −54 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/trac/trac_project.rb
  228. +0 −5 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge.rb
  229. +0 −47 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/ruby_forge.rb
  230. +0 −177 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/session.rb
  231. +0 −50 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/source_forge.rb
  232. +0 −45 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/xfile.rb
  233. +0 −85 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/xforge_base.rb
  234. +0 −36 trunk/vendor/meta_project-0.4.15/lib/meta_project/project_analyzer.rb
  235. +0 −267 trunk/vendor/meta_project-0.4.15/lib/meta_project/release/freshmeat.rb
  236. +0 −572 trunk/vendor/meta_project-0.4.15/lib/meta_project/release/raa.rb
  237. +0 −2  trunk/vendor/meta_project-0.4.15/lib/meta_project/scm_web.rb
  238. +0 −112 trunk/vendor/meta_project-0.4.15/lib/meta_project/scm_web/browser.rb
  239. +0 −89 trunk/vendor/meta_project-0.4.15/lib/meta_project/scm_web/pathname.rb
  240. +0 −6 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker.rb
  241. +0 −24 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/base.rb
  242. +0 −34 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/digit_issues.rb
  243. +0 −57 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/issue.rb
  244. +0 −2  trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/jira.rb
  245. +0 −35 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/jira/jira_issues.rb
  246. +0 −149 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/jira/jira_tracker.rb
  247. +0 −1  trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/trac.rb
  248. +0 −33 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/trac/trac_tracker.rb
  249. +0 −3  trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge.rb
  250. +0 −17 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge/ruby_forge_tracker.rb
  251. +0 −17 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge/source_forge_tracker.rb
  252. +0 −191 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge/xforge_tracker.rb
  253. +0 −52 trunk/vendor/meta_project-0.4.15/lib/meta_project/version_parser.rb
  254. +0 −3  trunk/vendor/meta_project-0.4.15/lib/rake/contrib/xforge.rb
  255. +0 −64 trunk/vendor/meta_project-0.4.15/lib/rake/contrib/xforge/base.rb
  256. +0 −97 trunk/vendor/meta_project-0.4.15/lib/rake/contrib/xforge/news_publisher.rb
  257. +0 −134 trunk/vendor/meta_project-0.4.15/lib/rake/contrib/xforge/release.rb
View
2  lib/mocha/mock.rb
@@ -6,6 +6,8 @@
module Mocha # :nodoc:
+ class ExpectationSequenceError < RuntimeError; end
+
# Traditional mock object.
#
# Methods return an Expectation which can be further modified by methods on Expectation.
View
39 lib/mocha/parameter_matchers/instance_of.rb
@@ -1,39 +0,0 @@
-module Mocha
-
- module ParameterMatchers
-
- # :call-seq: instance_of(klass) -> parameter_matcher
- #
- # Matches any object that is an instance of +klass+
- # object = mock()
- # object.expects(:method_1).with(instance_of(String))
- # object.method_1('string')
- # # no error raised
- #
- # object = mock()
- # object.expects(:method_1).with(instance_of(String))
- # object.method_1(99)
- # # error raised, because method_1 was not called with an instance of String
- def instance_of(klass)
- InstanceOf.new(klass)
- end
-
- class InstanceOf # :nodoc:
-
- def initialize(klass)
- @klass = klass
- end
-
- def ==(parameter)
- parameter.instance_of?(@klass)
- end
-
- def mocha_inspect
- "instance_of(#{@klass.mocha_inspect})"
- end
-
- end
-
- end
-
-end
View
39 lib/mocha/parameter_matchers/kind_of.rb
@@ -1,39 +0,0 @@
-module Mocha
-
- module ParameterMatchers
-
- # :call-seq: kind_of(klass) -> parameter_matcher
- #
- # Matches any object that is a kind of +klass+
- # object = mock()
- # object.expects(:method_1).with(kind_of(Integer))
- # object.method_1(99)
- # # no error raised
- #
- # object = mock()
- # object.expects(:method_1).with(kind_of(Integer))
- # object.method_1('string')
- # # error raised, because method_1 was not called with a kind of Integer
- def kind_of(klass)
- KindOf.new(klass)
- end
-
- class KindOf # :nodoc:
-
- def initialize(klass)
- @klass = klass
- end
-
- def ==(parameter)
- parameter.kind_of?(@klass)
- end
-
- def mocha_inspect
- "kind_of(#{@klass.mocha_inspect})"
- end
-
- end
-
- end
-
-end
View
25 test/unit/parameter_matchers/instance_of_test.rb
@@ -1,25 +0,0 @@
-require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
-
-require 'mocha/parameter_matchers/instance_of'
-require 'mocha/inspect'
-
-class InstanceOfTest < Test::Unit::TestCase
-
- include Mocha::ParameterMatchers
-
- def test_should_match_object_that_is_an_instance_of_specified_class
- matcher = instance_of(String)
- assert matcher == 'string'
- end
-
- def test_should_not_match_object_that_is_not_an_instance_of_specified_class
- matcher = instance_of(String)
- assert matcher != 99
- end
-
- def test_should_describe_matcher
- matcher = instance_of(String)
- assert_equal "instance_of(String)", matcher.mocha_inspect
- end
-
-end
View
25 test/unit/parameter_matchers/kind_of_test.rb
@@ -1,25 +0,0 @@
-require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
-
-require 'mocha/parameter_matchers/kind_of'
-require 'mocha/inspect'
-
-class InstanceOfTest < Test::Unit::TestCase
-
- include Mocha::ParameterMatchers
-
- def test_should_match_object_that_is_a_kind_of_specified_class
- matcher = kind_of(Integer)
- assert matcher == 99
- end
-
- def test_should_not_match_object_that_is_not_a_kind_of_specified_class
- matcher = kind_of(Integer)
- assert matcher != 'string'
- end
-
- def test_should_describe_matcher
- matcher = kind_of(Integer)
- assert_equal "kind_of(Integer)", matcher.mocha_inspect
- end
-
-end
View
3  trunk/COPYING
@@ -1,3 +0,0 @@
-Copyright Revieworld Ltd. 2006
-
-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).
View
7 trunk/MIT-LICENSE
@@ -1,7 +0,0 @@
-Copyright (c) 2006 Revieworld Ltd.
-
-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:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-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.
View
35 trunk/README
@@ -1,35 +0,0 @@
-= Mocha
-
-Mocha is a library for mocking and stubbing using a syntax like that of JMock[http://www.jmock.org].
-
-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/] and even JtestR[http://jtestr.codehaus.org/].
-
-Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking.
-
-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].
-
-== Download and Installation
-
-Install the gem with the following command...
-
- $ gem install mocha
-
-Or install the Rails[http://www.rubyonrails.org] plugin...
-
- $ script/plugin install svn://rubyforge.org/var/svn/mocha/trunk
-
-Or download Mocha from here - http://rubyforge.org/projects/mocha
-
-== Examples
-
-* Quick Start - {Usage Examples}[link:examples/misc.html]
-* Traditional mocking - {Star Trek Example}[link:examples/mocha.html]
-* Setting expectations on real classes - {Order Example}[link:examples/stubba.html]
-* More examples on {Floehopper's Blog}[http://blog.floehopper.org]
-* {Mailing List Archives}[http://rubyforge.org/pipermail/mocha-developer/]
-
-== License
-
-Copyright Revieworld Ltd. 2006
-
-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].
View
233 trunk/RELEASE
@@ -1,233 +0,0 @@
-= 0.9.0 (r316)
-
-* Configurable warnings or errors
- * when a method on a non-public method is stubbed
- * when a method on a non-existent method is stubbed
- * when a method on a non-mock object is stubbed
- * when a method is stubbed unnecessarily (i.e. the stubbed method is not called during the test)
-
-* Improved error messages
- * User-friendly list of unsatisfied expectations, satisfied expectations and state machines.
- * Improved readability of cardinality description.
- * Display sensible failure message for any_instance expectations e.g. "#<AnyInstance:Foo>.bar - expected calls: 1, actual calls: 0"
-
-* Parameter matchers
- * New to this release
- * optionally (allows matching of optional parameters if available)
- * yaml_equivalent (allows matching of YAML that represents the specified object)
- * responds_with (tests the quack not the duck)
- * Nesting of parameter matchers is now supported.
-
-* 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.
-
-* Added JMock-style sequences for constraining the order of expected invocations. See Standalone#sequence and Expectation#in_sequence.
-
-* Added JMock-style states for constraining the order of expected invocations. See Standalone#states, Expectation#then, Expectation#when and StateMachine.
-
-* Compatibility with versions of Ruby
- * Compatibility with Ruby v1.9. All test errors and warnings fixed.
- * Nasty fix so that TestCaseAdaptor works consistently with earlier versions of Test::Unit as well as more recent versions.
- * 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.
- * 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.
-
-* Added deprecation warning in stubba.rb which is no longer needed and will be removed.
-
-* Supply positioning information to evals to improve any error messages. See http://ola-bini.blogspot.com/2008/01/ruby-antipattern-using-eval-without.html
-
-* Bug fixes
- * 18914 in revision 296 - http://rubyforge.org/tracker/index.php?func=detail&aid=18914&group_id=1917&atid=7477
- * 18917 in revision 295 - http://rubyforge.org/tracker/index.php?func=detail&aid=18917&group_id=1917&atid=7477
- * 18336 in revision 287 - http://rubyforge.org/tracker/index.php?func=detail&aid=18336&group_id=1917&atid=7477
- * 17835 in revision 255 - http://rubyforge.org/tracker/index.php?func=detail&aid=17835&group_id=1917&atid=7477
- * 17412 in revision 242 - http://rubyforge.org/tracker/index.php?func=detail&aid=17412&group_id=1917&atid=7477
- * 15977 in revision 198 - http://rubyforge.org/tracker/index.php?func=detail&aid=15977&group_id=1917&atid=7477
- * 11885 in revision 156 - http://rubyforge.org/tracker/index.php?func=detail&aid=11885&group_id=1917&atid=7477
-
-= 0.5.5 (r167)
-
-- Renamed Matches parameter matcher to RegexpMatches for clarity.
-- Added noframes tag to rdoc index to assist Google.
-
-= 0.5.4 (r166)
-
-- Added matches parameter matcher for matching regular expressions.
-
-= 0.5.3 (r165)
-
-- Attempt to fix packaging problems by switching to newer version (1.15.1) of gnutar and setting COPY_EXTENDED_ATTRIBUTES_DISABLE environment variable.
-- Removed unused ExpectationSequenceError exception.
-- Added instance_of and kind_of parameter matchers.
-- Added Google Webmaster meta tag to rdoc template header.
-- Put Google Webmaster meta tag in the right header i.e. the one for the index page.
-
-= 0.5.2 (r159)
-
-- 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).
-- 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.
-
-= 0.5.1 (r149)
-
-- 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.
-
-= 0.5.0 (r147)
-
-- 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.
-
- object = mock()
- object.expects(:method).with(has_key('key_1'))
- object.method('key_1' => 1, 'key_2' => 2)
- # no verification error raised
-
- object = mock()
- object.expects(:method).with(has_key('key_1'))
- object.method('key_2' => 2)
- # verification error raised, because method was not called with Hash containing key: 'key_1'
-
-- 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.
-
- object = mock()
- object.stubs(:method).returns(1, 2).then.raises(Exception).then.returns(4)
- object.method # => 1
- object.method # => 2
- object.method # => raises exception of class Exception
- object.method # => 4
-
-- Yields on Consecutive Invocations - Allow multiple calls to yields on single expectation to allow yield parameters to be specified for consecutive invocations.
-
- object = mock()
- object.stubs(:method).yields(1, 2).then.yields(3)
- object.method { |*values| p values } # => [1, 2]
- object.method { |*values| p values } # => [3]
-
-- Multiple Yields on Single Invocation - Added Expectation#multiple_yields to allow a mocked or stubbed method to yield multiple times for a single invocation.
-
- object = mock()
- object.stubs(:method).multiple_yields([1, 2], [3])
- object.method { |*values| p values } # => [1, 2] # => [3]
-
-- 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.
-
- object = mock()
- object.stubs(:method).returns(2)
- object.expects(:method).once.returns(1)
- object.method # => 1
- object.method # => 2
- object.method # => 2
- # no verification error raised
-
- # The following should still work...
-
- Time.stubs(:now).returns(Time.parse('Mon Jan 01 00:00:00 UTC 2007'))
- Time.now # => Mon Jan 01 00:00:00 UTC 2007
- Time.stubs(:now).returns(Time.parse('Thu Feb 01 00:00:00 UTC 2007'))
- Time.now # => Thu Feb 01 00:00:00 UTC 2007
-
-- Deprecate passing an instance of Proc to Expectation#returns.
-- Explicitly include all Rakefile dependencies in project.
-- Fixed old Stubba example.
-- Fix so that it is possible for a stubbed method to raise an Interrupt exception without a message in Ruby 1.8.6
-- Added responds_like and quacks_like.
-- Capture standard object methods before Mocha adds any.
-- Added Expectation#once method to make interface less surprising.
-- 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.
-- Fiddled with mocha_inspect and tests to give more sensible results on x86 platform.
-- Fixed bug #7834 "infinite_range.rb makes incorrect assumption about to_f" logged by James Moore.
-
-= 0.4.0 (r92)
-
-- Allow naming of mocks (patch from Chris Roos).
-- Specify multiple return values for consecutive calls.
-- Improved consistency of expectation error messages.
-- Allow mocking of Object instance methods e.g. kind_of?, type.
-- Provide aliased versions of #expects and #stubs to allow mocking of these methods.
-- Added at_least, at_most, at_most_once methods to expectation.
-- Allow expects and stubs to take a hash of method and return values.
-- Eliminate warning: "instance variable @yield not initialized" (patch from Xavier Shay).
-- Restore instance methods on partial mocks (patch from Chris Roos).
-- Allow stubbing of a method with non-word characters in its name (patch from Paul Battley).
-- Removed coupling to Test::Unit.
-- Allow specified exception instance to be raised (patch from Chris Roos).
-- Make mock object_id appear in hex like normal Ruby inspect (patch from Paul Battley).
-- Fix path to object.rb in rdoc rake task (patch from Tomas Pospisek).
-- 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).
-- Stubba & SmartTestCase modules incorporated into Mocha module so only need to require 'mocha' - no longer need to require 'stubba'.
-- AutoMocha removed.
-
-= 0.3.3
-
-- Quick bug fix to restore instance methods on partial mocks (for Kevin Clark).
-
-= 0.3.2
-
-- Examples added.
-
-= 0.3.1
-
-- Dual licensing with MIT license added.
-
-= 0.3.0
-
-* Rails plugin.
-* Auto-verify for expectations on concrete classes.
-* Include each expectation verification in the test result assertion count.
-* Filter out noise from assertion backtraces.
-* Point assertion backtrace to line where failing expectation was created.
-* New yields method for expectations.
-* Create stubs which stub all method calls.
-* Mocks now respond_to? expected methods.
-
-= 0.2.1
-
-* Rename MochaAcceptanceTest::Rover#move method to avoid conflict with Rake (in Ruby 1.8.4 only?)
-
-= 0.2.0
-
-* 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).
-* Reorganized directory structure and extracted addition of setup and teardown methods into SmartTestCase mini-library.
-* 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.
-
-So instead of...
-
- wotsit = Mocha.new
- wotsit.expects(:thingummy).with(5).returns(10)
- doobrey = Doobrey.new(wotsit)
- doobrey.hoojamaflip
- wotsit.verify
-
-you need to do...
-
- wotsit = mock()
- wotsit.expects(:thingummy).with(5).returns(10)
- doobrey = Doobrey.new(wotsit)
- doobrey.hoojamaflip
- # no need to verify
-
-There are also shortcuts as follows...
-
-instead of...
-
- wotsit = Mocha.new
- wotsit.expects(:thingummy).returns(10)
- wotsit.expects(:summat).returns(25)
-
-you can have...
-
- wotsit = mock(:thingummy => 5, :summat => 25)
-
-and instead of...
-
- wotsit = Mocha.new
- wotsit.stubs(:thingummy).returns(10)
- wotsit.stubs(:summat).returns(25)
-
-you can have...
-
- wotsit = stub(:thingummy => 5, :summat => 25)
-
-= 0.1.2
-
-* Minor tweaks
-
-= 0.1.1
-
-* Initial release.
View
171 trunk/Rakefile
@@ -1,171 +0,0 @@
-require 'rubygems'
-require 'rake/rdoctask'
-require 'rake/gempackagetask'
-require 'rake/testtask'
-require 'rake/contrib/sshpublisher'
-
-module Mocha
- VERSION = "0.9.0"
-end
-
-desc "Run all tests"
-task 'default' => ['test:units', 'test:acceptance']
-
-namespace 'test' do
-
- unit_tests = FileList['test/unit/**/*_test.rb']
- acceptance_tests = FileList['test/acceptance/*_test.rb']
-
- desc "Run unit tests"
- Rake::TestTask.new('units') do |t|
- t.libs << 'test'
- t.test_files = unit_tests
- t.verbose = true
- t.warning = true
- end
-
- desc "Run acceptance tests"
- Rake::TestTask.new('acceptance') do |t|
- t.libs << 'test'
- t.test_files = acceptance_tests
- t.verbose = true
- t.warning = true
- end
-
- # require 'rcov/rcovtask'
- # Rcov::RcovTask.new('coverage') do |t|
- # t.libs << 'test'
- # t.test_files = unit_tests + acceptance_tests
- # t.verbose = true
- # t.warning = true
- # t.rcov_opts << '--sort coverage'
- # t.rcov_opts << '--xref'
- # end
-
-end
-
-desc 'Generate RDoc'
-Rake::RDocTask.new('rdoc') do |task|
- task.main = 'README'
- task.title = "Mocha #{Mocha::VERSION}"
- task.rdoc_dir = 'doc'
- task.template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics"))
- task.rdoc_files.include(
- 'README',
- 'RELEASE',
- 'COPYING',
- 'MIT-LICENSE',
- 'agiledox.txt',
- 'lib/mocha/standalone.rb',
- 'lib/mocha/mock.rb',
- 'lib/mocha/expectation.rb',
- 'lib/mocha/object.rb',
- 'lib/mocha/parameter_matchers.rb',
- 'lib/mocha/parameter_matchers',
- 'lib/mocha/state_machine.rb',
- 'lib/mocha/configuration.rb',
- 'lib/mocha/stubbing_error.rb'
- )
-end
-task 'rdoc' => 'examples'
-
-desc "Upload RDoc to RubyForge"
-task 'publish_rdoc' => ['rdoc', 'examples'] do
- Rake::SshDirPublisher.new("jamesmead@rubyforge.org", "/var/www/gforge-projects/mocha", "doc").upload
-end
-
-desc "Generate agiledox-like documentation for tests"
-file 'agiledox.txt' do
- File.open('agiledox.txt', 'w') do |output|
- tests = FileList['test/**/*_test.rb']
- tests.each do |file|
- m = %r".*/([^/].*)_test.rb".match(file)
- output << m[1]+" should:\n"
- test_definitions = File::readlines(file).select {|line| line =~ /.*def test.*/}
- test_definitions.sort.each do |definition|
- m = %r"test_(should_)?(.*)".match(definition)
- output << " - "+m[2].gsub(/_/," ") << "\n"
- end
- end
- end
-end
-
-desc "Convert example ruby files to syntax-highlighted html"
-task 'examples' do
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "vendor", "coderay-0.7.4.215", "lib"))
- require 'coderay'
- mkdir_p 'doc/examples'
- File.open('doc/examples/coderay.css', 'w') do |output|
- output << CodeRay::Encoders[:html]::CSS.new.stylesheet
- end
- ['mocha', 'stubba', 'misc'].each do |filename|
- File.open("doc/examples/#{filename}.html", 'w') do |file|
- file << "<html>"
- file << "<head>"
- file << %q(<link rel="stylesheet" media="screen" href="coderay.css" type="text/css">)
- file << "</head>"
- file << "<body>"
- file << CodeRay.scan_file("examples/#{filename}.rb").html.div
- file << "</body>"
- file << "</html>"
- end
- end
-end
-
-Gem::manage_gems
-
-specification = Gem::Specification.new do |s|
- s.name = "mocha"
- s.summary = "Mocking and stubbing library"
- s.version = Mocha::VERSION
- s.platform = Gem::Platform::RUBY
- s.author = 'James Mead'
- s.description = <<-EOF
- Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
- EOF
- s.email = 'mocha-developer@rubyforge.org'
- s.homepage = 'http://mocha.rubyforge.org'
- s.rubyforge_project = 'mocha'
-
- s.has_rdoc = true
- s.extra_rdoc_files = ['README', 'COPYING']
- s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers'
-
- s.autorequire = 'mocha'
- s.add_dependency('rake')
- s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
-end
-
-Rake::GemPackageTask.new(specification) do |package|
- package.need_zip = true
- package.need_tar = true
-end
-
-task 'verify_user' do
- raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
-end
-
-task 'verify_password' do
- raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
-end
-
-desc "Publish package files on RubyForge."
-task 'publish_packages' => ['verify_user', 'verify_password', 'package'] do
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "vendor", "meta_project-0.4.15", "lib"))
- require 'meta_project'
- require 'rake/contrib/xforge'
- release_files = FileList[
- "pkg/mocha-#{Mocha::VERSION}.gem",
- "pkg/mocha-#{Mocha::VERSION}.tgz",
- "pkg/mocha-#{Mocha::VERSION}.zip"
- ]
-
- Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new('mocha')) do |release|
- release.user_name = ENV['RUBYFORGE_USER']
- release.password = ENV['RUBYFORGE_PASSWORD']
- release.files = release_files.to_a
- release.release_name = "Mocha #{Mocha::VERSION}"
- release.release_changes = ''
- release.release_notes = ''
- end
-end
View
50 trunk/TODO
@@ -1,50 +0,0 @@
-=> Patch [#15235] Provide a pseudo-call syntax for simplifying set-up of expectations and stubs
-=> Patch [#10412] Merge 'with' and the expected method
-=> Bug [#8687] Block's return value is dropped on stubbed yielding methods
-
-=> interesting links
-- http://www.jmock.org/match-object-or-method.html
-- http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/106-12985-with_block_which_returns-val
-
-- think about making class_method_test & any_instance_method_test more blackbox to avoid ruby warnings
-
-=> update vendor libraries
-- does updating meta_project have any effect on broken tarball issue?
-
-=> release management
-- why does gem rdoc include all source files? what about other package types?
-- why does zip include Rakefile? what about other package types?
-- tag releases in repos
-- trac?
-
-=> multiple expectations for same method
-- fail fast if expectation count exceeded during test...? c.f. JMock?
-
-=> reduce footprint of mocha in terms of visible methods
-- do away with __is_a__ method if possible - Proc param may no longer be needed
-- add similar test to test_should_be_able_to_mock_standard_object_methods for partial mocks - rename non-public method with underscores e.g. mocha, reset_mocha, stubba_method, stubba_object, etc.
-- reduce number of methods added to Object, Class etc to bare minimum
-- reduce number of methods excluded from undef in Mock (maybe use BlankSlate as mocha parent class to allow mocking of standard object methods?)
-- perhaps only add methods to particular class at point where expects or stubs gets called
-- provide some means to un-stubba an object - ideally should restore any methods with same names as stubba methods c.f. dealing with expectations for methods called :expects, :stubs, etc.
-- use Object#inspect(:mocha) or Object#__inspect__ instead of Object#mocha_inspect?
-
-=> improve design
-- use builder object c.f. JMock
-- use expectation builder object to allow partial mocks to accept a hash in expects or stubs methods
-- possibly simplify by making mock the same as a partial mock of Object
-- provide test::unit agnostic api - mockery/context type objects on which the user must call setup/teardown?
-- allow stubs/expects methods to accept method names as strings and symbols to retain similarity to define_method() et al
-
-=> naming
-- default mock names to mock1, mock2, etc or something similar
-- stubba mocks should named according to parent stubbee
-
-=> improve tests
-- use real activerecord as svn external to for testing instead of active_record_test_case
-- test for setting expectations on class methods (and instance methods?) from within TestCase#setup
-
-=> possible extra functionality
-- maybe allow unstubbing of a specific method from within a test...?
-- oomatron type ideas
-- should all instances share expectations for any_instance or should each instance have their own - in which case how do we provide access to the instances
View
44 trunk/examples/misc.rb
@@ -1,44 +0,0 @@
-require 'test/unit'
-require 'rubygems'
-require 'mocha'
-
-class MiscExampleTest < Test::Unit::TestCase
-
- def test_mocking_a_class_method
- product = Product.new
- Product.expects(:find).with(1).returns(product)
- assert_equal product, Product.find(1)
- end
-
- def test_mocking_an_instance_method_on_a_real_object
- product = Product.new
- product.expects(:save).returns(true)
- assert product.save
- end
-
- def test_stubbing_instance_methods_on_real_objects
- prices = [stub(:pence => 1000), stub(:pence => 2000)]
- product = Product.new
- product.stubs(:prices).returns(prices)
- assert_equal [1000, 2000], product.prices.collect {|p| p.pence}
- end
-
- def test_stubbing_an_instance_method_on_all_instances_of_a_class
- Product.any_instance.stubs(:name).returns('stubbed_name')
- product = Product.new
- assert_equal 'stubbed_name', product.name
- end
-
- def test_traditional_mocking
- object = mock()
- object.expects(:expected_method).with(:p1, :p2).returns(:result)
- assert_equal :result, object.expected_method(:p1, :p2)
- end
-
- def test_shortcuts
- object = stub(:method1 => :result1, :method2 => :result2)
- assert_equal :result1, object.method1
- assert_equal :result2, object.method2
- end
-
-end
View
26 trunk/examples/mocha.rb
@@ -1,26 +0,0 @@
-class Enterprise
-
- def initialize(dilithium)
- @dilithium = dilithium
- end
-
- def go(warp_factor)
- warp_factor.times { @dilithium.nuke(:anti_matter) }
- end
-
-end
-
-require 'test/unit'
-require 'rubygems'
-require 'mocha'
-
-class EnterpriseTest < Test::Unit::TestCase
-
- def test_should_boldly_go
- dilithium = mock()
- dilithium.expects(:nuke).with(:anti_matter).at_least_once # auto-verified at end of test
- enterprise = Enterprise.new(dilithium)
- enterprise.go(2)
- end
-
-end
View
65 trunk/examples/stubba.rb
@@ -1,65 +0,0 @@
-class Order
-
- attr_accessor :shipped_on
-
- def total_cost
- line_items.inject(0) { |total, line_item| total + line_item.price } + shipping_cost
- end
-
- def total_weight
- line_items.inject(0) { |total, line_item| total + line_item.weight }
- end
-
- def shipping_cost
- total_weight * 5 + 10
- end
-
- class << self
-
- def find_all
- # Database.connection.execute('select * from orders...
- end
-
- def number_shipped_since(date)
- find_all.select { |order| order.shipped_on > date }.length
- end
-
- def unshipped_value
- find_all.inject(0) { |total, order| order.shipped_on ? total : total + order.total_cost }
- end
-
- end
-
-end
-
-require 'test/unit'
-require 'rubygems'
-require 'mocha'
-
-class OrderTest < Test::Unit::TestCase
-
- # illustrates stubbing instance method
- def test_should_calculate_shipping_cost_based_on_total_weight
- order = Order.new
- order.stubs(:total_weight).returns(10)
- assert_equal 60, order.shipping_cost
- end
-
- # illustrates stubbing class method
- def test_should_count_number_of_orders_shipped_after_specified_date
- now = Time.now; week_in_secs = 7 * 24 * 60 * 60
- order_1 = Order.new; order_1.shipped_on = now - 1 * week_in_secs
- order_2 = Order.new; order_2.shipped_on = now - 3 * week_in_secs
- Order.stubs(:find_all).returns([order_1, order_2])
- assert_equal 1, Order.number_shipped_since(now - 2 * week_in_secs)
- end
-
- # illustrates stubbing instance method for all instances of a class
- def test_should_calculate_value_of_unshipped_orders
- Order.stubs(:find_all).returns([Order.new, Order.new, Order.new])
- Order.any_instance.stubs(:shipped_on).returns(nil)
- Order.any_instance.stubs(:total_cost).returns(10)
- assert_equal 30, Order.unshipped_value
- end
-
-end
View
3  trunk/init.rb
@@ -1,3 +0,0 @@
-if ENV['RAILS_ENV'] == 'test' then
- require 'mocha'
-end
View
20 trunk/lib/mocha.rb
@@ -1,20 +0,0 @@
-require 'mocha_standalone'
-require 'mocha/test_case_adapter'
-require 'mocha/configuration'
-
-require 'test/unit/testcase'
-
-module Test
-
- module Unit
-
- class TestCase
-
- include Mocha::Standalone
- include Mocha::TestCaseAdapter
-
- end
-
- end
-
-end
View
55 trunk/lib/mocha/any_instance_method.rb
@@ -1,55 +0,0 @@
-require 'mocha/class_method'
-
-module Mocha
-
- class AnyInstanceMethod < ClassMethod
-
- def unstub
- remove_new_method
- restore_original_method
- stubbee.any_instance.reset_mocha
- end
-
- def mock
- stubbee.any_instance.mocha
- end
-
- def hide_original_method
- if method_exists?(method)
- begin
- stubbee.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__)
- rescue NameError
- # deal with nasties like ActiveRecord::Associations::AssociationProxy
- end
- end
- end
-
- def define_new_method
- stubbee.class_eval("def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__)
- end
-
- def remove_new_method
- stubbee.class_eval("remove_method :#{method}", __FILE__, __LINE__)
- end
-
- def restore_original_method
- if method_exists?(hidden_method)
- begin
- stubbee.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__)
- rescue NameError
- # deal with nasties like ActiveRecord::Associations::AssociationProxy
- end
- end
- end
-
- def method_exists?(method)
- existing_methods = []
- existing_methods += stubbee.public_instance_methods(false)
- existing_methods += stubbee.protected_instance_methods(false)
- existing_methods += stubbee.private_instance_methods(false)
- existing_methods.any? { |m| m.to_s == method.to_s }
- end
-
- end
-
-end
View
17 trunk/lib/mocha/backtrace_filter.rb
@@ -1,17 +0,0 @@
-module Mocha
-
- class BacktraceFilter
-
- LIB_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), "..")) + File::SEPARATOR
-
- def initialize(lib_directory = LIB_DIRECTORY)
- @lib_directory = lib_directory
- end
-
- def filtered(backtrace)
- backtrace.reject { |location| Regexp.new(@lib_directory).match(File.expand_path(location)) }
- end
-
- end
-
-end
View
92 trunk/lib/mocha/cardinality.rb
@@ -1,92 +0,0 @@
-module Mocha
-
- class Cardinality
-
- INFINITY = 1 / 0.0
-
- class << self
-
- def exactly(count)
- new(count, count)
- end
-
- def at_least(count)
- new(count, INFINITY)
- end
-
- def at_most(count)
- new(0, count)
- end
-
- def times(range_or_count)
- case range_or_count
- when Range
- new(range_or_count.first, range_or_count.last)
- else
- new(range_or_count, range_or_count)
- end
- end
-
- end
-
- def initialize(required, maximum)
- @required, @maximum = required, maximum
- end
-
- def invocations_allowed?(invocation_count)
- invocation_count < maximum
- end
-
- def satisfied?(invocations_so_far)
- invocations_so_far >= required
- end
-
- def needs_verifying?
- !allowed_any_number_of_times?
- end
-
- def verified?(invocation_count)
- (invocation_count >= required) && (invocation_count <= maximum)
- end
-
- def allowed_any_number_of_times?
- required == 0 && infinite?(maximum)
- end
-
- def used?(invocation_count)
- (invocation_count > 0) || (maximum == 0)
- end
-
- def mocha_inspect
- if allowed_any_number_of_times?
- "allowed any number of times"
- else
- if required == 0 && maximum == 0
- "expected never"
- elsif required == maximum
- "expected exactly #{times(required)}"
- elsif infinite?(maximum)
- "expected at least #{times(required)}"
- elsif required == 0
- "expected at most #{times(maximum)}"
- else
- "expected between #{required} and #{times(maximum)}"
- end
- end
- end
-
- protected
-
- attr_reader :required, :maximum
-
- def times(number)
- number == 1 ? "once" : "#{number} times"
- end
-
- def infinite?(number)
- number.respond_to?(:infinite?) && number.infinite?
- end
-
- end
-
-end
View
27 trunk/lib/mocha/central.rb
@@ -1,27 +0,0 @@
-module Mocha
-
- class Central
-
- attr_accessor :stubba_methods
-
- def initialize
- self.stubba_methods = []
- end
-
- def stub(method)
- unless stubba_methods.include?(method)
- method.stub
- stubba_methods.push(method)
- end
- end
-
- def unstub_all
- while stubba_methods.length > 0
- method = stubba_methods.pop
- method.unstub
- end
- end
-
- end
-
-end
View
19 trunk/lib/mocha/change_state_side_effect.rb
@@ -1,19 +0,0 @@
-module Mocha
-
- class ChangeStateSideEffect
-
- def initialize(state)
- @state = state
- end
-
- def perform
- @state.activate
- end
-
- def mocha_inspect
- "then #{@state.mocha_inspect}"
- end
-
- end
-
-end
View
86 trunk/lib/mocha/class_method.rb
@@ -1,86 +0,0 @@
-require 'mocha/metaclass'
-
-module Mocha
-
- class ClassMethod
-
- attr_reader :stubbee, :method
-
- def initialize(stubbee, method)
- @stubbee, @method = stubbee, method
- end
-
- def stub
- hide_original_method
- define_new_method
- end
-
- def unstub
- remove_new_method
- restore_original_method
- stubbee.reset_mocha
- end
-
- def mock
- stubbee.mocha
- end
-
- def hide_original_method
- if method_exists?(method)
- begin
- stubbee.__metaclass__.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__)
- rescue NameError
- # deal with nasties like ActiveRecord::Associations::AssociationProxy
- end
- end
- end
-
- def define_new_method
- stubbee.__metaclass__.class_eval("def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__)
- end
-
- def remove_new_method
- stubbee.__metaclass__.class_eval("remove_method :#{method}", __FILE__, __LINE__)
- end
-
- def restore_original_method
- if method_exists?(hidden_method)
- begin
- stubbee.__metaclass__.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__)
- rescue NameError
- # deal with nasties like ActiveRecord::Associations::AssociationProxy
- end
- end
- end
-
- def hidden_method
- if RUBY_VERSION < '1.9'
- method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s[0]}_" }
- else
- method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s.ord}_" }
- end
- "__stubba__#{method_name}__stubba__"
- end
-
- def eql?(other)
- return false unless (other.class == self.class)
- (stubbee.object_id == other.stubbee.object_id) and (method == other.method)
- end
-
- alias_method :==, :eql?
-
- def to_s
- "#{stubbee}.#{method}"
- end
-
- def method_exists?(method)
- existing_methods = []
- existing_methods += stubbee.public_methods(true) - stubbee.superclass.public_methods(true)
- existing_methods += stubbee.protected_methods(true) - stubbee.superclass.protected_methods(true)
- existing_methods += stubbee.private_methods(true) - stubbee.superclass.private_methods(true)
- existing_methods.any? { |m| m.to_s == method.to_s }
- end
-
- end
-
-end
View
60 trunk/lib/mocha/configuration.rb
@@ -1,60 +0,0 @@
-module Mocha # :nodoc:
-
- # Configuration settings
- class Configuration
-
- DEFAULTS = { :stubbing_method_unnecessarily => :allow, :stubbing_method_on_non_mock_object => :allow, :stubbing_non_existent_method => :allow, :stubbing_non_public_method => :allow }
-
- class << self
-
- # :call-seq: allow(action)
- #
- # Allow the specified <tt>action</tt> (as a symbol).
- # The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>.
- def allow(action)
- configuration[action] = :allow
- end
-
- def allow?(action) # :nodoc:
- configuration[action] == :allow
- end
-
- # :call-seq: warn_when(action)
- #
- # Warn if the specified <tt>action</tt> (as a symbol) is attempted.
- # The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>.
- def warn_when(action)
- configuration[action] = :warn
- end
-
- def warn_when?(action) # :nodoc:
- configuration[action] == :warn
- end
-
- # :call-seq: prevent(action)
- #
- # Raise a StubbingError if the specified <tt>action</tt> (as a symbol) is attempted.
- # The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>.
- def prevent(action)
- configuration[action] = :prevent
- end
-
- def prevent?(action) # :nodoc:
- configuration[action] == :prevent
- end
-
- def reset_configuration # :nodoc:
- @configuration = nil
- end
-
- private
-
- def configuration # :nodoc:
- @configuration ||= DEFAULTS.dup
- end
-
- end
-
- end
-
-end
View
22 trunk/lib/mocha/deprecation.rb
@@ -1,22 +0,0 @@
-module Mocha
-
- class Deprecation
-
- class << self
-
- attr_accessor :mode, :messages
-
- def warning(message)
- @messages << message
- $stderr.puts "Mocha deprecation warning: #{message}" unless mode == :disabled
- $stderr.puts caller.join("\n ") if mode == :debug
- end
-
- end
-
- self.mode = :enabled
- self.messages = []
-
- end
-
-end
View
17 trunk/lib/mocha/exception_raiser.rb
@@ -1,17 +0,0 @@
-module Mocha # :nodoc:
-
- class ExceptionRaiser # :nodoc:
-
- def initialize(exception, message)
- @exception, @message = exception, message
- end
-
- def evaluate
- raise @exception, @exception.to_s if @exception.is_a?(Module) && @exception.ancestors.include?(Interrupt)
- raise @exception, @message if @message
- raise @exception
- end
-
- end
-
-end
View
445 trunk/lib/mocha/expectation.rb
@@ -1,445 +0,0 @@
-require 'mocha/method_matcher'
-require 'mocha/parameters_matcher'
-require 'mocha/expectation_error'
-require 'mocha/return_values'
-require 'mocha/exception_raiser'
-require 'mocha/yield_parameters'
-require 'mocha/is_a'
-require 'mocha/in_state_ordering_constraint'
-require 'mocha/change_state_side_effect'
-require 'mocha/cardinality'
-
-module Mocha # :nodoc:
-
- # Methods on expectations returned from Mock#expects, Mock#stubs, Object#expects and Object#stubs.
- class Expectation
-
- # :call-seq: times(range) -> expectation
- #
- # Modifies expectation so that the number of calls to the expected method must be within a specific +range+.
- #
- # +range+ can be specified as an exact integer or as a range of integers
- # object = mock()
- # object.expects(:expected_method).times(3)
- # 3.times { object.expected_method }
- # # => verify succeeds
- #
- # object = mock()
- # object.expects(:expected_method).times(3)
- # 2.times { object.expected_method }
- # # => verify fails
- #
- # object = mock()
- # object.expects(:expected_method).times(2..4)
- # 3.times { object.expected_method }
- # # => verify succeeds
- #
- # object = mock()
- # object.expects(:expected_method).times(2..4)
- # object.expected_method
- # # => verify fails
- def times(range)
- @cardinality = Cardinality.times(range)
- self
- end
-
- # :call-seq: once() -> expectation
- #
- # Modifies expectation so that the expected method must be called exactly once.
- # Note that this is the default behaviour for an expectation, but you may wish to use it for clarity/emphasis.
- # object = mock()
- # object.expects(:expected_method).once
- # object.expected_method
- # # => verify succeeds
- #
- # object = mock()
- # object.expects(:expected_method).once
- # object.expected_method
- # object.expected_method
- # # => verify fails
- #
- # object = mock()
- # object.expects(:expected_method).once
- # # => verify fails
- def once
- @cardinality = Cardinality.exactly(1)
- self
- end
-
- # :call-seq: never() -> expectation
- #
- # Modifies expectation so that the expected method must never be called.
- # object = mock()
- # object.expects(:expected_method).never
- # object.expected_method
- # # => verify fails
- #
- # object = mock()
- # object.expects(:expected_method).never
- # object.expected_method
- # # => verify succeeds
- def never
- @cardinality = Cardinality.exactly(0)
- self
- end
-
- # :call-seq: at_least(minimum_number_of_times) -> expectation
- #
- # Modifies expectation so that the expected method must be called at least a +minimum_number_of_times+.
- # object = mock()
- # object.expects(:expected_method).at_least(2)
- # 3.times { object.expected_method }
- # # => verify succeeds
- #
- # object = mock()
- # object.expects(:expected_method).at_least(2)
- # object.expected_method
- # # => verify fails
- def at_least(minimum_number_of_times)
- @cardinality = Cardinality.at_least(minimum_number_of_times)
- self
- end
-
- # :call-seq: at_least_once() -> expectation
- #
- # Modifies expectation so that the expected method must be called at least once.
- # object = mock()
- # object.expects(:expected_method).at_least_once
- # object.expected_method
- # # => verify succeeds
- #
- # object = mock()
- # object.expects(:expected_method).at_least_once
- # # => verify fails
- def at_least_once
- at_least(1)
- self
- end
-
- # :call-seq: at_most(maximum_number_of_times) -> expectation
- #
- # Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+.
- # object = mock()
- # object.expects(:expected_method).at_most(2)
- # 2.times { object.expected_method }
- # # => verify succeeds
- #
- # object = mock()
- # object.expects(:expected_method).at_most(2)
- # 3.times { object.expected_method }
- # # => verify fails
- def at_most(maximum_number_of_times)
- @cardinality = Cardinality.at_most(maximum_number_of_times)
- self
- end
-
- # :call-seq: at_most_once() -> expectation
- #
- # Modifies expectation so that the expected method must be called at most once.
- # object = mock()
- # object.expects(:expected_method).at_most_once
- # object.expected_method
- # # => verify succeeds
- #
- # object = mock()
- # object.expects(:expected_method).at_most_once
- # 2.times { object.expected_method }
- # # => verify fails
- def at_most_once()
- at_most(1)
- self
- end
-
- # :call-seq: with(*expected_parameters, &matching_block) -> expectation
- #
- # Modifies expectation so that the expected method must be called with +expected_parameters+.
- # object = mock()
- # object.expects(:expected_method).with(:param1, :param2)
- # object.expected_method(:param1, :param2)
- # # => verify succeeds
- #
- # object = mock()
- # object.expects(:expected_method).with(:param1, :param2)
- # object.expected_method(:param3)
- # # => verify fails
- # May be used with parameter matchers in Mocha::ParameterMatchers.
- #
- # If a +matching_block+ is given, the block is called with the parameters passed to the expected method.
- # The expectation is matched if the block evaluates to +true+.
- # object = mock()
- # object.expects(:expected_method).with() { |value| value % 4 == 0 }
- # object.expected_method(16)
- # # => verify succeeds
- #
- # object = mock()
- # object.expects(:expected_method).with() { |value| value % 4 == 0 }
- # object.expected_method(17)
- # # => verify fails
- def with(*expected_parameters, &matching_block)
- @parameters_matcher = ParametersMatcher.new(expected_parameters, &matching_block)
- self
- end
-
- # :call-seq: yields(*parameters) -> expectation
- #
- # Modifies expectation so that when the expected method is called, it yields with the specified +parameters+.
- # object = mock()
- # object.expects(:expected_method).yields('result')
- # yielded_value = nil
- # object.expected_method { |value| yielded_value = value }
- # yielded_value # => 'result'
- # May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then.
- # object = mock()
- # object.stubs(:expected_method).yields(1).then.yields(2)
- # yielded_values_from_first_invocation = []
- # yielded_values_from_second_invocation = []
- # object.expected_method { |value| yielded_values_from_first_invocation << value } # first invocation
- # object.expected_method { |value| yielded_values_from_second_invocation << value } # second invocation
- # yielded_values_from_first_invocation # => [1]
- # yielded_values_from_second_invocation # => [2]
- def yields(*parameters)
- @yield_parameters.add(*parameters)
- self
- end
-
- # :call-seq: multiple_yields(*parameter_groups) -> expectation
- #
- # Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+.
- # object = mock()
- # object.expects(:expected_method).multiple_yields(['result_1', 'result_2'], ['result_3'])
- # yielded_values = []
- # object.expected_method { |*values| yielded_values << values }
- # yielded_values # => [['result_1', 'result_2'], ['result_3]]
- # May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then.
- # object = mock()
- # object.stubs(:expected_method).multiple_yields([1, 2], [3]).then.multiple_yields([4], [5, 6])
- # yielded_values_from_first_invocation = []
- # yielded_values_from_second_invocation = []
- # object.expected_method { |*values| yielded_values_from_first_invocation << values } # first invocation
- # object.expected_method { |*values| yielded_values_from_second_invocation << values } # second invocation
- # yielded_values_from_first_invocation # => [[1, 2], [3]]
- # yielded_values_from_second_invocation # => [[4], [5, 6]]
- def multiple_yields(*parameter_groups)
- @yield_parameters.multiple_add(*parameter_groups)
- self
- end
-
- # :call-seq: returns(value) -> expectation
- # returns(*values) -> expectation
- #
- # Modifies expectation so that when the expected method is called, it returns the specified +value+.
- # object = mock()
- # object.stubs(:stubbed_method).returns('result')
- # object.stubbed_method # => 'result'
- # object.stubbed_method # => 'result'
- # If multiple +values+ are given, these are returned in turn on consecutive calls to the method.
- # object = mock()
- # object.stubs(:stubbed_method).returns(1, 2)
- # object.stubbed_method # => 1
- # object.stubbed_method # => 2
- # May be called multiple times on the same expectation. Also see Expectation#then.
- # object = mock()
- # object.stubs(:expected_method).returns(1, 2).then.returns(3)
- # object.expected_method # => 1
- # object.expected_method # => 2
- # object.expected_method # => 3
- # May be called in conjunction with Expectation#raises on the same expectation.
- # object = mock()
- # object.stubs(:expected_method).returns(1, 2).then.raises(Exception)
- # object.expected_method # => 1
- # object.expected_method # => 2
- # object.expected_method # => raises exception of class Exception1
- def returns(*values)
- @return_values += ReturnValues.build(*values)
- self
- end
-
- # :call-seq: raises(exception = RuntimeError, message = nil) -> expectation
- #
- # Modifies expectation so that when the expected method is called, it raises the specified +exception+ with the specified +message+.
- # object = mock()
- # object.expects(:expected_method).raises(Exception, 'message')
- # object.expected_method # => raises exception of class Exception and with message 'message'
- # May be called multiple times on the same expectation. Also see Expectation#then.
- # object = mock()
- # object.stubs(:expected_method).raises(Exception1).then.raises(Exception2)
- # object.expected_method # => raises exception of class Exception1
- # object.expected_method # => raises exception of class Exception2
- # May be called in conjunction with Expectation#returns on the same expectation.
- # object = mock()
- # object.stubs(:expected_method).raises(Exception).then.returns(2, 3)
- # object.expected_method # => raises exception of class Exception1
- # object.expected_method # => 2
- # object.expected_method # => 3
- def raises(exception = RuntimeError, message = nil)
- @return_values += ReturnValues.new(ExceptionRaiser.new(exception, message))
- self
- end
-
- # :call-seq: then() -> expectation
- # then(state_machine.is(state)) -> expectation
- #
- # <tt>then()</tt> is used as syntactic sugar to improve readability. It has no effect on state of the expectation.
- # object = mock()
- # object.stubs(:expected_method).returns(1, 2).then.raises(Exception).then.returns(4)
- # object.expected_method # => 1
- # object.expected_method # => 2
- # object.expected_method # => raises exception of class Exception
- # object.expected_method # => 4
- #
- # <tt>then(state_machine.is(state))</tt> is used to change the +state_machine+ to the specified +state+ when the invocation occurs.
- #
- # See also Standalone#states, StateMachine and Expectation#when.
- # power = states('power').starts_as('off')
- #
- # radio = mock('radio')
- # radio.expects(:switch_on).then(power.is('on'))
- # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on'))
- # radio.expects(:adjust_volume).with(+5).when(power.is('on'))
- # radio.expects(:select_channel).with('BBC World Service').when(power.is('on'))
- # radio.expects(:adjust_volume).with(-5).when(power.is('on'))
- # radio.expects(:switch_off).then(power.is('off'))
- def then(*parameters)
- if parameters.length == 1
- state = parameters.first
- add_side_effect(ChangeStateSideEffect.new(state))
- end
- self
- end
-
- # :call-seq: when(state_machine.is(state)) -> exception
- #
- # Constrains the expectation to occur only when the +state_machine+ is in the named +state+.
- #
- # See also Standalone#states, StateMachine#starts_as and Expectation#then.
- # power = states('power').starts_as('off')
- #
- # radio = mock('radio')
- # radio.expects(:switch_on).then(power.is('on'))
- # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on'))
- # radio.expects(:adjust_volume).with(+5).when(power.is('on'))
- # radio.expects(:select_channel).with('BBC World Service').when(power.is('on'))
- # radio.expects(:adjust_volume).with(-5).when(power.is('on'))
- # radio.expects(:switch_off).then(power.is('off'))
- def when(state_predicate)
- add_ordering_constraint(InStateOrderingConstraint.new(state_predicate))
- self
- end
-
- # :call-seq: in_sequence(*sequences) -> expectation
- #
- # Constrains this expectation so that it must be invoked at the current point in the sequence.
- #
- # To expect a sequence of invocations, write the expectations in order and add the in_sequence(sequence) clause to each one.
- #
- # Expectations in a sequence can have any invocation count.
- #
- # If an expectation in a sequence is stubbed, rather than expected, it can be skipped in the sequence.
- #
- # See also Standalone#sequence.
- # breakfast = sequence('breakfast')
- #
- # egg = mock('egg')
- # egg.expects(:crack).in_sequence(breakfast)
- # egg.expects(:fry).in_sequence(breakfast)
- # egg.expects(:eat).in_sequence(breakfast)
- def in_sequence(*sequences)
- sequences.each { |sequence| add_in_sequence_ordering_constraint(sequence) }
- self
- end
-
- # :stopdoc:
-
- attr_reader :backtrace
-
- def initialize(mock, expected_method_name, backtrace = nil)
- @mock = mock
- @method_matcher = MethodMatcher.new(expected_method_name)
- @parameters_matcher = ParametersMatcher.new
- @ordering_constraints = []
- @side_effects = []
- @cardinality, @invocation_count = Cardinality.exactly(1), 0
- @return_values = ReturnValues.new
- @yield_parameters = YieldParameters.new
- @backtrace = backtrace || caller
- end
-
- def add_ordering_constraint(ordering_constraint)
- @ordering_constraints << ordering_constraint
- end
-
- def add_in_sequence_ordering_constraint(sequence)
- sequence.constrain_as_next_in_sequence(self)
- end
-
- def add_side_effect(side_effect)
- @side_effects << side_effect
- end
-
- def perform_side_effects
- @side_effects.each { |side_effect| side_effect.perform }
- end
-
- def in_correct_order?
- @ordering_constraints.all? { |ordering_constraint| ordering_constraint.allows_invocation_now? }
- end
-
- def matches_method?(method_name)
- @method_matcher.match?(method_name)
- end
-
- def match?(actual_method_name, *actual_parameters)
- @method_matcher.match?(actual_method_name) && @parameters_matcher.match?(actual_parameters) && in_correct_order?
- end
-
- def invocations_allowed?
- @cardinality.invocations_allowed?(@invocation_count)
- end
-
- def satisfied?
- @cardinality.satisfied?(@invocation_count)
- end
-
- def invoke
- @invocation_count += 1
- perform_side_effects()
- if block_given? then
- @yield_parameters.next_invocation.each do |yield_parameters|
- yield(*yield_parameters)
- end
- end
- @return_values.next
- end
-
- def verified?(assertion_counter = nil)
- assertion_counter.increment if assertion_counter && @cardinality.needs_verifying?
- @cardinality.verified?(@invocation_count)
- end
-
- def used?
- @cardinality.used?(@invocation_count)
- end
-
- def mocha_inspect
- message = "#{@cardinality.mocha_inspect}, "
- if @invocation_count > 0
- message << "already invoked #{@invocation_count} time"
- message << "s" if @invocation_count > 1
- else
- message << "never invoked"
- end
- message << ": "
- message << method_signature
- message << "; #{@ordering_constraints.map { |oc| oc.mocha_inspect }.join("; ")}" unless @ordering_constraints.empty?
- message
- end
-
- def method_signature
- "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}"
- end
-
- # :startdoc:
-
- end
-
-end
View
15 trunk/lib/mocha/expectation_error.rb
@@ -1,15 +0,0 @@
-require 'mocha/backtrace_filter'
-
-module Mocha
-
- class ExpectationError < StandardError
-
- def initialize(message = nil, backtrace = [])
- super(message)
- filter = BacktraceFilter.new
- set_backtrace(filter.filtered(backtrace))
- end
-
- end
-
-end
View
42 trunk/lib/mocha/expectation_list.rb
@@ -1,42 +0,0 @@
-module Mocha # :nodoc:
-
- class ExpectationList
-
- def initialize
- @expectations = []
- end
-
- def add(expectation)
- @expectations << expectation
- expectation
- end
-
- def matches_method?(method_name)
- @expectations.any? { |expectation| expectation.matches_method?(method_name) }
- end
-
- def detect(method_name, *arguments)
- expectations = @expectations.reverse.select { |e| e.match?(method_name, *arguments) }
- expectation = expectations.detect { |e| e.invocations_allowed? }
- expectation || expectations.first
- end
-
- def verified?(assertion_counter = nil)
- @expectations.all? { |expectation| expectation.verified?(assertion_counter) }
- end
-
- def to_a
- @expectations
- end
-
- def to_set
- @expectations.to_set
- end
-
- def length
- @expectations.length
- end
-
- end
-
-end
View
19 trunk/lib/mocha/in_state_ordering_constraint.rb
@@ -1,19 +0,0 @@
-module Mocha
-
- class InStateOrderingConstraint
-
- def initialize(state_predicate)
- @state_predicate = state_predicate
- end
-
- def allows_invocation_now?
- @state_predicate.active?
- end
-
- def mocha_inspect
- "when #{@state_predicate.mocha_inspect}"
- end
-
- end
-
-end
View
39 trunk/lib/mocha/inspect.rb
@@ -1,39 +0,0 @@
-require 'date'
-
-class Object
- def mocha_inspect
- address = self.__id__ * 2
- address += 0x100000000 if address < 0
- inspect =~ /#</ ? "#<#{self.class}:0x#{'%x' % address}>" : inspect
- end
-end
-
-class String
- def mocha_inspect
- inspect.gsub(/\"/, "'")
- end
-end
-
-class Array
- def mocha_inspect
- "[#{collect { |member| member.mocha_inspect }.join(', ')}]"
- end
-end
-
-class Hash
- def mocha_inspect
- "{#{collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')}}"
- end
-end
-
-class Time
- def mocha_inspect
- "#{inspect} (#{to_f} secs)"
- end
-end
-
-class Date
- def mocha_inspect
- to_s
- end
-end
View
17 trunk/lib/mocha/instance_method.rb
@@ -1,17 +0,0 @@
-require 'mocha/class_method'
-
-module Mocha
-
- class InstanceMethod < ClassMethod
-
- def method_exists?(method)
- existing_methods = []
- existing_methods += stubbee.public_methods(false)
- existing_methods += stubbee.protected_methods(false)
- existing_methods += stubbee.private_methods(false)
- existing_methods.any? { |m| m.to_s == method.to_s }
- end
-
- end
-
-end
View
9 trunk/lib/mocha/is_a.rb
@@ -1,9 +0,0 @@
-class Object
-
- # :stopdoc:
-
- alias_method :__is_a__, :is_a?
-
- # :startdoc:
-
-end
View
15 trunk/lib/mocha/logger.rb
@@ -1,15 +0,0 @@
-module Mocha
-
- class Logger
-
- def initialize(io)
- @io = io
- end
-
- def warn(message)
- @io.puts "WARNING: #{message}"
- end
-
- end
-
-end
View
7 trunk/lib/mocha/metaclass.rb
@@ -1,7 +0,0 @@
-class Object
-
- def __metaclass__
- class << self; self; end
- end
-
-end
View
21 trunk/lib/mocha/method_matcher.rb
@@ -1,21 +0,0 @@
-module Mocha
-
- class MethodMatcher
-
- attr_reader :expected_method_name
-
- def initialize(expected_method_name)
- @expected_method_name = expected_method_name
- end
-
- def match?(actual_method_name)
- @expected_method_name == actual_method_name
- end
-
- def mocha_inspect
- "#{@expected_method_name}"
- end
-
- end
-
-end
View
207 trunk/lib/mocha/mock.rb
@@ -1,207 +0,0 @@
-require 'mocha/expectation'
-require 'mocha/expectation_list'
-require 'mocha/metaclass'
-require 'mocha/names'
-require 'mocha/mockery'
-require 'mocha/method_matcher'
-require 'mocha/parameters_matcher'
-
-<