Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Tagging 0.9.0 release again after previously removing it.

  • Loading branch information...
commit 6c0513ffac3ca6be0c66fc0f8bbb49b2c6b4064b 2 parents ab6e4a2 + e162cd7
James Mead floehopper authored

Showing 332 changed files with 1,160 additions and 16,443 deletions. Show diff stats Hide diff stats

  1. +57 33 Rakefile
  2. +15 13 TODO
  3. +44 36 examples/misc.rb
  4. +1 1  examples/stubba.rb
  5. +1 0  lib/mocha.rb
  6. +24 4 lib/mocha/any_instance_method.rb
  7. +0 111 lib/mocha/auto_verify.rb
  8. 0  {trunk → }/lib/mocha/backtrace_filter.rb
  9. 0  {trunk → }/lib/mocha/cardinality.rb
  10. +2 10 lib/mocha/central.rb
  11. 0  {trunk → }/lib/mocha/change_state_side_effect.rb
  12. +30 6 lib/mocha/class_method.rb
  13. 0  {trunk → }/lib/mocha/configuration.rb
  14. +1 1  lib/mocha/exception_raiser.rb
  15. +152 89 lib/mocha/expectation.rb
  16. +10 1 lib/mocha/expectation_error.rb
  17. +17 20 lib/mocha/expectation_list.rb
  18. 0  {trunk → }/lib/mocha/in_state_ordering_constraint.rb
  19. +0 25 lib/mocha/infinite_range.rb
  20. +9 0 lib/mocha/instance_method.rb
  21. 0  {trunk → }/lib/mocha/logger.rb
  22. 0  {trunk → }/lib/mocha/method_matcher.rb
  23. +0 27 lib/mocha/missing_expectation.rb
  24. +44 37 lib/mocha/mock.rb
  25. 0  {trunk → }/lib/mocha/mockery.rb
  26. 0  {trunk → }/lib/mocha/module_method.rb
  27. 0  {trunk → }/lib/mocha/names.rb
  28. +26 9 lib/mocha/object.rb
  29. +19 2 lib/mocha/parameter_matchers.rb
  30. +8 5 lib/mocha/parameter_matchers/all_of.rb
  31. +8 5 lib/mocha/parameter_matchers/any_of.rb
  32. 0  {trunk → }/lib/mocha/parameter_matchers/any_parameters.rb
  33. +6 3 lib/mocha/parameter_matchers/anything.rb
  34. 0  {trunk → }/lib/mocha/parameter_matchers/base.rb
  35. 0  {trunk → }/lib/mocha/parameter_matchers/equals.rb
  36. 0  {trunk → }/lib/mocha/parameter_matchers/has_entries.rb
  37. +23 6 lib/mocha/parameter_matchers/has_entry.rb
  38. +6 3 lib/mocha/parameter_matchers/has_key.rb
  39. +6 3 lib/mocha/parameter_matchers/has_value.rb
  40. +5 2 lib/mocha/parameter_matchers/includes.rb
  41. +5 2 lib/mocha/parameter_matchers/instance_of.rb
  42. 0  {trunk → }/lib/mocha/parameter_matchers/is_a.rb
  43. +5 2 lib/mocha/parameter_matchers/kind_of.rb
  44. 0  {trunk → }/lib/mocha/parameter_matchers/not.rb
  45. 0  {trunk → }/lib/mocha/parameter_matchers/object.rb
  46. 0  {trunk → }/lib/mocha/parameter_matchers/optionally.rb
  47. +7 4 lib/mocha/parameter_matchers/regexp_matches.rb
  48. 0  {trunk → }/lib/mocha/parameter_matchers/responds_with.rb
  49. 0  {trunk → }/lib/mocha/parameter_matchers/yaml_equivalent.rb
  50. 0  {trunk → }/lib/mocha/parameters_matcher.rb
  51. +1 1  lib/mocha/pretty_parameters.rb
  52. +7 4 lib/mocha/return_values.rb
  53. 0  {trunk → }/lib/mocha/sequence.rb
  54. +0 23 lib/mocha/setup_and_teardown.rb
  55. +2 9 lib/mocha/single_return_value.rb
  56. +151 17 lib/mocha/standalone.rb
  57. 0  {trunk → }/lib/mocha/state_machine.rb
  58. +0 18 lib/mocha/stub.rb
  59. 0  {trunk → }/lib/mocha/stubbing_error.rb
  60. +76 22 lib/mocha/test_case_adapter.rb
  61. +3 3 lib/mocha/yield_parameters.rb
  62. +2 1  lib/stubba.rb
  63. 0  {trunk → }/test/acceptance/acceptance_test_helper.rb
  64. 0  {trunk → }/test/acceptance/bug_18914_test.rb
  65. +0 187 test/acceptance/expected_invocation_count_acceptance_test.rb
  66. 0  {trunk → }/test/acceptance/expected_invocation_count_test.rb
  67. 0  {trunk → }/test/acceptance/failure_messages_test.rb
  68. +0 98 test/acceptance/mocha_acceptance_test.rb
  69. 0  {trunk → }/test/acceptance/mocha_example_test.rb
  70. 0  {trunk → }/test/acceptance/mocha_test_result_test.rb
  71. 0  {trunk → }/test/acceptance/mock_test.rb
  72. 0  {trunk → }/test/acceptance/mock_with_initializer_block_test.rb
  73. +0 71 test/acceptance/mocked_methods_dispatch_acceptance_test.rb
  74. 0  {trunk → }/test/acceptance/mocked_methods_dispatch_test.rb
  75. 0  {trunk → }/test/acceptance/optional_parameters_test.rb
  76. +0 81 test/acceptance/parameter_matcher_acceptance_test.rb
  77. 0  {trunk → }/test/acceptance/parameter_matcher_test.rb
  78. 0  {trunk → }/test/acceptance/partial_mocks_test.rb
  79. 0  {trunk → }/test/acceptance/return_value_test.rb
  80. 0  {trunk → }/test/acceptance/sequence_test.rb
  81. +0 131 test/acceptance/standalone_acceptance_test.rb
  82. 0  {trunk → }/test/acceptance/standalone_test.rb
  83. 0  {trunk → }/test/acceptance/states_test.rb
  84. 0  {trunk → }/test/acceptance/stub_any_instance_method_test.rb
  85. 0  {trunk → }/test/acceptance/stub_class_method_test.rb
  86. 0  {trunk → }/test/acceptance/stub_everything_test.rb
  87. 0  {trunk → }/test/acceptance/stub_instance_method_test.rb
  88. 0  {trunk → }/test/acceptance/stub_module_method_test.rb
  89. 0  {trunk → }/test/acceptance/stub_test.rb
  90. +0 102 test/acceptance/stubba_acceptance_test.rb
  91. 0  {trunk → }/test/acceptance/stubba_example_test.rb
  92. 0  {trunk → }/test/acceptance/stubba_test_result_test.rb
  93. 0  {trunk → }/test/acceptance/stubbing_error_backtrace_test.rb
  94. 0  {trunk → }/test/acceptance/stubbing_method_unnecessarily_test.rb
  95. 0  {trunk → }/test/acceptance/stubbing_non_existent_any_instance_method_test.rb
  96. 0  {trunk → }/test/acceptance/stubbing_non_existent_class_method_test.rb
  97. 0  {trunk → }/test/acceptance/stubbing_non_existent_instance_method_test.rb
  98. 0  {trunk → }/test/acceptance/stubbing_non_public_any_instance_method_test.rb
  99. 0  {trunk → }/test/acceptance/stubbing_non_public_class_method_test.rb
  100. 0  {trunk → }/test/acceptance/stubbing_non_public_instance_method_test.rb
  101. 0  {trunk → }/test/acceptance/stubbing_on_non_mock_object_test.rb
  102. +3 1 test/execution_point.rb
  103. +0 105 test/integration/mocha_test_result_integration_test.rb
  104. +0 89 test/integration/stubba_integration_test.rb
  105. +0 85 test/integration/stubba_test_result_integration_test.rb
  106. 0  {trunk → }/test/simple_counter.rb
  107. +0 1  test/test_helper.rb
  108. +8 6 test/test_runner.rb
  109. +3 1 test/unit/any_instance_method_test.rb
  110. +1 1  test/unit/array_inspect_test.rb
  111. +0 122 test/unit/auto_verify_test.rb
  112. 0  {trunk → }/test/unit/backtrace_filter_test.rb
  113. 0  {trunk → }/test/unit/cardinality_test.rb
  114. +4 63 test/unit/central_test.rb
  115. 0  {trunk → }/test/unit/change_state_side_effect_test.rb
  116. +42 1 test/unit/class_method_test.rb
  117. +1 1  test/unit/date_time_inspect_test.rb
  118. 0  {trunk → }/test/unit/exception_raiser_test.rb
  119. +9 21 test/unit/expectation_list_test.rb
  120. +0 28 test/unit/expectation_raiser_test.rb
  121. +175 115 test/unit/expectation_test.rb
  122. 0  {trunk → }/test/unit/in_state_ordering_constraint_test.rb
  123. +0 53 test/unit/infinite_range_test.rb
  124. 0  {trunk → }/test/unit/method_matcher_test.rb
  125. +0 45 test/unit/missing_expectation_test.rb
  126. +39 53 test/unit/mock_test.rb
  127. 0  {trunk → }/test/unit/mockery_test.rb
  128. +0 18 test/unit/no_yield_test.rb
  129. 0  {trunk → }/test/unit/no_yields_test.rb
  130. +4 2 test/unit/object_inspect_test.rb
  131. +6 89 test/unit/object_test.rb
  132. +2 2 test/unit/parameter_matchers/all_of_test.rb
  133. +2 2 test/unit/parameter_matchers/any_of_test.rb
  134. +2 2 test/unit/parameter_matchers/anything_test.rb
  135. 0  {trunk → }/test/unit/parameter_matchers/equals_test.rb
  136. 0  {trunk → }/test/unit/parameter_matchers/has_entries_test.rb
  137. +43 6 test/unit/parameter_matchers/has_entry_test.rb
  138. +13 2 test/unit/parameter_matchers/has_key_test.rb
  139. +14 2 test/unit/parameter_matchers/has_value_test.rb
  140. +2 2 test/unit/parameter_matchers/includes_test.rb
  141. +2 2 test/unit/parameter_matchers/instance_of_test.rb
  142. 0  {trunk → }/test/unit/parameter_matchers/is_a_test.rb
  143. +3 3 test/unit/parameter_matchers/kind_of_test.rb
  144. 0  {trunk → }/test/unit/parameter_matchers/not_test.rb
  145. +3 3 test/unit/parameter_matchers/regexp_matches_test.rb
  146. 0  {trunk → }/test/unit/parameter_matchers/responds_with_test.rb
  147. +6 1 test/unit/parameter_matchers/stub_matcher.rb
  148. 0  {trunk → }/test/unit/parameter_matchers/yaml_equivalent_test.rb
  149. 0  {trunk → }/test/unit/parameters_matcher_test.rb
  150. +0 32 test/unit/pretty_parameters_test.rb
  151. 0  {trunk → }/test/unit/sequence_test.rb
  152. +0 76 test/unit/setup_and_teardown_test.rb
  153. +0 19 test/unit/single_return_value_test.rb
  154. 0  {trunk → }/test/unit/state_machine_test.rb
  155. +0 24 test/unit/stub_test.rb
  156. +0 3  trunk/COPYING
  157. +0 7 trunk/MIT-LICENSE
  158. +0 35 trunk/README
  159. +0 233 trunk/RELEASE
  160. +0 171 trunk/Rakefile
  161. +0 50 trunk/TODO
  162. +0 44 trunk/examples/misc.rb
  163. +0 26 trunk/examples/mocha.rb
  164. +0 65 trunk/examples/stubba.rb
  165. +0 3  trunk/init.rb
  166. +0 20 trunk/lib/mocha.rb
  167. +0 55 trunk/lib/mocha/any_instance_method.rb
  168. +0 27 trunk/lib/mocha/central.rb
  169. +0 86 trunk/lib/mocha/class_method.rb
  170. +0 22 trunk/lib/mocha/deprecation.rb
  171. +0 17 trunk/lib/mocha/exception_raiser.rb
  172. +0 445 trunk/lib/mocha/expectation.rb
  173. +0 15 trunk/lib/mocha/expectation_error.rb
  174. +0 42 trunk/lib/mocha/expectation_list.rb
  175. +0 39 trunk/lib/mocha/inspect.rb
  176. +0 17 trunk/lib/mocha/instance_method.rb
  177. +0 9 trunk/lib/mocha/is_a.rb
  178. +0 7 trunk/lib/mocha/metaclass.rb
  179. +0 207 trunk/lib/mocha/mock.rb
  180. +0 20 trunk/lib/mocha/multiple_yields.rb
  181. +0 11 trunk/lib/mocha/no_yields.rb
  182. +0 127 trunk/lib/mocha/object.rb
  183. +0 26 trunk/lib/mocha/parameter_matchers.rb
  184. +0 42 trunk/lib/mocha/parameter_matchers/all_of.rb
  185. +0 47 trunk/lib/mocha/parameter_matchers/any_of.rb
  186. +0 33 trunk/lib/mocha/parameter_matchers/anything.rb
  187. +0 56 trunk/lib/mocha/parameter_matchers/has_entry.rb
  188. +0 42 trunk/lib/mocha/parameter_matchers/has_key.rb
  189. +0 42 trunk/lib/mocha/parameter_matchers/has_value.rb
  190. +0 40 trunk/lib/mocha/parameter_matchers/includes.rb
  191. +0 42 trunk/lib/mocha/parameter_matchers/instance_of.rb
  192. +0 42 trunk/lib/mocha/parameter_matchers/kind_of.rb
  193. +0 43 trunk/lib/mocha/parameter_matchers/regexp_matches.rb
  194. +0 28 trunk/lib/mocha/pretty_parameters.rb
  195. +0 34 trunk/lib/mocha/return_values.rb
  196. +0 17 trunk/lib/mocha/single_return_value.rb
  197. +0 18 trunk/lib/mocha/single_yield.rb
  198. +0 166 trunk/lib/mocha/standalone.rb
  199. +0 103 trunk/lib/mocha/test_case_adapter.rb
  200. +0 31 trunk/lib/mocha/yield_parameters.rb
  201. +0 2  trunk/lib/mocha_standalone.rb
  202. +0 3  trunk/lib/stubba.rb
  203. +0 746 trunk/templates/html_with_google_analytics.rb
  204. +0 36 trunk/test/active_record_test_case.rb
  205. +0 15 trunk/test/deprecation_disabler.rb
  206. +0 36 trunk/test/execution_point.rb
  207. +0 18 trunk/test/method_definer.rb
  208. +0 11 trunk/test/test_helper.rb
  209. +0 33 trunk/test/test_runner.rb
  210. +0 126 trunk/test/unit/any_instance_method_test.rb
  211. +0 16 trunk/test/unit/array_inspect_test.rb
  212. +0 65 trunk/test/unit/central_test.rb
  213. +0 237 trunk/test/unit/class_method_test.rb
  214. +0 21 trunk/test/unit/date_time_inspect_test.rb
  215. +0 57 trunk/test/unit/expectation_list_test.rb
  216. +0 459 trunk/test/unit/expectation_test.rb
  217. +0 16 trunk/test/unit/hash_inspect_test.rb
  218. +0 22 trunk/test/unit/metaclass_test.rb
  219. +0 302 trunk/test/unit/mock_test.rb
  220. +0 18 trunk/test/unit/multiple_yields_test.rb
  221. +0 37 trunk/test/unit/object_inspect_test.rb
  222. +0 82 trunk/test/unit/object_test.rb
  223. +0 26 trunk/test/unit/parameter_matchers/all_of_test.rb
  224. +0 26 trunk/test/unit/parameter_matchers/any_of_test.rb
  225. +0 21 trunk/test/unit/parameter_matchers/anything_test.rb
  226. +0 62 trunk/test/unit/parameter_matchers/has_entry_test.rb
  227. +0 36 trunk/test/unit/parameter_matchers/has_key_test.rb
  228. +0 37 trunk/test/unit/parameter_matchers/has_value_test.rb
  229. +0 25 trunk/test/unit/parameter_matchers/includes_test.rb
  230. +0 25 trunk/test/unit/parameter_matchers/instance_of_test.rb
  231. +0 25 trunk/test/unit/parameter_matchers/kind_of_test.rb
  232. +0 25 trunk/test/unit/parameter_matchers/regexp_matches_test.rb
  233. +0 27 trunk/test/unit/parameter_matchers/stub_matcher.rb
  234. +0 63 trunk/test/unit/return_values_test.rb
  235. +0 14 trunk/test/unit/single_return_value_test.rb
  236. +0 18 trunk/test/unit/single_yield_test.rb
  237. +0 11 trunk/test/unit/string_inspect_test.rb
  238. +0 93 trunk/test/unit/yield_parameters_test.rb
  239. +0 53 trunk/vendor/coderay-0.7.4.215/FOLDERS
  240. +0 340 trunk/vendor/coderay-0.7.4.215/LICENSE
  241. +0 117 trunk/vendor/coderay-0.7.4.215/README
  242. +0 77 trunk/vendor/coderay-0.7.4.215/bin/coderay
  243. +0 4 trunk/vendor/coderay-0.7.4.215/bin/coderay_stylesheet
  244. +0 319 trunk/vendor/coderay-0.7.4.215/lib/coderay.rb
  245. +0 29 trunk/vendor/coderay-0.7.4.215/lib/coderay/duo.rb
  246. +0 173 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoder.rb
  247. +0 8 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/_map.rb
  248. +0 21 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/count.rb
  249. +0 46 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/debug.rb
  250. +0 20 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/div.rb
  251. +0 260 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/html.rb
  252. +0 77 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/classes.rb
  253. +0 65 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/css.rb
  254. +0 122 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/numerization.rb
  255. +0 195 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/output.rb
  256. +0 26 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/null.rb
  257. +0 21 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/page.rb
  258. +0 20 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/span.rb
  259. +0 81 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/statistic.rb
  260. +0 33 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/text.rb
  261. +0 44 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/tokens.rb
  262. +0 71 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/xml.rb
  263. +0 22 trunk/vendor/coderay-0.7.4.215/lib/coderay/encoders/yaml.rb
  264. +0 182 trunk/vendor/coderay-0.7.4.215/lib/coderay/helpers/file_type.rb
  265. +0 122 trunk/vendor/coderay-0.7.4.215/lib/coderay/helpers/gzip_simple.rb
  266. +0 326 trunk/vendor/coderay-0.7.4.215/lib/coderay/helpers/plugin.rb
  267. +0 119 trunk/vendor/coderay-0.7.4.215/lib/coderay/helpers/word_list.rb
  268. +0 238 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanner.rb
  269. +0 15 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/_map.rb
  270. +0 163 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/c.rb
  271. +0 60 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/debug.rb
  272. +0 149 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/delphi.rb
  273. +0 177 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/html.rb
  274. +0 133 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/nitro_xhtml.rb
  275. +0 16 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/plaintext.rb
  276. +0 73 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/rhtml.rb
  277. +0 367 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/ruby.rb
  278. +0 230 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/ruby/patterns.rb
  279. +0 18 trunk/vendor/coderay-0.7.4.215/lib/coderay/scanners/xml.rb
  280. +0 20 trunk/vendor/coderay-0.7.4.215/lib/coderay/style.rb
  281. +0 7 trunk/vendor/coderay-0.7.4.215/lib/coderay/styles/_map.rb
  282. +0 125 trunk/vendor/coderay-0.7.4.215/lib/coderay/styles/cycnus.rb
  283. +0 119 trunk/vendor/coderay-0.7.4.215/lib/coderay/styles/murphy.rb
  284. +0 368 trunk/vendor/coderay-0.7.4.215/lib/coderay/tokens.rb
  285. +0 295 trunk/vendor/meta_project-0.4.15/CHANGES
  286. +0 21 trunk/vendor/meta_project-0.4.15/MIT-LICENSE
  287. +0 129 trunk/vendor/meta_project-0.4.15/README
  288. +0 152 trunk/vendor/meta_project-0.4.15/Rakefile
  289. +0 2  trunk/vendor/meta_project-0.4.15/doc/base_attrs.rdoc
  290. +0 19 trunk/vendor/meta_project-0.4.15/lib/meta_project.rb
  291. +0 22 trunk/vendor/meta_project-0.4.15/lib/meta_project/core_ext/open_uri.rb
  292. +0 36 trunk/vendor/meta_project-0.4.15/lib/meta_project/core_ext/pathname.rb
  293. +0 5 trunk/vendor/meta_project-0.4.15/lib/meta_project/core_ext/string.rb
  294. +0 32 trunk/vendor/meta_project-0.4.15/lib/meta_project/http/multipart.rb
  295. +0 1  trunk/vendor/meta_project-0.4.15/lib/meta_project/patois.rb
  296. +0 99 trunk/vendor/meta_project-0.4.15/lib/meta_project/patois/parser.rb
  297. +0 4 trunk/vendor/meta_project-0.4.15/lib/meta_project/project.rb
  298. +0 9 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/base.rb
  299. +0 1  trunk/vendor/meta_project-0.4.15/lib/meta_project/project/codehaus.rb
  300. +0 31 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/codehaus/codehaus_project_svn.rb
  301. +0 1  trunk/vendor/meta_project-0.4.15/lib/meta_project/project/trac.rb
  302. +0 54 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/trac/trac_project.rb
  303. +0 5 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge.rb
  304. +0 47 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/ruby_forge.rb
  305. +0 177 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/session.rb
  306. +0 50 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/source_forge.rb
  307. +0 45 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/xfile.rb
  308. +0 85 trunk/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/xforge_base.rb
  309. +0 36 trunk/vendor/meta_project-0.4.15/lib/meta_project/project_analyzer.rb
  310. +0 267 trunk/vendor/meta_project-0.4.15/lib/meta_project/release/freshmeat.rb
  311. +0 572 trunk/vendor/meta_project-0.4.15/lib/meta_project/release/raa.rb
  312. +0 2  trunk/vendor/meta_project-0.4.15/lib/meta_project/scm_web.rb
  313. +0 112 trunk/vendor/meta_project-0.4.15/lib/meta_project/scm_web/browser.rb
  314. +0 89 trunk/vendor/meta_project-0.4.15/lib/meta_project/scm_web/pathname.rb
  315. +0 6 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker.rb
  316. +0 24 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/base.rb
  317. +0 34 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/digit_issues.rb
  318. +0 57 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/issue.rb
  319. +0 2  trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/jira.rb
  320. +0 35 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/jira/jira_issues.rb
  321. +0 149 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/jira/jira_tracker.rb
  322. +0 1  trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/trac.rb
  323. +0 33 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/trac/trac_tracker.rb
  324. +0 3  trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge.rb
  325. +0 17 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge/ruby_forge_tracker.rb
  326. +0 17 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge/source_forge_tracker.rb
  327. +0 191 trunk/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge/xforge_tracker.rb
  328. +0 52 trunk/vendor/meta_project-0.4.15/lib/meta_project/version_parser.rb
  329. +0 3  trunk/vendor/meta_project-0.4.15/lib/rake/contrib/xforge.rb
  330. +0 64 trunk/vendor/meta_project-0.4.15/lib/rake/contrib/xforge/base.rb
  331. +0 97 trunk/vendor/meta_project-0.4.15/lib/rake/contrib/xforge/news_publisher.rb
  332. +0 134 trunk/vendor/meta_project-0.4.15/lib/rake/contrib/xforge/release.rb
