mocha 1.5.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +61 -0
  3. data/.rubocop_todo.yml +27 -0
  4. data/CONTRIBUTING.md +4 -9
  5. data/README.md +66 -97
  6. data/RELEASE.md +93 -0
  7. data/Rakefile +44 -38
  8. data/bin/build-matrix +32 -20
  9. data/docs/CNAME +1 -0
  10. data/docs/Mocha.html +254 -0
  11. data/docs/Mocha/API.html +1153 -0
  12. data/docs/Mocha/ClassMethods.html +264 -0
  13. data/docs/Mocha/Configuration.html +1383 -0
  14. data/docs/Mocha/Expectation.html +2654 -0
  15. data/docs/Mocha/ExpectationError.html +152 -0
  16. data/docs/Mocha/ExpectationErrorFactory.html +260 -0
  17. data/docs/Mocha/Hooks.html +370 -0
  18. data/docs/Mocha/Integration.html +125 -0
  19. data/docs/Mocha/Integration/MiniTest.html +123 -0
  20. data/docs/Mocha/Integration/MiniTest/Adapter.html +164 -0
  21. data/docs/Mocha/Integration/TestUnit.html +123 -0
  22. data/docs/Mocha/Integration/TestUnit/Adapter.html +164 -0
  23. data/docs/Mocha/Mock.html +1237 -0
  24. data/docs/Mocha/ObjectMethods.html +765 -0
  25. data/docs/Mocha/ParameterMatchers.html +2961 -0
  26. data/docs/Mocha/ParameterMatchers/AllOf.html +153 -0
  27. data/docs/Mocha/ParameterMatchers/AnyOf.html +153 -0
  28. data/docs/Mocha/ParameterMatchers/AnyParameters.html +153 -0
  29. data/docs/Mocha/ParameterMatchers/Anything.html +153 -0
  30. data/docs/Mocha/ParameterMatchers/Base.html +441 -0
  31. data/docs/Mocha/ParameterMatchers/Equals.html +153 -0
  32. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +153 -0
  33. data/docs/Mocha/ParameterMatchers/HasEntries.html +153 -0
  34. data/docs/Mocha/ParameterMatchers/HasEntry.html +153 -0
  35. data/docs/Mocha/ParameterMatchers/HasKey.html +153 -0
  36. data/docs/Mocha/ParameterMatchers/HasValue.html +153 -0
  37. data/docs/Mocha/ParameterMatchers/Includes.html +153 -0
  38. data/docs/Mocha/ParameterMatchers/InstanceOf.html +153 -0
  39. data/docs/Mocha/ParameterMatchers/IsA.html +153 -0
  40. data/docs/Mocha/ParameterMatchers/KindOf.html +153 -0
  41. data/docs/Mocha/ParameterMatchers/Not.html +153 -0
  42. data/docs/Mocha/ParameterMatchers/Optionally.html +153 -0
  43. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +153 -0
  44. data/docs/Mocha/ParameterMatchers/RespondsWith.html +153 -0
  45. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +153 -0
  46. data/docs/Mocha/Sequence.html +149 -0
  47. data/docs/Mocha/StateMachine.html +527 -0
  48. data/docs/Mocha/StateMachine/State.html +140 -0
  49. data/docs/Mocha/StateMachine/StatePredicate.html +140 -0
  50. data/docs/Mocha/StubbingError.html +150 -0
  51. data/docs/_index.html +519 -0
  52. data/docs/class_list.html +51 -0
  53. data/docs/css/common.css +1 -0
  54. data/docs/css/full_list.css +58 -0
  55. data/docs/css/style.css +496 -0
  56. data/docs/file.COPYING.html +81 -0
  57. data/docs/file.MIT-LICENSE.html +85 -0
  58. data/docs/file.README.html +448 -0
  59. data/docs/file.RELEASE.html +956 -0
  60. data/docs/file_list.html +71 -0
  61. data/docs/frames.html +17 -0
  62. data/docs/index.html +448 -0
  63. data/docs/js/app.js +303 -0
  64. data/docs/js/full_list.js +216 -0
  65. data/docs/js/jquery.js +4 -0
  66. data/docs/method_list.html +627 -0
  67. data/docs/top-level-namespace.html +118 -0
  68. data/gemfiles/Gemfile.minitest.5.11.3 +7 -0
  69. data/init.rb +1 -3
  70. data/lib/mocha.rb +8 -0
  71. data/lib/mocha/any_instance_method.rb +11 -59
  72. data/lib/mocha/api.rb +65 -70
  73. data/lib/mocha/argument_iterator.rb +4 -8
  74. data/lib/mocha/backtrace_filter.rb +1 -5
  75. data/lib/mocha/cardinality.rb +43 -35
  76. data/lib/mocha/central.rb +7 -15
  77. data/lib/mocha/change_state_side_effect.rb +0 -4
  78. data/lib/mocha/class_methods.rb +19 -21
  79. data/lib/mocha/configuration.rb +305 -18
  80. data/lib/mocha/debug.rb +3 -2
  81. data/lib/mocha/deprecation.rb +4 -11
  82. data/lib/mocha/detection/mini_test.rb +0 -2
  83. data/lib/mocha/detection/test_unit.rb +3 -5
  84. data/lib/mocha/error_with_filtered_backtrace.rb +0 -4
  85. data/lib/mocha/exception_raiser.rb +4 -6
  86. data/lib/mocha/expectation.rb +62 -67
  87. data/lib/mocha/expectation_error.rb +1 -1
  88. data/lib/mocha/expectation_error_factory.rb +0 -1
  89. data/lib/mocha/expectation_list.rb +7 -11
  90. data/lib/mocha/hooks.rb +0 -1
  91. data/lib/mocha/in_state_ordering_constraint.rb +0 -4
  92. data/lib/mocha/inspect.rb +28 -28
  93. data/lib/mocha/instance_method.rb +18 -3
  94. data/lib/mocha/integration.rb +2 -5
  95. data/lib/mocha/integration/mini_test.rb +7 -0
  96. data/lib/mocha/integration/mini_test/adapter.rb +2 -4
  97. data/lib/mocha/integration/mini_test/exception_translation.rb +1 -1
  98. data/lib/mocha/integration/mini_test/nothing.rb +4 -4
  99. data/lib/mocha/integration/mini_test/version_13.rb +3 -1
  100. data/lib/mocha/integration/mini_test/version_140.rb +3 -1
  101. data/lib/mocha/integration/mini_test/version_141.rb +3 -1
  102. data/lib/mocha/integration/mini_test/version_142_to_172.rb +3 -1
  103. data/lib/mocha/integration/mini_test/version_200.rb +3 -1
  104. data/lib/mocha/integration/mini_test/version_201_to_222.rb +3 -1
  105. data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +3 -1
  106. data/lib/mocha/integration/mini_test/version_2112_to_320.rb +3 -1
  107. data/lib/mocha/integration/mini_test/version_230_to_2101.rb +3 -1
  108. data/lib/mocha/integration/monkey_patcher.rb +5 -7
  109. data/lib/mocha/integration/test_unit.rb +7 -0
  110. data/lib/mocha/integration/test_unit/adapter.rb +5 -6
  111. data/lib/mocha/integration/test_unit/gem_version_200.rb +4 -2
  112. data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +4 -2
  113. data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +4 -2
  114. data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +4 -2
  115. data/lib/mocha/integration/test_unit/nothing.rb +4 -4
  116. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +3 -1
  117. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +3 -1
  118. data/lib/mocha/invocation.rb +61 -0
  119. data/lib/mocha/is_a.rb +0 -2
  120. data/lib/mocha/logger.rb +0 -4
  121. data/lib/mocha/macos_version.rb +5 -0
  122. data/lib/mocha/method_matcher.rb +1 -5
  123. data/lib/mocha/minitest.rb +7 -2
  124. data/lib/mocha/mock.rb +57 -47
  125. data/lib/mocha/mockery.rb +41 -90
  126. data/lib/mocha/multiple_yields.rb +0 -5
  127. data/lib/mocha/names.rb +2 -12
  128. data/lib/mocha/no_yields.rb +1 -7
  129. data/lib/mocha/not_initialized_error.rb +0 -2
  130. data/lib/mocha/object_methods.rb +25 -31
  131. data/lib/mocha/parameter_matchers.rb +1 -3
  132. data/lib/mocha/parameter_matchers/all_of.rb +2 -8
  133. data/lib/mocha/parameter_matchers/any_of.rb +2 -8
  134. data/lib/mocha/parameter_matchers/any_parameters.rb +3 -9
  135. data/lib/mocha/parameter_matchers/anything.rb +2 -8
  136. data/lib/mocha/parameter_matchers/base.rb +6 -12
  137. data/lib/mocha/parameter_matchers/equals.rb +0 -6
  138. data/lib/mocha/parameter_matchers/equivalent_uri.rb +3 -12
  139. data/lib/mocha/parameter_matchers/has_entries.rb +2 -6
  140. data/lib/mocha/parameter_matchers/has_entry.rb +8 -11
  141. data/lib/mocha/parameter_matchers/has_key.rb +2 -6
  142. data/lib/mocha/parameter_matchers/has_value.rb +2 -6
  143. data/lib/mocha/parameter_matchers/includes.rb +4 -6
  144. data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
  145. data/lib/mocha/parameter_matchers/instance_of.rb +0 -6
  146. data/lib/mocha/parameter_matchers/is_a.rb +2 -6
  147. data/lib/mocha/parameter_matchers/kind_of.rb +2 -6
  148. data/lib/mocha/parameter_matchers/not.rb +2 -6
  149. data/lib/mocha/parameter_matchers/optionally.rb +4 -10
  150. data/lib/mocha/parameter_matchers/regexp_matches.rb +0 -6
  151. data/lib/mocha/parameter_matchers/responds_with.rb +3 -8
  152. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +2 -6
  153. data/lib/mocha/parameters_matcher.rb +6 -9
  154. data/lib/mocha/pretty_parameters.rb +0 -4
  155. data/lib/mocha/raised_exception.rb +11 -0
  156. data/lib/mocha/receivers.rb +10 -14
  157. data/lib/mocha/return_values.rb +4 -8
  158. data/lib/mocha/sequence.rb +4 -9
  159. data/lib/mocha/setup.rb +5 -0
  160. data/lib/mocha/single_return_value.rb +2 -5
  161. data/lib/mocha/single_yield.rb +0 -5
  162. data/lib/mocha/singleton_class.rb +9 -0
  163. data/lib/mocha/state_machine.rb +6 -10
  164. data/lib/mocha/stubbed_method.rb +127 -0
  165. data/lib/mocha/stubbing_error.rb +0 -2
  166. data/lib/mocha/test_unit.rb +7 -2
  167. data/lib/mocha/thrower.rb +4 -6
  168. data/lib/mocha/thrown_object.rb +12 -0
  169. data/lib/mocha/version.rb +1 -1
  170. data/lib/mocha/yield_parameters.rb +3 -7
  171. data/mocha.gemspec +33 -60
  172. data/test/acceptance/acceptance_test_helper.rb +6 -4
  173. data/test/acceptance/bug_18914_test.rb +7 -13
  174. data/test/acceptance/bug_21465_test.rb +0 -3
  175. data/test/acceptance/bug_21563_test.rb +0 -3
  176. data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +69 -0
  177. data/test/acceptance/exception_rescue_test.rb +7 -9
  178. data/test/acceptance/expectations_on_multiple_methods_test.rb +2 -2
  179. data/test/acceptance/expected_invocation_count_test.rb +27 -30
  180. data/test/acceptance/failure_messages_test.rb +3 -6
  181. data/test/acceptance/issue_272_test.rb +1 -3
  182. data/test/acceptance/issue_65_test.rb +15 -14
  183. data/test/acceptance/issue_70_test.rb +0 -2
  184. data/test/acceptance/mocha_example_test.rb +5 -7
  185. data/test/acceptance/mocha_test_result_test.rb +7 -8
  186. data/test/acceptance/mock_test.rb +48 -9
  187. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -3
  188. data/test/acceptance/multiple_expectations_failure_message_test.rb +16 -18
  189. data/test/acceptance/optional_parameters_test.rb +0 -3
  190. data/test/acceptance/parameter_matcher_test.rb +2 -4
  191. data/test/acceptance/partial_mocks_test.rb +4 -7
  192. data/test/acceptance/prepend_test.rb +14 -17
  193. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -3
  194. data/test/acceptance/raise_exception_test.rb +2 -5
  195. data/test/acceptance/return_value_test.rb +0 -3
  196. data/test/acceptance/sequence_test.rb +9 -12
  197. data/test/acceptance/states_test.rb +6 -5
  198. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +33 -3
  199. data/test/acceptance/stub_any_instance_method_test.rb +39 -18
  200. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +8 -9
  201. data/test/acceptance/stub_class_method_defined_on_class_test.rb +2 -2
  202. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -2
  203. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +34 -2
  204. data/test/acceptance/stub_everything_test.rb +1 -4
  205. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +6 -8
  206. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -2
  207. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -2
  208. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +63 -2
  209. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -2
  210. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +2 -2
  211. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -3
  212. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -2
  213. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -1
  214. data/test/acceptance/stub_module_method_test.rb +13 -14
  215. data/test/acceptance/stub_test.rb +1 -4
  216. data/test/acceptance/stubba_example_test.rb +6 -15
  217. data/test/acceptance/stubba_test_result_test.rb +5 -9
  218. data/test/acceptance/stubbing_error_backtrace_test.rb +6 -7
  219. data/test/acceptance/stubbing_frozen_object_test.rb +2 -2
  220. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +12 -8
  221. data/test/acceptance/stubbing_method_unnecessarily_test.rb +5 -7
  222. data/test/acceptance/stubbing_nil_test.rb +9 -10
  223. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +12 -14
  224. data/test/acceptance/stubbing_non_existent_class_method_test.rb +14 -14
  225. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +12 -14
  226. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +8 -10
  227. data/test/acceptance/stubbing_non_public_class_method_test.rb +12 -12
  228. data/test/acceptance/stubbing_non_public_instance_method_test.rb +10 -12
  229. data/test/acceptance/stubbing_on_non_mock_object_test.rb +9 -15
  230. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +3 -5
  231. data/test/acceptance/throw_test.rb +0 -3
  232. data/test/acceptance/unexpected_invocation_test.rb +2 -4
  233. data/test/acceptance/unstubbing_test.rb +41 -15
  234. data/test/deprecation_disabler.rb +0 -1
  235. data/test/execution_point.rb +2 -4
  236. data/test/integration/mini_test_test.rb +2 -2
  237. data/test/integration/shared_tests.rb +27 -23
  238. data/test/integration/test_unit_test.rb +2 -2
  239. data/test/method_definer.rb +11 -19
  240. data/test/mini_test_result.rb +17 -11
  241. data/test/minitest_result.rb +0 -1
  242. data/test/simple_counter.rb +0 -2
  243. data/test/test_helper.rb +13 -5
  244. data/test/test_runner.rb +4 -4
  245. data/test/test_unit_result.rb +4 -2
  246. data/test/unit/any_instance_method_test.rb +74 -35
  247. data/test/unit/array_inspect_test.rb +2 -4
  248. data/test/unit/backtrace_filter_test.rb +3 -5
  249. data/test/unit/cardinality_test.rb +41 -25
  250. data/test/unit/central_test.rb +26 -28
  251. data/test/unit/change_state_side_effect_test.rb +0 -4
  252. data/test/unit/class_methods_test.rb +35 -6
  253. data/test/unit/configuration_test.rb +13 -14
  254. data/test/unit/date_time_inspect_test.rb +1 -3
  255. data/test/unit/exception_raiser_test.rb +10 -7
  256. data/test/unit/expectation_list_test.rb +13 -13
  257. data/test/unit/expectation_test.rb +110 -130
  258. data/test/unit/hash_inspect_test.rb +3 -5
  259. data/test/unit/hooks_test.rb +9 -4
  260. data/test/unit/in_state_ordering_constraint_test.rb +0 -4
  261. data/test/unit/instance_method_test.rb +282 -0
  262. data/test/unit/method_matcher_test.rb +1 -3
  263. data/test/unit/mock_test.rb +47 -25
  264. data/test/unit/mockery_test.rb +32 -33
  265. data/test/unit/module_methods_test.rb +2 -5
  266. data/test/unit/multiple_yields_test.rb +0 -2
  267. data/test/unit/no_yields_test.rb +0 -2
  268. data/test/unit/object_inspect_test.rb +26 -5
  269. data/test/unit/object_methods_test.rb +19 -8
  270. data/test/unit/parameter_matchers/all_of_test.rb +0 -2
  271. data/test/unit/parameter_matchers/any_of_test.rb +0 -2
  272. data/test/unit/parameter_matchers/anything_test.rb +2 -4
  273. data/test/unit/parameter_matchers/equals_test.rb +1 -3
  274. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -10
  275. data/test/unit/parameter_matchers/has_entries_test.rb +3 -3
  276. data/test/unit/parameter_matchers/has_entry_test.rb +14 -15
  277. data/test/unit/parameter_matchers/has_key_test.rb +1 -2
  278. data/test/unit/parameter_matchers/has_value_test.rb +1 -3
  279. data/test/unit/parameter_matchers/includes_test.rb +9 -10
  280. data/test/unit/parameter_matchers/instance_of_test.rb +1 -3
  281. data/test/unit/parameter_matchers/is_a_test.rb +1 -3
  282. data/test/unit/parameter_matchers/kind_of_test.rb +1 -3
  283. data/test/unit/parameter_matchers/not_test.rb +0 -2
  284. data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -2
  285. data/test/unit/parameter_matchers/responds_with_test.rb +10 -4
  286. data/test/unit/parameter_matchers/stub_matcher.rb +0 -4
  287. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +1 -3
  288. data/test/unit/parameters_matcher_test.rb +2 -4
  289. data/test/unit/receivers_test.rb +35 -5
  290. data/test/unit/return_values_test.rb +28 -25
  291. data/test/unit/sequence_test.rb +1 -5
  292. data/test/unit/single_return_value_test.rb +6 -3
  293. data/test/unit/single_yield_test.rb +0 -2
  294. data/test/unit/state_machine_test.rb +1 -3
  295. data/test/unit/string_inspect_test.rb +2 -4
  296. data/test/unit/thrower_test.rb +7 -4
  297. data/test/unit/yield_parameters_test.rb +0 -2
  298. data/yard-templates/default/layout/html/google_analytics.erb +6 -9
  299. data/yard-templates/default/layout/html/setup.rb +2 -3
  300. metadata +81 -49
  301. data/lib/mocha/class_method.rb +0 -119
  302. data/lib/mocha/mini_test.rb +0 -5
  303. data/lib/mocha/module_method.rb +0 -16
  304. data/lib/mocha/module_methods.rb +0 -14
  305. data/lib/mocha/parameter_matchers/object.rb +0 -17
  306. data/lib/mocha/standalone.rb +0 -4
  307. data/lib/mocha/unexpected_invocation.rb +0 -26
  308. data/lib/mocha_standalone.rb +0 -4
  309. data/test/acceptance/mock_with_initializer_block_test.rb +0 -58
  310. data/test/unit/class_method_test.rb +0 -229