90 Rakefile
@@ -5,50 +5,72 @@ require 'rake/testtask'
5 5 require 'rake/contrib/sshpublisher'
6 6
7 7 module Mocha
8   - VERSION = "0.5.5"
  8 + VERSION = "0.5.6"
9 9 end
10 10
11 11 desc "Run all tests"
12   -task :default => :test_all
13   -
14   -task :test_all => [:test_unit, :test_integration, :test_acceptance]
15   -
16   -desc "Run unit tests"
17   -Rake::TestTask.new(:test_unit) do |t|
18   - t.libs << 'test'
19   - t.test_files = FileList['test/unit/**/*_test.rb']
20   - t.verbose = true
21   - t.warning = true
22   -end
  12 +task 'default' => ['test:units', 'test:acceptance']
  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
23 26
24   -desc "Run integration tests"
25   -Rake::TestTask.new(:test_integration) do |t|
26   - t.libs << 'test'
27   - t.test_files = FileList['test/integration/*_test.rb']
28   - t.verbose = true
29   - t.warning = true
30   -end
  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
31 44
32   -desc "Run acceptance tests"
33   -Rake::TestTask.new(:test_acceptance) do |t|
34   - t.libs << 'test'
35   - t.test_files = FileList['test/acceptance/*_test.rb']
36   - t.verbose = true
37   - t.warning = true
38 45 end
39 46
40 47 desc 'Generate RDoc'
41   -Rake::RDocTask.new do |task|
  48 +Rake::RDocTask.new('rdoc') do |task|