@@ -2,10 +2,8 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  require 'mocha/central'
4
4
  require 'mocha/mock'
5
- require 'method_definer'
6
5
 
7
6
  class CentralTest < Mocha::TestCase
8
-
9
7
  include Mocha
10
8
 
11
9
  def test_should_start_with_empty_stubba_methods
@@ -48,48 +46,48 @@ class CentralTest < Mocha::TestCase
48
46
 
49
47
  def test_should_unstub_specified_method
50
48
  stubba = Central.new
51
- method_1 = build_mock
52
- method_1.stubs(:matches?).returns(false)
53
- method_2 = build_mock
54
- method_2.stubs(:matches?).returns(true)
55
- method_2.expects(:unstub)
56
- stubba.stubba_methods = [method_1, method_2]
49
+ method1 = build_mock
50
+ method1.stubs(:matches?).returns(false)
51
+ method2 = build_mock
52
+ method2.stubs(:matches?).returns(true)
53
+ method2.expects(:unstub)
54
+ stubba.stubba_methods = [method1, method2]
57
55
 
58
- stubba.unstub(method_2)
56
+ stubba.unstub(method2)
59
57
 
60
- assert_equal [method_1], stubba.stubba_methods
61
- assert method_2.__verified__?
58
+ assert_equal [method1], stubba.stubba_methods
59
+ assert method2.__verified__?
62
60
  end
63
61
 
64
62
  def test_should_not_unstub_specified_method_if_not_already_stubbed
65
63
  stubba = Central.new
66
- method_1 = build_mock
67
- method_1.stubs(:matches?).returns(false)
68
- method_2 = build_mock
69
- method_2.expects(:unstub).never
70
- stubba.stubba_methods = [method_1]
64
+ method1 = build_mock
65
+ method1.stubs(:matches?).returns(false)
66
+ method2 = build_mock
67
+ method2.expects(:unstub).never
68
+ stubba.stubba_methods = [method1]
71
69
 
72
- stubba.unstub(method_2)
70
+ stubba.unstub(method2)
73
71
 
74
- assert_equal [method_1], stubba.stubba_methods
75
- assert method_2.__verified__?
72
+ assert_equal [method1], stubba.stubba_methods
73
+ assert method2.__verified__?
76
74
  end
77
75
 
78
76
  def test_should_unstub_all_methods
79
77
  stubba = Central.new
80
- method_1 = build_mock
81
- method_1.stubs(:matches?).returns(true)
82
- method_1.expects(:unstub)
83
- method_2 = build_mock
84
- method_2.stubs(:matches?).returns(true)
85
- method_2.expects(:unstub)
86
- stubba.stubba_methods = [method_1, method_2]
78
+ method1 = build_mock
79
+ method1.stubs(:matches?).returns(true)
80
+ method1.expects(:unstub)
81
+ method2 = build_mock
82
+ method2.stubs(:matches?).returns(true)
83
+ method2.expects(:unstub)
84
+ stubba.stubba_methods = [method1, method2]
87
85
 
88
86
  stubba.unstub_all
89
87
 
90
88
  assert_equal [], stubba.stubba_methods
91
- assert method_1.__verified__?
92
- assert method_2.__verified__?
89
+ assert method1.__verified__?
90
+ assert method2.__verified__?
93
91
  end
94
92
 
95
93
  private
@@ -3,11 +3,9 @@ require File.expand_path('../../test_helper', __FILE__)
3
3
  require 'mocha/change_state_side_effect'
4
4
 
5
5
  class ChangeStateSideEffectTest < Mocha::TestCase
6
-
7
6
  include Mocha
8
7
 
9
8
  class FakeState
10
-
11
9
  attr_reader :active
12
10
  attr_writer :description
13
11
 
@@ -18,7 +16,6 @@ class ChangeStateSideEffectTest < Mocha::TestCase
18
16
  def mocha_inspect
19
17
  @description
20
18
  end
21
-
22
19
  end