42 49 task.main = 'README'
43 50 task.title = "Mocha #{Mocha::VERSION}"
44 51 task.rdoc_dir = 'doc'
45 52 task.template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics"))
46   - task.rdoc_files.include('README', 'RELEASE', 'COPYING', 'MIT-LICENSE', 'agiledox.txt', 'lib/mocha/auto_verify.rb', 'lib/mocha/mock.rb', 'lib/mocha/expectation.rb', 'lib/mocha/object.rb', 'lib/mocha/parameter_matchers.rb', 'lib/mocha/parameter_matchers')
  53 + task.rdoc_files.include(
  54 + 'README',
  55 + 'RELEASE',
  56 + 'COPYING',
  57 + 'MIT-LICENSE',
  58 + 'agiledox.txt',
  59 + 'lib/mocha/standalone.rb',
  60 + 'lib/mocha/mock.rb',
  61 + 'lib/mocha/expectation.rb',
  62 + 'lib/mocha/object.rb',
  63 + 'lib/mocha/parameter_matchers.rb',
  64 + 'lib/mocha/parameter_matchers',
  65 + 'lib/mocha/state_machine.rb',
  66 + 'lib/mocha/configuration.rb',
  67 + 'lib/mocha/stubbing_error.rb'
  68 + )
47 69 end
48   -task :rdoc => :examples
  70 +task 'rdoc' => 'examples'