23
20
 
24
21
  def test_should_activate_the_given_state
@@ -37,5 +34,4 @@ class ChangeStateSideEffectTest < Mocha::TestCase
37
34
 
38
35
  assert_equal 'then the-new-state', side_effect.mocha_inspect
39
36
  end
40
-
41
37
  end
@@ -1,13 +1,19 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha/class_methods'
3
3
  require 'mocha/object_methods'
4
+ require 'mocha/mockery'
5
+ require 'mocha/names'
4
6
 
5
7
  class ClassMethodsTest < Mocha::TestCase
6
-
7
8
  def setup
9
+ Mocha::Mockery.setup
8
10
  @klass = Class.new.extend(Mocha::ClassMethods, Mocha::ObjectMethods)
9
11
  end
10
12
 
13
+ def teardown
14
+ Mocha::Mockery.teardown
15
+ end
16
+
11
17
  def test_should_build_any_instance_object
12
18
  any_instance = @klass.any_instance
13
19
  assert_not_nil any_instance
@@ -15,13 +21,37 @@ class ClassMethodsTest < Mocha::TestCase
15
21
  end
16
22
 
17
23
  def test_should_return_same_any_instance_object
18
- any_instance_1 = @klass.any_instance
19
- any_instance_2 = @klass.any_instance
20
- assert_equal any_instance_1, any_instance_2
24
+ any_instance1 = @klass.any_instance
25
+ any_instance2 = @klass.any_instance
26
+ assert_equal any_instance1, any_instance2
27
+ end
28
+
29
+ def test_any_instance_should_build_mocha_referring_to_klass
30
+ mocha = @klass.any_instance.mocha
31
+ assert_not_nil mocha
32
+ assert mocha.is_a?(Mocha::Mock)
33
+ expected_name = Mocha::ImpersonatingAnyInstanceName.new(@klass).mocha_inspect
34
+ assert_equal expected_name, mocha.mocha_inspect
35
+ end
36
+
37
+ def test_any_instance_should_not_build_mocha_if_instantiate_is_false
38
+ assert_nil @klass.any_instance.mocha(false)
39
+ end
40
+
41
+ def test_any_instance_should_reuse_existing_mocha
42
+ mocha1 = @klass.any_instance.mocha
43
+ mocha2 = @klass.any_instance.mocha
44
+ assert_equal mocha1, mocha2
45
+ end
46
+
47
+ def test_any_instance_should_reuse_existing_mocha_even_if_instantiate_is_false
48
+ mocha1 = @klass.any_instance.mocha
49
+ mocha2 = @klass.any_instance.mocha(false)
50
+ assert_equal mocha1, mocha2
21
51
  end
22
52
 
23
53
  def test_should_use_stubba_class_method_for_class
24
- assert_equal Mocha::ClassMethod, @klass.stubba_method
54
+ assert_equal Mocha::InstanceMethod, @klass.stubba_method
25
55
  end
26
56
 
27
57
  def test_should_use_stubba_class_method_for_any_instance
@@ -36,5 +66,4 @@ class ClassMethodsTest < Mocha::TestCase
36
66
  any_instance = @klass.any_instance
37
67
  assert_equal @klass, any_instance.stubba_object
38
68
  end
39
-
40
69
  end
@@ -1,38 +1,37 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
- require "mocha/configuration"
2
+ require 'mocha/configuration'
3
3
 
4
4
  class ConfigurationTest < Mocha::TestCase
5
5
  def test_allow_temporarily_changes_config_when_given_block
6
- Mocha::Configuration.warn_when(:stubbing_method_unnecessarily)
6
+ Mocha.configure { |c| c.stubbing_method_unnecessarily = :warn }
7
7
  yielded = false
8
- Mocha::Configuration.allow(:stubbing_method_unnecessarily) do
8
+ Mocha::Configuration.override(:stubbing_method_unnecessarily => :allow) do
9
9
  yielded = true
10
- assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
10
+ assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
11
11
  end
12
12
  assert yielded
13
- assert Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily)
13
+ assert_equal :warn, Mocha.configuration.stubbing_method_unnecessarily
14
14
  end
15
15
 
16
16
  def test_prevent_temporarily_changes_config_when_given_block
17
- Mocha::Configuration.allow(:stubbing_method_unnecessarily)
17
+ Mocha.configure { |c| c.stubbing_method_unnecessarily = :allow }
18
18
  yielded = false
19
- Mocha::Configuration.prevent(:stubbing_method_unnecessarily) do
19
+ Mocha::Configuration.override(:stubbing_method_unnecessarily => :prevent) do
20
20
  yielded = true
21
- assert Mocha::Configuration.prevent?(:stubbing_method_unnecessarily)
21
+ assert_equal :prevent, Mocha.configuration.stubbing_method_unnecessarily
22
22
  end
23
23
  assert yielded
24
- assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
24
+ assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
25
25
  end
26
26
 
27
27
  def test_warn_when_temporarily_changes_config_when_given_block
28
- Mocha::Configuration.allow(:stubbing_method_unnecessarily)
28
+ Mocha.configure { |c| c.stubbing_method_unnecessarily = :allow }
29
29
  yielded = false
30
- Mocha::Configuration.warn_when(:stubbing_method_unnecessarily) do
30
+ Mocha::Configuration.override(:stubbing_method_unnecessarily => :warn) do
31
31
  yielded = true
32
- assert Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily)
32
+ assert_equal :warn, Mocha.configuration.stubbing_method_unnecessarily
33
33
  end
34
34
  assert yielded
35
- assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
35
+ assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
36
36
  end
37
37
  end
38
-
@@ -2,7 +2,6 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha/inspect'
3
3
 
4
4
  class DateTimeInspectTest < Mocha::TestCase
5
-
6
5
  def test_should_use_include_date_in_seconds
7
6
  time = Time.now
8
7
  assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect
@@ -14,8 +13,7 @@ class DateTimeInspectTest < Mocha::TestCase
14
13
  end
15
14
 
16
15
  def test_should_use_to_s_for_datetime
17
- datetime = DateTime.new(2006, 1, 1)
16
+ datetime = DateTime.new(2006, 1, 1) # rubocop:disable Style/DateTime
18
17
  assert_equal datetime.to_s, datetime.mocha_inspect
19
18
  end
20
-
21
19
  end
@@ -1,42 +1,45 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
+ require 'mocha/invocation'
3
4
  require 'mocha/exception_raiser'
4
5
  require 'timeout'
5
6
 
6
7
  class ExceptionRaiserTest < Mocha::TestCase
7
-
8
8
  include Mocha
9
9
 
10
+ def new_invocation
11
+ Invocation.new(:irrelevant, :irrelevant)
12
+ end
13
+
10
14
  def test_should_raise_exception_with_specified_class_and_default_message
11
15
  exception_class = Class.new(StandardError)
12
16
  raiser = ExceptionRaiser.new(exception_class, nil)
13
- exception = assert_raises(exception_class) { raiser.evaluate }
17
+ exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
14
18
  assert_equal exception_class.to_s, exception.message
15
19
  end
16
20
 
17
21
  def test_should_raise_exception_with_specified_class_and_message
18
22
  exception_class = Class.new(StandardError)
19
23
  raiser = ExceptionRaiser.new(exception_class, 'message')
20
- exception = assert_raises(exception_class) { raiser.evaluate }
24
+ exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
21
25
  assert_equal 'message', exception.message
22
26
  end
23
27
 
24
28
  def test_should_raise_exception_instance
25
29
  exception_class = Class.new(StandardError)
26
30
  raiser = ExceptionRaiser.new(exception_class.new('message'), nil)
27
- exception = assert_raises(exception_class) { raiser.evaluate }
31
+ exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
28
32
  assert_equal 'message', exception.message
29
33
  end
30
34
 
31
35
  def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
32
36
  raiser = ExceptionRaiser.new(Interrupt, nil)
33
- assert_raises(Interrupt) { raiser.evaluate }
37
+ assert_raises(Interrupt) { raiser.evaluate(new_invocation) }
34
38
  end
35
39
 
36
40
  def test_should_raise_subclass_of_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
37
41
  exception_class = Class.new(Interrupt)
38
42
  raiser = ExceptionRaiser.new(exception_class, nil)
39
- assert_raises(exception_class) { raiser.evaluate }
43
+ assert_raises(exception_class) { raiser.evaluate(new_invocation) }
40
44
  end
41
-
42
45
  end
@@ -1,11 +1,12 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha/expectation_list'
3
3
  require 'mocha/expectation'
4
+ require 'mocha/invocation'
4
5
  require 'set'
5
6
  require 'method_definer'
6
7
 
7
8
  class ExpectationListTest < Mocha::TestCase
8
-
9
+ include MethodDefiner
9
10
  include Mocha
10
11
 
11
12
  def test_should_return_added_expectation
@@ -20,7 +21,7 @@ class ExpectationListTest < Mocha::TestCase
20
21
  expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
21
22
  expectation_list.add(expectation1)
22
23
  expectation_list.add(expectation2)
23
- assert_same expectation1, expectation_list.match(:my_method, :argument1, :argument2)
24
+ assert_same expectation1, expectation_list.match(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
24
25
  end
25
26
 
26
27
  def test_should_remove_all_expectations_matching_method_name
@@ -32,9 +33,9 @@ class ExpectationListTest < Mocha::TestCase
32
33
  expectation_list.add(expectation2)
33
34
  expectation_list.add(expectation3)
34
35
  expectation_list.remove_all_matching_method(:method_one)
35
- assert_nil expectation_list.match(:method_one, :argument1, :argument2)
36
- assert_nil expectation_list.match(:method_one, :argument3, :argument4)
37
- assert_same expectation3, expectation_list.match(:method_two)
36
+ assert_nil expectation_list.match(Invocation.new(:irrelevant, :method_one, :argument1, :argument2))
37
+ assert_nil expectation_list.match(Invocation.new(:irrelevant, :method_one, :argument3, :argument4))
38
+ assert_same expectation3, expectation_list.match(Invocation.new(:irrelevant, :method_two))
38
39
  end
39
40
 
40
41
  def test_should_find_most_recent_matching_expectation
@@ -43,29 +44,29 @@ class ExpectationListTest < Mocha::TestCase
43
44
  expectation2 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
44
45
  expectation_list.add(expectation1)
45
46
  expectation_list.add(expectation2)
46
- assert_same expectation2, expectation_list.match(:my_method, :argument1, :argument2)
47
+ assert_same expectation2, expectation_list.match(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
47
48
  end
48
49
 
49
50
  def test_should_find_matching_expectation_allowing_invocation
50
51
  expectation_list = ExpectationList.new
51
52
  expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
52
53
  expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
53
- expectation1.define_instance_method(:invocations_allowed?) { true }
54
- expectation2.define_instance_method(:invocations_allowed?) { true }
54
+ define_instance_method(expectation1, :invocations_allowed?) { true }
55
+ define_instance_method(expectation2, :invocations_allowed?) { true }
55
56
  expectation_list.add(expectation1)
56
57
  expectation_list.add(expectation2)
57
- assert_same expectation1, expectation_list.match_allowing_invocation(:my_method, :argument1, :argument2)
58
+ assert_same expectation1, expectation_list.match_allowing_invocation(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
58
59
  end
59
60
 
60
61
  def test_should_find_most_recent_matching_expectation_allowing_invocation
61
62
  expectation_list = ExpectationList.new
62
63
  expectation1 = Expectation.new(nil, :my_method)
63
64
  expectation2 = Expectation.new(nil, :my_method)
64
- expectation1.define_instance_method(:invocations_allowed?) { true }
65
- expectation2.define_instance_method(:invocations_allowed?) { false }
65
+ define_instance_method(expectation1, :invocations_allowed?) { true }
66
+ define_instance_method(expectation2, :invocations_allowed?) { false }
66
67
  expectation_list.add(expectation1)
67
68
  expectation_list.add(expectation2)
68
- assert_same expectation1, expectation_list.match_allowing_invocation(:my_method)
69
+ assert_same expectation1, expectation_list.match_allowing_invocation(Invocation.new(:irrelevant, :my_method))
69
70
  end
70
71
 
71
72
  def test_should_combine_two_expectation_lists_into_one
@@ -78,5 +79,4 @@ class ExpectationListTest < Mocha::TestCase
78
79
  expectation_list = expectation_list1 + expectation_list2
79
80
  assert_equal [expectation1, expectation2], expectation_list.to_a
80
81
  end
81
-
82
82
  end
@@ -1,332 +1,321 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
- require 'method_definer'
3
2
  require 'mocha/expectation'
3
+ require 'mocha/invocation'
4
4
  require 'mocha/sequence'
5
5
  require 'execution_point'
6
6
  require 'simple_counter'
7
7
 
8
8
  class ExpectationTest < Mocha::TestCase
9
-
10
9
  include Mocha
11
10
 
12
11
  def new_expectation
13
12
  Expectation.new(nil, :expected_method)
14
13
  end
15
14
 
15
+ def invoke(expectation, &block)
16
+ expectation.invoke(Invocation.new(:irrelevant, :expected_method), &block)
17
+ end
18
+
16
19
  def test_should_match_calls_to_same_method_with_any_parameters
17
- assert new_expectation.match?(:expected_method, 1, 2, 3)
20
+ assert new_expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
18
21
  end
19
22
 
20
23
  def test_should_match_calls_to_same_method_with_exactly_zero_parameters
21
- expectation = new_expectation.with()
22
- assert expectation.match?(:expected_method)
24
+ assert new_expectation.with.match?(Invocation.new(:irrelevant, :expected_method))
23
25
  end
24
26
 
25
27
  def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters
26
- expectation = new_expectation.with()
27
- assert !expectation.match?(:expected_method, 1, 2, 3)
28
+ assert !new_expectation.with.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
28
29
  end
29
30
 
30
31
  def test_should_match_calls_to_same_method_with_expected_parameter_values
31
- expectation = new_expectation.with(1, 2, 3)
32
- assert expectation.match?(:expected_method, 1, 2, 3)
32
+ assert new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
33
33
  end
34
34
 
35
35
  def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected
36
- expectation = new_expectation.with() {|x, y, z| x + y == z}
37
- assert expectation.match?(:expected_method, 1, 2, 3)
36
+ expectation = new_expectation.with { |x, y, z| x + y == z }
37
+ assert expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
38
38
  end
39
39
 
40
40
  def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
41
- expectation = new_expectation.with() {|x, y, z| x + y == z}
42
- assert !expectation.match?(:different_method, 1, 2, 3)
41
+ expectation = new_expectation.with { |x, y, z| x + y == z }
42
+ assert !expectation.match?(Invocation.new(:irrelevant, :different_method, 1, 2, 3))
43
43
  end
44
44
 
45
45
  def test_should_not_match_calls_to_different_methods_with_no_parameters
46
- assert !new_expectation.match?(:unexpected_method)
46
+ assert !new_expectation.match?(Invocation.new(:irrelevant, :unexpected_method))
47
47
  end
48
48
 
49
49
  def test_should_not_match_calls_to_same_method_with_too_few_parameters
50
- expectation = new_expectation.with(1, 2, 3)
51
- assert !expectation.match?(:unexpected_method, 1, 2)
50
+ assert !new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 2))
52
51
  end
53
52
 
54
53
  def test_should_not_match_calls_to_same_method_with_too_many_parameters
55
- expectation = new_expectation.with(1, 2)
56
- assert !expectation.match?(:unexpected_method, 1, 2, 3)
54
+ assert !new_expectation.with(1, 2).match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
57
55
  end
58
56
 
59
57
  def test_should_not_match_calls_to_same_method_with_unexpected_parameter_values
60
- expectation = new_expectation.with(1, 2, 3)
61
- assert !expectation.match?(:unexpected_method, 1, 0, 3)
58
+ assert !new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 0, 3))
62
59
  end