49 71
50 72 desc "Upload RDoc to RubyForge"
51   -task :publish_rdoc => [:rdoc, :examples] do
  73 +task 'publish_rdoc' => ['rdoc', 'examples'] do
52 74 Rake::SshDirPublisher.new("jamesmead@rubyforge.org", "/var/www/gforge-projects/mocha", "doc").upload
53 75 end
54 76
@@ -69,7 +91,7 @@ file 'agiledox.txt' do
69 91 end
70 92
71 93 desc "Convert example ruby files to syntax-highlighted html"
72   -task :examples do
  94 +task 'examples' do
73 95 $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "vendor", "coderay-0.7.4.215", "lib"))
74 96 require 'coderay'
75 97 mkdir_p 'doc/examples'
@@ -96,6 +118,7 @@ specification = Gem::Specification.new do |s|
96 118 s.name = "mocha"
97 119 s.summary = "Mocking and stubbing library"
98 120 s.version = Mocha::VERSION
  121 + s.platform = Gem::Platform::RUBY
99 122 s.author = 'James Mead'
100 123 s.description = <<-EOF
101 124 Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
@@ -109,6 +132,7 @@ specification = Gem::Specification.new do |s|
109 132 s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers'
110 133
111 134 s.autorequire = 'mocha'
  135 + s.add_dependency('rake')
112 136 s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
113 137 end
114 138
@@ -117,16 +141,16 @@ Rake::GemPackageTask.new(specification) do |package|
117 141 package.need_tar = true
118 142 end
119 143
120   -task :verify_user do
  144 +task 'verify_user' do
121 145 raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
122 146 end
123 147
124   -task :verify_password do
  148 +task 'verify_password' do
125 149 raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
126 150 end
127 151
128 152 desc "Publish package files on RubyForge."
129   -task :publish_packages => [:verify_user, :verify_password, :package] do
  153 +task 'publish_packages' => ['verify_user', 'verify_password', 'package'] do