63
60
 
64
61
  def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected
65
- expectation = new_expectation.with() {|x, y, z| x + y == z}
66
- assert !expectation.match?(:expected_method, 1, 0, 3)
62
+ expectation = new_expectation.with { |x, y, z| x + y == z }
63
+ assert !expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 0, 3))
67
64
  end
68
65
 
69
66
  def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two
70
67
  expectation = new_expectation.times(1)
71
68
  assert expectation.invocations_allowed?
72
- expectation.invoke
69
+ invoke(expectation)
73
70
  assert !expectation.invocations_allowed?
74
71
  end
75
72
 
76
73
  def test_should_allow_invocations_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three
77
74
  expectation = new_expectation.times(2)
78
- assert expectation.invocations_allowed?
79
- expectation.invoke
80
- assert expectation.invocations_allowed?
81
- expectation.invoke
75
+ 2.times do
76
+ assert expectation.invocations_allowed?
77
+ invoke(expectation)
78
+ end
82
79
  assert !expectation.invocations_allowed?
83
80
  end
84
81
 
85
82
  def test_should_allow_invocations_until_expected_invocation_count_is_a_range_from_two_to_three_and_actual_invocation_count_would_be_four
86
83
  expectation = new_expectation.times(2..3)
87
- assert expectation.invocations_allowed?
88
- expectation.invoke
89
- assert expectation.invocations_allowed?
90
- expectation.invoke
91
- assert expectation.invocations_allowed?
92
- expectation.invoke
84
+ 3.times do
85
+ assert expectation.invocations_allowed?
86
+ invoke(expectation)
87
+ end
93
88
  assert !expectation.invocations_allowed?
94
89
  end
95
90
 
96
91
  def test_should_store_provided_backtrace
97
92
  backtrace = Object.new
98
- expectation = Expectation.new(nil, :expected_method, backtrace)
99
- assert_equal backtrace, expectation.backtrace
93
+ assert_equal backtrace, Expectation.new(nil, :expected_method, backtrace).backtrace
100
94
  end
101
95
 
96
+ # rubocop:disable Style/Semicolon
102
97
  def test_should_default_backtrace_to_caller
103
98
  execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
104
99
  assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
105
100
  end
101
+ # rubocop:enable Style/Semicolon
106
102
 
107
103
  def test_should_not_yield
108
104
  yielded = false
109
- new_expectation.invoke() { yielded = true }
105
+ invoke(new_expectation) { yielded = true }
110
106
  assert_equal false, yielded
111
107
  end
112
108
 
113
109
  def test_should_yield_no_parameters
114
- expectation = new_expectation().yields()
115
110
  yielded_parameters = nil
116
- expectation.invoke() { |*parameters| yielded_parameters = parameters }
117
- assert_equal Array.new, yielded_parameters
111
+ invoke(new_expectation.yields) { |*parameters| yielded_parameters = parameters }
112
+ assert_equal [], yielded_parameters
113
+ end
114
+
115
+ def test_yield_should_fail_when_the_caller_does_not_provide_a_block
116
+ assert_raises(LocalJumpError) { invoke(new_expectation.yields(:foo)) }
118
117
  end
119
118
 
120
119
  def test_should_yield_with_specified_parameters
121
- expectation = new_expectation().yields(1, 2, 3)
122
120
  yielded_parameters = nil
123
- expectation.invoke() { |*parameters| yielded_parameters = parameters }
121
+ invoke(new_expectation.yields(1, 2, 3)) { |*parameters| yielded_parameters = parameters }
124
122
  assert_equal [1, 2, 3], yielded_parameters
125
123
  end
126
124
 
127
125
  def test_should_yield_different_parameters_on_consecutive_invocations
128
- expectation = new_expectation().yields(1, 2, 3).yields(4, 5)
126
+ expectation = new_expectation.yields(1, 2, 3).yields(4, 5)
129
127
  yielded_parameters = []
130
- expectation.invoke() { |*parameters| yielded_parameters << parameters }
131
- expectation.invoke() { |*parameters| yielded_parameters << parameters }
128
+ invoke(expectation) { |*parameters| yielded_parameters << parameters }
129
+ invoke(expectation) { |*parameters| yielded_parameters << parameters }
132
130
  assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
133
131
  end
134
132
 
135
133
  def test_should_yield_multiple_times_for_single_invocation
136
- expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5])
137
134
  yielded_parameters = []
138
- expectation.invoke() { |*parameters| yielded_parameters << parameters }
135
+ invoke(new_expectation.multiple_yields([1, 2, 3], [4, 5])) { |*parameters| yielded_parameters << parameters }
139
136
  assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
140
137
  end
141
138
 
142
139
  def test_should_yield_multiple_times_for_first_invocation_and_once_for_second_invocation
143
- expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7)
140
+ expectation = new_expectation.multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7)
144
141
  yielded_parameters = []
145
- expectation.invoke() { |*parameters| yielded_parameters << parameters }
146
- expectation.invoke() { |*parameters| yielded_parameters << parameters }
142
+ invoke(expectation) { |*parameters| yielded_parameters << parameters }
143
+ invoke(expectation) { |*parameters| yielded_parameters << parameters }
147
144
  assert_equal [[1, 2, 3], [4, 5], [6, 7]], yielded_parameters
148
145
  end
149
146
 
150
147
  def test_should_return_specified_value
151
- expectation = new_expectation.returns(99)
152
- assert_equal 99, expectation.invoke
148
+ assert_equal 99, invoke(new_expectation.returns(99))
153
149
  end
154
150
 
155
151
  def test_should_return_same_specified_value_multiple_times
156
152
  expectation = new_expectation.returns(99)
157
- assert_equal 99, expectation.invoke
158
- assert_equal 99, expectation.invoke
153
+ assert_equal 99, invoke(expectation)
154
+ assert_equal 99, invoke(expectation)
159
155
  end
160
156
 
161
157
  def test_should_return_specified_values_on_consecutive_calls
162
158
  expectation = new_expectation.returns(99, 100, 101)
163
- assert_equal 99, expectation.invoke
164
- assert_equal 100, expectation.invoke
165
- assert_equal 101, expectation.invoke
159
+ assert_equal 99, invoke(expectation)
160
+ assert_equal 100, invoke(expectation)
161
+ assert_equal 101, invoke(expectation)
166
162
  end
167
163
 
168
164
  def test_should_return_specified_values_on_consecutive_calls_even_if_values_are_modified
169
165
  values = [99, 100, 101]
170
166
  expectation = new_expectation.returns(*values)
171
167
  values.shift
172
- assert_equal 99, expectation.invoke
173
- assert_equal 100, expectation.invoke
174
- assert_equal 101, expectation.invoke
168
+ assert_equal 99, invoke(expectation)
169
+ assert_equal 100, invoke(expectation)
170
+ assert_equal 101, invoke(expectation)
175
171
  end
176
172
 
177
173
  def test_should_return_nil_by_default
178
- assert_nil new_expectation.invoke
174
+ assert_nil invoke(new_expectation)
179
175
  end
180
176
 
181
177
  def test_should_return_nil_if_no_value_specified
182
- expectation = new_expectation.returns()
183
- assert_nil expectation.invoke
178
+ assert_nil invoke(new_expectation.returns)
184
179
  end
185
180
 
186
181
  def test_should_raise_runtime_exception