130 154 $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "vendor", "meta_project-0.4.15", "lib"))
131 155 require 'meta_project'
132 156 require 'rake/contrib/xforge'
28 TODO
... ... @@ -1,17 +1,22 @@
  1 +=> Patch [#15235] Provide a pseudo-call syntax for simplifying set-up of expectations and stubs
  2 +=> Patch [#10412] Merge 'with' and the expected method
  3 +=> Bug [#8687] Block's return value is dropped on stubbed yielding methods
  4 +
  5 +=> interesting links
  6 +- http://www.jmock.org/match-object-or-method.html
  7 +- http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/106-12985-with_block_which_returns-val
  8 +
  9 +- think about making class_method_test & any_instance_method_test more blackbox to avoid ruby warnings
  10 +
  11 +=> update vendor libraries
  12 +- does updating meta_project have any effect on broken tarball issue?
  13 +
1 14 => release management
2 15 - why does gem rdoc include all source files? what about other package types?
3 16 - why does zip include Rakefile? what about other package types?
4 17 - tag releases in repos
5 18 - trac?
6 19
7   -=> restrict partial mocks to existing public methods?
8   -- investigate where/why check for existence of stubbed method has gone.
9   -- allow stubbing of private/protected methods? - force_stub?
10   -- allow specification of class to be mocked, so we can check for existence of methods
11   -
12   -=> bugs
13   -- assertion count is not incremented for missing expectation errors
14   -
15 20 => multiple expectations for same method
16 21 - fail fast if expectation count exceeded during test...? c.f. JMock?
17 22
@@ -26,13 +31,11 @@
26 31
27 32 => improve design
28 33 - use builder object c.f. JMock
  34 +- use expectation builder object to allow partial mocks to accept a hash in expects or stubs methods
29 35 - possibly simplify by making mock the same as a partial mock of Object
30 36 - provide test::unit agnostic api - mockery/context type objects on which the user must call setup/teardown?
31 37 - allow stubs/expects methods to accept method names as strings and symbols to retain similarity to define_method() et al
32 38
33   -=> documentation
34   -- read and improve tutorial emailed by user
35   -
36 39 => naming
37 40 - default mock names to mock1, mock2, etc or something similar
38 41 - stubba mocks should named according to parent stubbee
@@ -42,7 +45,6 @@
42 45 - test for setting expectations on class methods (and instance methods?) from within TestCase#setup
43 46
44 47 => possible extra functionality
45   -- more jmock style stuff - e.g. labels/required order, more sophisticated param matching?
46 48 - maybe allow unstubbing of a specific method from within a test...?
47 49 - oomatron type ideas
48   -- 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
  50 +- 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
80 examples/misc.rb
... ... @@ -1,36 +1,44 @@
1   -# Mocking a class method
2   -
3   - product = Product.new
4   - Product.expects(:find).with(1).returns(product)
5   - assert_equal product, Product.find(1)
6   -
7   -# Mocking an instance method on a real object
8   -
9   - product = Product.new
10   - product.expects(:save).returns(true)
11   - assert product.save
12   -
13   -# Stubbing instance methods on real object
14   -
15   - prices = [stub(:pence => 1000), stub(:pence => 2000)]
16   - product = Product.new
17   - product.stubs(:prices).returns(prices)
18   - assert_equal [1000, 2000], product.prices.collect {|p| p.pence}
19   -
20   -# Stubbing an instance method on all instances of a class
21   -
22   - Product.any_instance.stubs(:name).returns('stubbed_name')
23   - product = Product.new
24   - assert_equal 'stubbed_name', product.name
25   -
26   -# Traditional mocking
27   -
28   - object = mock()
29   - object.expects(:expected_method).with(:p1, :p2).returns(:result)
30   - assert_equal :result, object.expected_method(:p1, :p2)
31   -
32   -# Shortcuts
33   -
34   - object = stub(:method1 => :result1, :method2 => :result2)
35   - assert_equal :result1, object.method1
36   - assert_equal :result2, object.method2
  1 +require 'test/unit'
  2 +require 'rubygems'
  3 +require 'mocha'
  4 +
  5 +class MiscExampleTest < Test::Unit::TestCase
  6 +
  7 + def test_mocking_a_class_method
  8 + product = Product.new
  9 + Product.expects(:find).with(1).returns(product)
  10 + assert_equal product, Product.find(1)
  11 + end
  12 +
  13 + def test_mocking_an_instance_method_on_a_real_object
  14 + product = Product.new
  15 + product.expects(:save).returns(true)
  16 + assert product.save
  17 + end
  18 +
  19 + def test_stubbing_instance_methods_on_real_objects
  20 + prices = [stub(:pence => 1000), stub(:pence => 2000)]
  21 + product = Product.new
  22 + product.stubs(:prices).returns(prices)
  23 + assert_equal [1000, 2000], product.prices.collect {|p| p.pence}
  24 + end
  25 +
  26 + def test_stubbing_an_instance_method_on_all_instances_of_a_class
  27 + Product.any_instance.stubs(:name).returns('stubbed_name')
  28 + product = Product.new
  29 + assert_equal 'stubbed_name', product.name
  30 + end
  31 +
  32 + def test_traditional_mocking
  33 + object = mock()
  34 + object.expects(:expected_method).with(:p1, :p2).returns(:result)
  35 + assert_equal :result, object.expected_method(:p1, :p2)
  36 + end
  37 +
  38 + def test_shortcuts
  39 + object = stub(:method1 => :result1, :method2 => :result2)
  40 + assert_equal :result1, object.method1
  41 + assert_equal :result2, object.method2
  42 + end
  43 +
  44 +end
2  examples/stubba.rb
@@ -21,7 +21,7 @@ def find_all
21 21 end
22 22
23 23 def number_shipped_since(date)
24   - find_all.select { |order| order.shipped_on > date }.size
  24 + find_all.select { |order| order.shipped_on > date }.length
25 25 end
26 26
27 27 def unshipped_value
1  lib/mocha.rb
... ... @@ -1,5 +1,6 @@
1 1 require 'mocha_standalone'
2 2 require 'mocha/test_case_adapter'
  3 +require 'mocha/configuration'
3 4
4 5 require 'test/unit/testcase'
5 6
28 lib/mocha/any_instance_method.rb
@@ -15,21 +15,41 @@ def mock
15 15 end
16 16
17 17 def hide_original_method
18   - stubbee.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.method_defined?(method)
  18 + if method_exists?(method)
  19 + begin
  20 + stubbee.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__)
  21 + rescue NameError
  22 + # deal with nasties like ActiveRecord::Associations::AssociationProxy
  23 + end
  24 + end
19 25 end
20 26
21 27 def define_new_method
22   - stubbee.class_eval "def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end"
  28 + stubbee.class_eval("def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__)
23 29 end
24 30
25 31 def remove_new_method
26   - stubbee.class_eval "remove_method :#{method}"
  32 + stubbee.class_eval("remove_method :#{method}", __FILE__, __LINE__)
27 33 end
28 34
29 35 def restore_original_method
30   - stubbee.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.method_defined?(hidden_method)
  36 + if method_exists?(hidden_method)
  37 + begin
  38 + stubbee.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__)
  39 + rescue NameError
  40 + # deal with nasties like ActiveRecord::Associations::AssociationProxy
  41 + end
  42 + end
31 43 end
32 44
  45 + def method_exists?(method)
  46 + existing_methods = []
  47 + existing_methods += stubbee.public_instance_methods(false)
  48 + existing_methods += stubbee.protected_instance_methods(false)
  49 + existing_methods += stubbee.private_instance_methods(false)
  50 + existing_methods.any? { |m| m.to_s == method.to_s }
  51 + end
  52 +
33 53 end
34 54
35 55 end
111 lib/mocha/auto_verify.rb
... ... @@ -1,111 +0,0 @@
1   -require 'mocha/mock'
2   -
3   -module Mocha # :nodoc:
4   -
5   - # Methods added to TestCase allowing creation of traditional mock objects.
6   - #
7   - # Mocks created this way will have their expectations automatically verified at the end of the test.
8   - #
9   - # See Mock for methods on mock objects.
10   - module AutoVerify
11   -
12   - def mocks # :nodoc:
13   - @mocks ||= []
14   - end
15   -
16   - def reset_mocks # :nodoc:
17   - @mocks = nil
18   - end
19   -
20   - # :call-seq: mock(name) -> mock object
21   - # mock(expected_methods = {}) -> mock object
22   - # mock(name, expected_methods = {}) -> mock object
23   - #
24   - # Creates a mock object.
25   - #
26   - # +name+ is a +String+ identifier for the mock object.
27   - #
28   - # +expected_methods+ is a +Hash+ with expected method name symbols as keys and corresponding return values as values.
29   - #
30   - # Note that (contrary to expectations set up by #stub) these expectations <b>must</b> be fulfilled during the test.
31   - # def test_product
32   - # product = mock('ipod_product', :manufacturer => 'ipod', :price => 100)
33   - # assert_equal 'ipod', product.manufacturer
34   - # assert_equal 100, product.price
35   - # # an error will be raised unless both Product#manufacturer and Product#price have been called
36   - # end
37   - def mock(*args)
38   - name, expectations = name_and_expectations_from_args(args)
39   - mock = Mock.new(false, name)
40   - mock.expects(expectations)
41   - mocks << mock
42   - mock
43   - end
44   -
45   - # :call-seq: stub(name) -> mock object
46   - # stub(stubbed_methods = {}) -> mock object
47   - # stub(name, stubbed_methods = {}) -> mock object
48   - #
49   - # Creates a mock object.
50   - #
51   - # +name+ is a +String+ identifier for the mock object.
52   - #
53   - # +stubbed_methods+ is a +Hash+ with stubbed method name symbols as keys and corresponding return values as values.
54   - #
55   - # Note that (contrary to expectations set up by #mock) these expectations <b>need not</b> be fulfilled during the test.
56   - # def test_product
57   - # product = stub('ipod_product', :manufacturer => 'ipod', :price => 100)
58   - # assert_equal 'ipod', product.manufacturer
59   - # assert_equal 100, product.price
60   - # # an error will not be raised even if Product#manufacturer and Product#price have not been called
61   - # end
62   - def stub(*args)
63   - name, expectations = name_and_expectations_from_args(args)
64   - mock = Mock.new(false, name)
65   - mock.stubs(expectations)
66   - mocks << mock
67   - mock
68   - end
69   -
70   - # :call-seq: stub_everything(name) -> mock object
71   - # stub_everything(stubbed_methods = {}) -> mock object
72   - # stub_everything(name, stubbed_methods = {}) -> mock object
73   - #
74   - # Creates a mock object that accepts calls to any method.
75   - #
76   - # By default it will return +nil+ for any method call.
77   - #
78   - # +name+ and +stubbed_methods+ work in the same way as for #stub.
79   - # def test_product
80   - # product = stub_everything('ipod_product', :price => 100)
81   - # assert_nil product.manufacturer
82   - # assert_nil product.any_old_method
83   - # assert_equal 100, product.price
84   - # end
85   - def stub_everything(*args)
86   - name, expectations = name_and_expectations_from_args(args)
87   - mock = Mock.new(true, name)
88   - mock.stubs(expectations)
89   - mocks << mock
90   - mock
91   - end
92   -
93   - def verify_mocks # :nodoc:
94   - mocks.each { |mock| mock.verify { yield if block_given? } }
95   - end
96   -
97   - def teardown_mocks # :nodoc:
98   - reset_mocks
99   - end
100   -
101   - private
102   -
103   - def name_and_expectations_from_args(args) # :nodoc:
104   - name = args.first.is_a?(String) ? args.delete_at(0) : nil
105   - expectations = args.first || {}
106   - [name, expectations]
107   - end
108   -
109   - end
110   -
111   -end
0  trunk/lib/mocha/backtrace_filter.rb → lib/mocha/backtrace_filter.rb
File renamed without changes
0  trunk/lib/mocha/cardinality.rb → lib/mocha/cardinality.rb
File renamed without changes
12 lib/mocha/central.rb
@@ -11,20 +11,12 @@ def initialize
11 11 def stub(method)
12 12 unless stubba_methods.include?(method)
13 13 method.stub
14   - stubba_methods.push method
  14 + stubba_methods.push(method)
15 15 end
16 16 end
17 17
18   - def verify_all(&block)
19   - unique_mocks.each { |mock| mock.verify(&block) }
20   - end
21   -
22   - def unique_mocks
23   - stubba_methods.inject({}) { |mocks, method| mocks[method.mock.__id__] = method.mock; mocks }.values
24   - end
25   -
26 18 def unstub_all
27   - while stubba_methods.size > 0
  19 + while stubba_methods.length > 0
28 20 method = stubba_methods.pop
29 21 method.unstub
30 22 end
0  trunk/lib/mocha/change_state_side_effect.rb → lib/mocha/change_state_side_effect.rb
File renamed without changes
36 lib/mocha/class_method.rb
@@ -26,29 +26,45 @@ def mock
26 26 end
27 27
28 28 def hide_original_method
29   - stubbee.__metaclass__.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.__metaclass__.method_defined?(method)
  29 + if method_exists?(method)
  30 + begin
  31 + stubbee.__metaclass__.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__)
  32 + rescue NameError
  33 + # deal with nasties like ActiveRecord::Associations::AssociationProxy
  34 + end
  35 + end
30 36 end
31 37
32 38 def define_new_method
33   - stubbee.__metaclass__.class_eval "def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end"
  39 + stubbee.__metaclass__.class_eval("def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__)
34 40 end
35 41
36 42 def remove_new_method
37   - stubbee.__metaclass__.class_eval "remove_method :#{method}"
  43 + stubbee.__metaclass__.class_eval("remove_method :#{method}", __FILE__, __LINE__)
38 44 end
39 45
40 46 def restore_original_method
41   - stubbee.__metaclass__.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.__metaclass__.method_defined?(hidden_method)
  47 + if method_exists?(hidden_method)
  48 + begin
  49 + stubbee.__metaclass__.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__)
  50 + rescue NameError
  51 + # deal with nasties like ActiveRecord::Associations::AssociationProxy
  52 + end
  53 + end
42 54 end
43 55
44 56 def hidden_method
45   - method_name = method.to_s.gsub(/\W/) {|s| "_substituted_character_#{s[0]}_" }
  57 + if RUBY_VERSION < '1.9'
  58 + method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s[0]}_" }
  59 + else
  60 + method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s.ord}_" }
  61 + end
46 62 "__stubba__#{method_name}__stubba__"
47 63 end
48 64
49 65 def eql?(other)
50 66 return false unless (other.class == self.class)
51   - (stubbee == other.stubbee) and (method == other.method)
  67 + (stubbee.object_id == other.stubbee.object_id) and (method == other.method)
52 68 end
53 69
54 70 alias_method :==, :eql?
@@ -56,6 +72,14 @@ def eql?(other)
56 72 def to_s
57 73 "#{stubbee}.#{method}"
58 74 end
  75 +
  76 + def method_exists?(method)
  77 + existing_methods = []
  78 + existing_methods += stubbee.public_methods(true) - stubbee.superclass.public_methods(true)
  79 + existing_methods += stubbee.protected_methods(true) - stubbee.superclass.protected_methods(true)
  80 + existing_methods += stubbee.private_methods(true) - stubbee.superclass.private_methods(true)
  81 + existing_methods.any? { |m| m.to_s == method.to_s }
  82 + end
59 83
60 84 end
61 85
0  trunk/lib/mocha/configuration.rb → lib/mocha/configuration.rb
File renamed without changes
2  lib/mocha/exception_raiser.rb
@@ -7,7 +7,7 @@ def initialize(exception, message)
7 7 end
8 8
9 9 def evaluate
10   - raise @exception, @exception.to_s if @exception == Interrupt
  10 + raise @exception, @exception.to_s if @exception.is_a?(Module) && @exception.ancestors.include?(Interrupt)