187
- expectation = new_expectation.raises
188
- assert_raise(RuntimeError) { expectation.invoke }
182
+ assert_raises(RuntimeError) { invoke(new_expectation.raises) }
189
183
  end
190
184
 
191
185
  def test_should_raise_custom_exception
192
186
  exception = Class.new(Exception)
193
- expectation = new_expectation.raises(exception)
194
- assert_raise(exception) { expectation.invoke }
187
+ assert_raises(exception) { invoke(new_expectation.raises(exception)) }
195
188
  end
196
189
 
197
190
  def test_should_raise_same_instance_of_custom_exception
198
191
  exception_klass = Class.new(StandardError)
199
192
  expected_exception = exception_klass.new
200
- expectation = new_expectation.raises(expected_exception)
201
- actual_exception = assert_raise(exception_klass) { expectation.invoke }
193
+ actual_exception = assert_raises(exception_klass) { invoke(new_expectation.raises(expected_exception)) }
202
194
  assert_same expected_exception, actual_exception
203
195
  end
204
196
 
205
197
  def test_should_use_the_default_exception_message
206
- expectation = new_expectation.raises(Exception)
207
- exception = assert_raise(Exception) { expectation.invoke }
198
+ exception = assert_raises(Exception) { invoke(new_expectation.raises(Exception)) }
208
199
  assert_equal Exception.new.message, exception.message
209
200
  end
210
201
 
211
202
  def test_should_raise_custom_exception_with_message
212
- exception_msg = "exception message"
213
- expectation = new_expectation.raises(Exception, exception_msg)
214
- exception = assert_raise(Exception) { expectation.invoke }
203
+ exception_msg = 'exception message'
204
+ exception = assert_raises(Exception) { invoke(new_expectation.raises(Exception, exception_msg)) }
215
205
  assert_equal exception_msg, exception.message
216
206
  end
217
207
 
218
208
  def test_should_return_values_then_raise_exception
219
- expectation = new_expectation.returns(1, 2).then.raises()
220
- assert_equal 1, expectation.invoke
221
- assert_equal 2, expectation.invoke
222
- assert_raise(RuntimeError) { expectation.invoke }
209
+ expectation = new_expectation.returns(1, 2).then.raises
210
+ assert_equal 1, invoke(expectation)
211
+ assert_equal 2, invoke(expectation)
212
+ assert_raises(RuntimeError) { invoke(expectation) }
223
213
  end
224
214
 
225
215
  def test_should_raise_exception_then_return_values
226
- expectation = new_expectation.raises().then.returns(1, 2)
227
- assert_raise(RuntimeError) { expectation.invoke }
228
- assert_equal 1, expectation.invoke
229
- assert_equal 2, expectation.invoke
216
+ expectation = new_expectation.raises.then.returns(1, 2)
217
+ assert_raises(RuntimeError) { invoke(expectation) }
218
+ assert_equal 1, invoke(expectation)
219
+ assert_equal 2, invoke(expectation)
230
220
  end
231
221
 
232
222
  def test_should_verify_successfully_if_expected_call_was_made
233
223
  expectation = new_expectation
234
- expectation.invoke
224
+ invoke(expectation)
235
225
  assert expectation.verified?
236
226
  end
237
227
 
238
228
  def test_should_not_verify_successfully_if_call_expected_once_but_invoked_twice
239
229
  expectation = new_expectation.once
240
- expectation.invoke
241
- expectation.invoke
230
+ invoke(expectation)
231
+ invoke(expectation)
242
232
  assert !expectation.verified?
243
233
  end
244
234
 
245
235
  def test_should_not_verify_successfully_if_call_expected_once_but_not_invoked
246
- expectation = new_expectation.once
247
- assert !expectation.verified?
236
+ assert !new_expectation.once.verified?
248
237
  end
249
238
 
250
239
  def test_should_verify_successfully_if_call_expected_once_and_invoked_once
251
240
  expectation = new_expectation.once
252
- expectation.invoke
241
+ invoke(expectation)
253
242
  assert expectation.verified?
254
243
  end
255
244
 
256
245
  def test_should_not_verify_successfully_if_call_expected_twice_and_invoked_three_times
257
246
  expectation = new_expectation.twice
258
- expectation.invoke
259
- expectation.invoke
260
- expectation.invoke
247
+ invoke(expectation)
248
+ invoke(expectation)
249
+ invoke(expectation)
261
250
  assert !expectation.verified?
262
251
  end
263
252
 
264
253
  def test_should_not_verify_successfully_if_call_expected_twice_but_invoked_once
265
254
  expectation = new_expectation.twice
266
- expectation.invoke
255
+ invoke(expectation)
267
256
  assert !expectation.verified?
268
257
  end
269
258
 
270
259
  def test_should_verify_successfully_if_call_expected_twice_and_invoked_twice
271
260
  expectation = new_expectation.twice
272
- expectation.invoke
273
- expectation.invoke
261
+ invoke(expectation)
262
+ invoke(expectation)
274
263
  assert expectation.verified?
275
264
  end
276
265
 
277
266
  def test_should_verify_successfully_if_expected_call_was_made_at_least_once
278
267
  expectation = new_expectation.at_least_once
279
- 3.times {expectation.invoke}
268
+ 3.times { invoke(expectation) }
280
269
  assert expectation.verified?
281
270
  end
282
271
 
283
272
  def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once
284
273
  expectation = new_expectation.with(1, 2, 3).at_least_once
285
274
  assert !expectation.verified?
286
- assert_match(/expected at least once, not yet invoked/i, expectation.mocha_inspect)
275
+ assert_match(/expected at least once, invoked never/i, expectation.mocha_inspect)
287
276
  end
288
277
 
289
278
  def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times
290
279
  expectation = new_expectation.times(2)
291
- 2.times {expectation.invoke}
280
+ 2.times { invoke(expectation) }
292
281
  assert expectation.verified?
293
282
  end
294
283
 
295
284
  def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times
296
285
  expectation = new_expectation.times(2)
297
- 1.times {expectation.invoke}
286
+ 1.times { invoke(expectation) }
298
287
  assert !expectation.verified?
299
288
  assert_match(/expected exactly twice, invoked once/i, expectation.mocha_inspect)
300
289
  end
301
290
 
302
291
  def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times
303
292
  expectation = new_expectation.times(2)
304
- 3.times {expectation.invoke}
293
+ 3.times { invoke(expectation) }
305
294
  assert !expectation.verified?
306
295
  end
307
296
 
308
297
  def test_should_increment_assertion_counter_for_expectation_because_it_does_need_verifyng
309
298
  expectation = new_expectation
310
- expectation.invoke
299
+ invoke(expectation)
311
300
  assertion_counter = SimpleCounter.new
312
301
  expectation.verified?(assertion_counter)
313
302
  assert_equal 1, assertion_counter.count
314
303
  end
315
304
 
316
305
  def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_need_verifying
317
- stub = Expectation.new(nil, :expected_method).at_least(0)
318
306
  assertion_counter = SimpleCounter.new
319
- stub.verified?(assertion_counter)
307
+ Expectation.new(nil, :expected_method).at_least(0).verified?(assertion_counter)
320
308
  assert_equal 0, assertion_counter.count
321
309
  end
322
310
 
311
+ # rubocop:disable Style/Semicolon
323
312
  def test_should_store_backtrace_from_point_where_expectation_was_created
324
313
  execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
325
314
  assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
326
315
  end
316
+ # rubocop:enable Style/Semicolon
327
317
 
328
318
  class FakeMock
329
-
330
319
  def initialize(name)
331
320
  @name = name
332
321
  end
@@ -334,20 +323,18 @@ class ExpectationTest < Mocha::TestCase
334
323
  def mocha_inspect
335
324
  @name
336
325
  end
337
-
338
326
  end