11 11 raise @exception, @message if @message
12 12 raise @exception
13 13 end
241 lib/mocha/expectation.rb
... ... @@ -1,56 +1,19 @@
1   -require 'mocha/infinite_range'
2   -require 'mocha/pretty_parameters'
  1 +require 'mocha/method_matcher'
  2 +require 'mocha/parameters_matcher'
3 3 require 'mocha/expectation_error'
4 4 require 'mocha/return_values'
5 5 require 'mocha/exception_raiser'
6 6 require 'mocha/yield_parameters'
7 7 require 'mocha/is_a'
  8 +require 'mocha/in_state_ordering_constraint'
  9 +require 'mocha/change_state_side_effect'
  10 +require 'mocha/cardinality'
8 11
9 12 module Mocha # :nodoc:
10 13
11 14 # Methods on expectations returned from Mock#expects, Mock#stubs, Object#expects and Object#stubs.
12 15 class Expectation
13 16
14   - # :stopdoc:
15   -
16   - class AlwaysEqual
17   - def ==(other)
18   - true
19   - end
20   - end
21   -
22   - attr_reader :method_name, :backtrace
23   -
24   - def initialize(mock, method_name, backtrace = nil)
25   - @mock, @method_name = mock, method_name
26   - @expected_count = 1
27   - @parameters, @parameter_block = AlwaysEqual.new, nil
28   - @invoked_count, @return_values = 0, ReturnValues.new
29   - @backtrace = backtrace || caller
30   - @yield_parameters = YieldParameters.new
31   - @final_expectation = false
32   - end
33   -
34   - def match?(method_name, *arguments)
35   - return false unless @method_name == method_name
36   - if @parameter_block then
37   - return false unless @parameter_block.call(*arguments)
38   - else
39   - return false unless (@parameters == arguments)
40   - end
41   - return true
42   - end
43   -
44   - def invocations_allowed?
45   - if @expected_count.is_a?(Range) then
46   - @invoked_count < @expected_count.last
47   - else
48   - @invoked_count < @expected_count
49   - end
50   - end
51   -
52   - # :startdoc:
53   -
54 17 # :call-seq: times(range) -> expectation
55 18 #
56 19 # Modifies expectation so that the number of calls to the expected method must be within a specific +range+.
@@ -76,7 +39,7 @@ def invocations_allowed?
76 39 # object.expected_method
77 40 # # => verify fails
78 41 def times(range)
79   - @expected_count = range
  42 + @cardinality = Cardinality.times(range)
80 43 self
81 44 end
82 45
@@ -98,8 +61,8 @@ def times(range)
98 61 # object = mock()
99 62 # object.expects(:expected_method).once
100 63 # # => verify fails
101   - def once()
102   - times(1)
  64 + def once
  65 + @cardinality = Cardinality.exactly(1)
103 66 self
104 67 end
105 68
@@ -116,7 +79,7 @@ def once()
116 79 # object.expected_method
117 80 # # => verify succeeds
118 81 def never
119   - times(0)
  82 + @cardinality = Cardinality.exactly(0)
120 83 self
121 84 end
122 85
@@ -133,7 +96,7 @@ def never
133 96 # object.expected_method
134 97 # # => verify fails
135 98 def at_least(minimum_number_of_times)
136   - times(Range.at_least(minimum_number_of_times))
  99 + @cardinality = Cardinality.at_least(minimum_number_of_times)
137 100 self
138 101 end
139 102
@@ -148,7 +111,7 @@ def at_least(minimum_number_of_times)
148 111 # object = mock()
149 112 # object.expects(:expected_method).at_least_once
150 113 # # => verify fails
151   - def at_least_once()
  114 + def at_least_once
152 115 at_least(1)
153 116 self
154 117 end
@@ -166,7 +129,7 @@ def at_least_once()
166 129 # 3.times { object.expected_method }
167 130 # # => verify fails
168 131 def at_most(maximum_number_of_times)
169   - times(Range.at_most(maximum_number_of_times))
  132 + @cardinality = Cardinality.at_most(maximum_number_of_times)
170 133 self
171 134 end
172 135
@@ -187,9 +150,9 @@ def at_most_once()
187 150 self
188 151 end
189 152
190   - # :call-seq: with(*arguments, &parameter_block) -> expectation
  153 + # :call-seq: with(*expected_parameters, &matching_block) -> expectation
191 154 #
192   - # Modifies expectation so that the expected method must be called with specified +arguments+.
  155 + # Modifies expectation so that the expected method must be called with +expected_parameters+.
193 156 # object = mock()
194 157 # object.expects(:expected_method).with(:param1, :param2)
195 158 # object.expected_method(:param1, :param2)
@@ -201,7 +164,7 @@ def at_most_once()
201 164 # # => verify fails
202 165 # May be used with parameter matchers in Mocha::ParameterMatchers.
203 166 #
204   - # If a +parameter_block+ is given, the block is called with the parameters passed to the expected method.
  167 + # If a +matching_block+ is given, the block is called with the parameters passed to the expected method.
205 168 # The expectation is matched if the block evaluates to +true+.
206 169 # object = mock()
207 170 # object.expects(:expected_method).with() { |value| value % 4 == 0 }
@@ -212,9 +175,8 @@ def at_most_once()
212 175 # object.expects(:expected_method).with() { |value| value % 4 == 0 }
213 176 # object.expected_method(17)
214 177 # # => verify fails
215   - def with(*arguments, &parameter_block)
216   - @parameters, @parameter_block = arguments, parameter_block
217   - class << @parameters; def to_s; join(', '); end; end
  178 + def with(*expected_parameters, &matching_block)
  179 + @parameters_matcher = ParametersMatcher.new(expected_parameters, &matching_block)
218 180 self
219 181 end
220 182
@@ -263,7 +225,7 @@ def multiple_yields(*parameter_groups)
263 225 end
264 226
265 227 # :call-seq: returns(value) -> expectation
266   - # :call-seq: returns(*values) -> expectation
  228 + # returns(*values) -> expectation
267 229 #
268 230 # Modifies expectation so that when the expected method is called, it returns the specified +value+.
269 231 # object = mock()
@@ -287,16 +249,6 @@ def multiple_yields(*parameter_groups)
287 249 # object.expected_method # => 1
288 250 # object.expected_method # => 2
289 251 # object.expected_method # => raises exception of class Exception1
290   - # If +value+ is a +Proc+, then the expected method will return the result of calling <tt>Proc#call</tt>.
291   - #
292   - # This usage is _deprecated_.
293   - # Use explicit multiple return values and/or multiple expectations instead.
294   - #
295   - # A +Proc+ instance will be treated the same as any other value in a future release.
296   - # object = mock()
297   - # object.stubs(:stubbed_method).returns(lambda { rand(100) })
298   - # object.stubbed_method # => 41
299   - # object.stubbed_method # => 77
300 252 def returns(*values)
301 253 @return_values += ReturnValues.build(*values)
302 254 self
@@ -325,22 +277,132 @@ def raises(exception = RuntimeError, message = nil)
325 277 end
326 278
327 279 # :call-seq: then() -> expectation
  280 + # then(state_machine.is(state)) -> expectation
328 281 #
329   - # Syntactic sugar to improve readability. Has no effect on state of the expectation.
  282 + # <tt>then()</tt> is used as syntactic sugar to improve readability. It has no effect on state of the expectation.
330 283 # object = mock()
331 284 # object.stubs(:expected_method).returns(1, 2).then.raises(Exception).then.returns(4)
332 285 # object.expected_method # => 1
333 286 # object.expected_method # => 2
334 287 # object.expected_method # => raises exception of class Exception
335 288 # object.expected_method # => 4
336   - def then
  289 + #
  290 + # <tt>then(state_machine.is(state))</tt> is used to change the +state_machine+ to the specified +state+ when the invocation occurs.
  291 + #
  292 + # See also Standalone#states, StateMachine and Expectation#when.
  293 + # power = states('power').starts_as('off')
  294 + #
  295 + # radio = mock('radio')
  296 + # radio.expects(:switch_on).then(power.is('on'))
  297 + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on'))
  298 + # radio.expects(:adjust_volume).with(+5).when(power.is('on'))
  299 + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on'))
  300 + # radio.expects(:adjust_volume).with(-5).when(power.is('on'))
  301 + # radio.expects(:switch_off).then(power.is('off'))
  302 + def then(*parameters)
  303 + if parameters.length == 1
  304 + state = parameters.first
  305 + add_side_effect(ChangeStateSideEffect.new(state))
  306 + end
  307 + self
  308 + end
  309 +
  310 + # :call-seq: when(state_machine.is(state)) -> exception
  311 + #
  312 + # Constrains the expectation to occur only when the +state_machine+ is in the named +state+.
  313 + #
  314 + # See also Standalone#states, StateMachine#starts_as and Expectation#then.
  315 + # power = states('power').starts_as('off')
  316 + #
  317 + # radio = mock('radio')
  318 + # radio.expects(:switch_on).then(power.is('on'))
  319 + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on'))
  320 + # radio.expects(:adjust_volume).with(+5).when(power.is('on'))
  321 + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on'))
  322 + # radio.expects(:adjust_volume).with(-5).when(power.is('on'))
  323 + # radio.expects(:switch_off).then(power.is('off'))
  324 + def when(state_predicate)
  325 + add_ordering_constraint(InStateOrderingConstraint.new(state_predicate))
  326 + self
  327 + end
  328 +
  329 + # :call-seq: in_sequence(*sequences) -> expectation
  330 + #
  331 + # Constrains this expectation so that it must be invoked at the current point in the sequence.
  332 + #
  333 + # To expect a sequence of invocations, write the expectations in order and add the in_sequence(sequence) clause to each one.
  334 + #
  335 + # Expectations in a sequence can have any invocation count.
  336 + #
  337 + # If an expectation in a sequence is stubbed, rather than expected, it can be skipped in the sequence.
  338 + #
  339 + # See also Standalone#sequence.
  340 + # breakfast = sequence('breakfast')
  341 + #
  342 + # egg = mock('egg')
  343 + # egg.expects(:crack).in_sequence(breakfast)
  344 + # egg.expects(:fry).in_sequence(breakfast)
  345 + # egg.expects(:eat).in_sequence(breakfast)
  346 + def in_sequence(*sequences)
  347 + sequences.each { |sequence| add_in_sequence_ordering_constraint(sequence) }
337 348 self
338 349 end
339 350
340 351 # :stopdoc:
341 352
  353 + attr_reader :backtrace
  354 +
  355 + def initialize(mock, expected_method_name, backtrace = nil)
  356 + @mock = mock
  357 + @method_matcher = MethodMatcher.new(expected_method_name)
  358 + @parameters_matcher = ParametersMatcher.new
  359 + @ordering_constraints = []
  360 + @side_effects = []
  361 + @cardinality, @invocation_count = Cardinality.exactly(1), 0
  362 + @return_values = ReturnValues.new
  363 + @yield_parameters = YieldParameters.new
  364 + @backtrace = backtrace || caller
  365 + end
  366 +
  367 + def add_ordering_constraint(ordering_constraint)
  368 + @ordering_constraints << ordering_constraint
  369 + end
  370 +
  371 + def add_in_sequence_ordering_constraint(sequence)
  372 + sequence.constrain_as_next_in_sequence(self)
  373 + end
  374 +
  375 + def add_side_effect(side_effect)
  376 + @side_effects << side_effect
  377 + end
  378 +
  379 + def perform_side_effects
  380 + @side_effects.each { |side_effect| side_effect.perform }
  381 + end
  382 +
  383 + def in_correct_order?
  384 + @ordering_constraints.all? { |ordering_constraint| ordering_constraint.allows_invocation_now? }
  385 + end
  386 +
  387 + def matches_method?(method_name)
  388 + @method_matcher.match?(method_name)
  389 + end
  390 +
  391 + def match?(actual_method_name, *actual_parameters)
  392 + @method_matcher.match?(actual_method_name) && @parameters_matcher.match?(actual_parameters) && in_correct_order?
  393 + end
  394 +
  395 + def invocations_allowed?
  396 + @cardinality.invocations_allowed?(@invocation_count)
  397 + end
  398 +
  399 + def satisfied?
  400 + @cardinality.satisfied?(@invocation_count)
  401 + end
  402 +
342 403 def invoke
343   - @invoked_count += 1
  404 + @invocation_count += 1
  405 + perform_side_effects()
344 406 if block_given? then
345 407 @yield_parameters.next_invocation.each do |yield_parameters|
346 408 yield(*yield_parameters)
@@ -349,34 +411,35 @@ def invoke
349 411 @return_values.next
350 412 end
351 413
352   - def verify
353   - yield(self) if block_given?
354   - unless (@expected_count === @invoked_count) then
355   - error = ExpectationError.new(error_message(@expected_count, @invoked_count))
356   - error.set_backtrace(filtered_backtrace)
357   - raise error
358   - end
  414 + def verified?(assertion_counter = nil)
  415 + assertion_counter.increment if assertion_counter && @cardinality.needs_verifying?
  416 + @cardinality.verified?(@invocation_count)
359 417 end
360 418
361   - def mocha_lib_directory
362   - File.expand_path(File.join(File.dirname(__FILE__), "..")) + File::SEPARATOR
  419 + def used?
  420 + @cardinality.used?(@invocation_count)
363 421 end
364 422
365   - def filtered_backtrace
366   - backtrace.reject { |location| Regexp.new(mocha_lib_directory).match(File.expand_path(location)) }
367   - end
368   -
369   - def method_signature
370   - return "#{method_name}" if @parameters.__is_a__(AlwaysEqual)
371   - "#{@method_name}(#{PrettyParameters.new(@parameters).pretty})"
  423 + def mocha_inspect
  424 + message = "#{@cardinality.mocha_inspect}, "
  425 + if @invocation_count > 0
  426 + message << "already invoked #{@invocation_count} time"
  427 + message << "s" if @invocation_count > 1
  428 + else
  429 + message << "never invoked"
  430 + end
  431 + message << ": "
  432 + message << method_signature
  433 + message << "; #{@ordering_constraints.map { |oc| oc.mocha_inspect }.join("; ")}" unless @ordering_constraints.empty?
  434 + message
372 435 end
373 436
374   - def error_message(expected_count, actual_count)
375   - "#{@mock.mocha_inspect}.#{method_signature} - expected calls: #{expected_count.mocha_inspect}, actual calls: #{actual_count}"
  437 + def method_signature
  438 + "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}"
376 439 end
377   -
  440 +
378 441 # :startdoc:
379 442
380 443 end
381 444
382   -end
  445 +end
11 lib/mocha/expectation_error.rb
... ... @@ -1,6 +1,15 @@
  1 +require 'mocha/backtrace_filter'
  2 +
1 3 module Mocha
2 4
3 5 class ExpectationError < StandardError
  6 +
  7 + def initialize(message = nil, backtrace = [])
  8 + super(message)