339
327
 
340
328
  def test_should_raise_error_with_message_indicating_which_method_was_expected_to_be_called_on_which_mock_object_with_which_parameters_and_in_what_sequences
341
329
  mock = FakeMock.new('mock')
342
330
  sequence_one = Sequence.new('one')
343
331
  sequence_two = Sequence.new('two')
344
- expectation = Expectation.new(mock, :expected_method).with(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]).in_sequence(sequence_one, sequence_two)
332
+ expectation = Expectation.new(mock, :expected_method).with(1, 2, { 'a' => true }, { :b => false }, [1, 2, 3]).in_sequence(sequence_one, sequence_two)
345
333
  assert !expectation.verified?
346
334
  assert_match %{mock.expected_method(1, 2, {"a" => true}, {:b => false}, [1, 2, 3]); in sequence "one"; in sequence "two"}, expectation.mocha_inspect
347
335
  end
348
336
 
349
337
  class FakeConstraint
350
-
351
338
  def initialize(allows_invocation_now)
352
339
  @allows_invocation_now = allows_invocation_now
353
340
  end
@@ -355,12 +342,11 @@ class ExpectationTest < Mocha::TestCase
355
342
  def allows_invocation_now?
356
343
  @allows_invocation_now
357
344
  end
358
-
359
345
  end
360
346
 
361
347
  def test_should_be_in_correct_order_if_all_ordering_constraints_allow_invocation_now
362
- constraint_one = FakeConstraint.new(allows_invocation_now = true)
363
- constraint_two = FakeConstraint.new(allows_invocation_now = true)
348
+ constraint_one = FakeConstraint.new(true)
349
+ constraint_two = FakeConstraint.new(true)
364
350
  expectation = Expectation.new(nil, :method_one)
365
351
  expectation.add_ordering_constraint(constraint_one)
366
352
  expectation.add_ordering_constraint(constraint_two)
@@ -368,8 +354,8 @@ class ExpectationTest < Mocha::TestCase
368
354
  end
369
355
 
370
356
  def test_should_not_be_in_correct_order_if_one_ordering_constraint_does_not_allow_invocation_now
371
- constraint_one = FakeConstraint.new(allows_invocation_now = true)
372
- constraint_two = FakeConstraint.new(allows_invocation_now = false)
357
+ constraint_one = FakeConstraint.new(true)
358
+ constraint_two = FakeConstraint.new(false)
373
359
  expectation = Expectation.new(nil, :method_one)
374
360
  expectation.add_ordering_constraint(constraint_one)
375
361
  expectation.add_ordering_constraint(constraint_two)
@@ -377,48 +363,46 @@ class ExpectationTest < Mocha::TestCase
377
363
  end
378
364
 
379
365
  def test_should_match_if_all_ordering_constraints_allow_invocation_now
380
- constraint_one = FakeConstraint.new(allows_invocation_now = true)
381
- constraint_two = FakeConstraint.new(allows_invocation_now = true)
366
+ constraint_one = FakeConstraint.new(true)
367
+ constraint_two = FakeConstraint.new(true)
382
368
  expectation = Expectation.new(nil, :method_one)
383
369
  expectation.add_ordering_constraint(constraint_one)
384
370
  expectation.add_ordering_constraint(constraint_two)
385
- assert expectation.match?(:method_one)
371
+ assert expectation.match?(Invocation.new(:irrelevant, :method_one))
386
372
  end
387
373
 
388
374
  def test_should_not_match_if_one_ordering_constraints_does_not_allow_invocation_now
389
- constraint_one = FakeConstraint.new(allows_invocation_now = true)
390
- constraint_two = FakeConstraint.new(allows_invocation_now = false)
375
+ constraint_one = FakeConstraint.new(true)
376
+ constraint_two = FakeConstraint.new(false)
391
377
  expectation = Expectation.new(nil, :method_one)
392
378
  expectation.add_ordering_constraint(constraint_one)
393
379
  expectation.add_ordering_constraint(constraint_two)
394
- assert !expectation.match?(:method_one)
380
+ assert !expectation.match?(Invocation.new(:irrelevant, :method_one))
395
381
  end
396
382
 
397
383
  def test_should_not_be_satisfied_when_required_invocation_has_not_been_made
398
- expectation = Expectation.new(nil, :method_one).times(1)
399
- assert !expectation.satisfied?
384
+ assert !Expectation.new(nil, :method_one).times(1).satisfied?
400
385
  end
401
386
 
402
387
  def test_should_be_satisfied_when_required_invocation_has_been_made
403
388
  expectation = Expectation.new(nil, :method_one).times(1)
404
- expectation.invoke
389
+ invoke(expectation)
405
390
  assert expectation.satisfied?
406
391
  end
407
392
 
408
393
  def test_should_not_be_satisfied_when_minimum_number_of_invocations_has_not_been_made
409
394
  expectation = Expectation.new(nil, :method_one).at_least(2)
410
- expectation.invoke
395
+ invoke(expectation)
411
396
  assert !expectation.satisfied?
412
397
  end
413
398
 
414
399
  def test_should_be_satisfied_when_minimum_number_of_invocations_has_been_made
415
400
  expectation = Expectation.new(nil, :method_one).at_least(2)
416
- 2.times { expectation.invoke }
401
+ 2.times { invoke(expectation) }
417
402
  assert expectation.satisfied?
418
403
  end
419
404
 
420
405
  class FakeSequence
421
-
422
406
  attr_reader :expectations
423
407
 
424
408
  def initialize
@@ -428,7 +412,6 @@ class ExpectationTest < Mocha::TestCase
428
412
  def constrain_as_next_in_sequence(expectation)
429
413
  @expectations << expectation
430
414
  end
431
-
432
415
  end
433
416
 
434
417
  def test_should_tell_sequences_to_constrain_expectation_as_next_in_sequence
@@ -441,7 +424,6 @@ class ExpectationTest < Mocha::TestCase
441
424
  end
442
425
 
443
426
  class FakeState
444
-
445
427
  def initialize
446
428
  @active = false
447
429
  end
@@ -453,7 +435,6 @@ class ExpectationTest < Mocha::TestCase
453
435
  def active?
454
436
  @active
455
437
  end
456
-
457
438
  end
458
439
 
459
440
  def test_should_change_state_when_expectation_is_invoked
@@ -462,7 +443,7 @@ class ExpectationTest < Mocha::TestCase
462
443
 
463
444
  expectation.then(state)
464
445
 
465
- expectation.invoke
446
+ invoke(expectation)
466
447
  assert state.active?
467
448
  end
468
449
 
@@ -471,10 +452,10 @@ class ExpectationTest < Mocha::TestCase
471
452
  expectation = Expectation.new(nil, :method_one)
472
453
 
473
454
  expectation.when(state)
474
- assert !expectation.match?(:method_one)
455
+ assert !expectation.match?(Invocation.new(:irrelevant, :method_one))
475
456
 
476
457
  state.activate
477
- assert expectation.match?(:method_one)
458
+ assert expectation.match?(Invocation.new(:irrelevant, :method_one))
478
459
  end
479
460
 
480
461
  def test_should_include_default_representation_of_object_in_inspect
@@ -482,8 +463,7 @@ class ExpectationTest < Mocha::TestCase
482
463
  class << object
483
464
  define_method(:inspect) { 'mock' }
484
465
  end
485
- expectation = Expectation.new(object, :method_one)
486
- assert_match Regexp.new("^#<Expectation:0x[0-9A-Fa-f]{1,12} .* >$"), expectation.inspect
466
+ assert_match Regexp.new('^#<Expectation:0x[0-9A-Fa-f]{1,12} .* >$'), Expectation.new(object, :method_one).inspect
487
467
  end
488
468
 
489
469
  def test_should_include_output_of_mocha_inspect_in_inspect