mocha 1.8.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (274) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.rubocop.yml +3 -0
  4. data/.rubocop_todo.yml +7 -30
  5. data/.yardopts +1 -0
  6. data/CONTRIBUTING.md +1 -1
  7. data/README.md +56 -31
  8. data/RELEASE.md +166 -0
  9. data/Rakefile +15 -7
  10. data/init.rb +1 -3
  11. data/lib/mocha/any_instance_method.rb +11 -53
  12. data/lib/mocha/api.rb +119 -56
  13. data/lib/mocha/block_matcher.rb +31 -0
  14. data/lib/mocha/cardinality.rb +52 -34
  15. data/lib/mocha/class_methods.rb +17 -15
  16. data/lib/mocha/configuration.rb +351 -67
  17. data/lib/mocha/deprecation.rb +2 -1
  18. data/lib/mocha/detection/test_unit.rb +1 -3
  19. data/lib/mocha/exception_raiser.rb +2 -1
  20. data/lib/mocha/expectation.rb +120 -81
  21. data/lib/mocha/expectation_error.rb +1 -3
  22. data/lib/mocha/expectation_list.rb +6 -6
  23. data/lib/mocha/inspect.rb +30 -26
  24. data/lib/mocha/instance_method.rb +19 -2
  25. data/lib/mocha/integration/mini_test.rb +7 -0
  26. data/lib/mocha/integration/test_unit.rb +7 -0
  27. data/lib/mocha/integration.rb +1 -3
  28. data/lib/mocha/invocation.rb +77 -0
  29. data/lib/mocha/macos_version.rb +5 -0
  30. data/lib/mocha/minitest.rb +6 -1
  31. data/lib/mocha/mock.rb +80 -39
  32. data/lib/mocha/mockery.rb +34 -80
  33. data/lib/mocha/names.rb +1 -1
  34. data/lib/mocha/object_methods.rb +13 -19
  35. data/lib/mocha/parameter_matchers/all_of.rb +1 -1
  36. data/lib/mocha/parameter_matchers/any_of.rb +1 -1
  37. data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -9
  38. data/lib/mocha/parameter_matchers/has_entries.rb +2 -3
  39. data/lib/mocha/parameter_matchers/has_entry.rb +24 -16
  40. data/lib/mocha/parameter_matchers/has_key.rb +2 -3
  41. data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
  42. data/lib/mocha/parameter_matchers/has_value.rb +2 -3
  43. data/lib/mocha/parameter_matchers/includes.rb +2 -0
  44. data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
  45. data/lib/mocha/parameter_matchers/is_a.rb +2 -3
  46. data/lib/mocha/parameter_matchers/not.rb +2 -3
  47. data/lib/mocha/parameter_matchers.rb +2 -1
  48. data/lib/mocha/raised_exception.rb +11 -0
  49. data/lib/mocha/return_values.rb +3 -3
  50. data/lib/mocha/setup.rb +5 -0
  51. data/lib/mocha/single_return_value.rb +2 -1
  52. data/lib/mocha/singleton_class.rb +9 -0
  53. data/lib/mocha/state_machine.rb +31 -40
  54. data/lib/mocha/stubbed_method.rb +125 -0
  55. data/lib/mocha/test_unit.rb +6 -1
  56. data/lib/mocha/thrower.rb +2 -1
  57. data/lib/mocha/thrown_object.rb +12 -0
  58. data/lib/mocha/version.rb +1 -1
  59. data/lib/mocha/yield_parameters.rb +5 -11
  60. data/lib/mocha.rb +8 -0
  61. data/mocha.gemspec +14 -10
  62. metadata +16 -233
  63. data/bin/build-matrix +0 -83
  64. data/docs/CNAME +0 -1
  65. data/docs/Mocha/API.html +0 -1056
  66. data/docs/Mocha/ClassMethods.html +0 -267
  67. data/docs/Mocha/Configuration.html +0 -626
  68. data/docs/Mocha/Expectation.html +0 -2709
  69. data/docs/Mocha/ExpectationError.html +0 -157
  70. data/docs/Mocha/ExpectationErrorFactory.html +0 -269
  71. data/docs/Mocha/Hooks.html +0 -385
  72. data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -165
  73. data/docs/Mocha/Integration/MiniTest.html +0 -123
  74. data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -165
  75. data/docs/Mocha/Integration/TestUnit.html +0 -123
  76. data/docs/Mocha/Integration.html +0 -125
  77. data/docs/Mocha/Mock.html +0 -1197
  78. data/docs/Mocha/ObjectMethods.html +0 -712
  79. data/docs/Mocha/ParameterMatchers/AllOf.html +0 -154
  80. data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -154
  81. data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
  82. data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
  83. data/docs/Mocha/ParameterMatchers/Base.html +0 -448
  84. data/docs/Mocha/ParameterMatchers/Equals.html +0 -154
  85. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
  86. data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -154
  87. data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -154
  88. data/docs/Mocha/ParameterMatchers/HasKey.html +0 -154
  89. data/docs/Mocha/ParameterMatchers/HasValue.html +0 -154
  90. data/docs/Mocha/ParameterMatchers/Includes.html +0 -154
  91. data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -154
  92. data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
  93. data/docs/Mocha/ParameterMatchers/KindOf.html +0 -154
  94. data/docs/Mocha/ParameterMatchers/Not.html +0 -154
  95. data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
  96. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -154
  97. data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -154
  98. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -154
  99. data/docs/Mocha/ParameterMatchers.html +0 -3049
  100. data/docs/Mocha/Sequence.html +0 -149
  101. data/docs/Mocha/StateMachine/State.html +0 -141
  102. data/docs/Mocha/StateMachine/StatePredicate.html +0 -141
  103. data/docs/Mocha/StateMachine.html +0 -539
  104. data/docs/Mocha/StubbingError.html +0 -150
  105. data/docs/Mocha/UnexpectedInvocation.html +0 -140
  106. data/docs/Mocha.html +0 -127
  107. data/docs/_index.html +0 -537
  108. data/docs/class_list.html +0 -51
  109. data/docs/css/common.css +0 -1
  110. data/docs/css/full_list.css +0 -58
  111. data/docs/css/style.css +0 -496
  112. data/docs/file.COPYING.html +0 -81
  113. data/docs/file.MIT-LICENSE.html +0 -85
  114. data/docs/file.README.html +0 -418
  115. data/docs/file.RELEASE.html +0 -875
  116. data/docs/file_list.html +0 -71
  117. data/docs/frames.html +0 -17
  118. data/docs/index.html +0 -418
  119. data/docs/js/app.js +0 -292
  120. data/docs/js/full_list.js +0 -216
  121. data/docs/js/jquery.js +0 -4
  122. data/docs/method_list.html +0 -571
  123. data/docs/top-level-namespace.html +0 -118
  124. data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
  125. data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
  126. data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
  127. data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
  128. data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
  129. data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
  130. data/gemfiles/Gemfile.minitest.2.11.0 +0 -7
  131. data/gemfiles/Gemfile.minitest.2.11.2 +0 -7
  132. data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
  133. data/gemfiles/Gemfile.test-unit.2.0.0 +0 -7
  134. data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
  135. data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
  136. data/lib/mocha/class_method.rb +0 -113
  137. data/lib/mocha/mini_test.rb +0 -5
  138. data/lib/mocha/module_method.rb +0 -6
  139. data/lib/mocha/module_methods.rb +0 -10
  140. data/lib/mocha/multiple_yields.rb +0 -15
  141. data/lib/mocha/no_yields.rb +0 -5
  142. data/lib/mocha/parameter_matchers/object.rb +0 -15
  143. data/lib/mocha/pretty_parameters.rb +0 -24
  144. data/lib/mocha/single_yield.rb +0 -13
  145. data/lib/mocha/standalone.rb +0 -4
  146. data/lib/mocha/unexpected_invocation.rb +0 -24
  147. data/lib/mocha_standalone.rb +0 -4
  148. data/test/acceptance/acceptance_test_helper.rb +0 -35
  149. data/test/acceptance/bug_18914_test.rb +0 -38
  150. data/test/acceptance/bug_21465_test.rb +0 -32
  151. data/test/acceptance/bug_21563_test.rb +0 -23
  152. data/test/acceptance/exception_rescue_test.rb +0 -54
  153. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -56
  154. data/test/acceptance/expected_invocation_count_test.rb +0 -230
  155. data/test/acceptance/failure_messages_test.rb +0 -62
  156. data/test/acceptance/issue_272_test.rb +0 -51
  157. data/test/acceptance/issue_65_test.rb +0 -65
  158. data/test/acceptance/issue_70_test.rb +0 -54
  159. data/test/acceptance/mocha_example_test.rb +0 -97
  160. data/test/acceptance/mocha_test_result_test.rb +0 -84
  161. data/test/acceptance/mock_test.rb +0 -98
  162. data/test/acceptance/mock_with_initializer_block_test.rb +0 -56
  163. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -76
  164. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -67
  165. data/test/acceptance/optional_parameters_test.rb +0 -68
  166. data/test/acceptance/parameter_matcher_test.rb +0 -300
  167. data/test/acceptance/partial_mocks_test.rb +0 -45
  168. data/test/acceptance/prepend_test.rb +0 -87
  169. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -77
  170. data/test/acceptance/raise_exception_test.rb +0 -37
  171. data/test/acceptance/return_value_test.rb +0 -50
  172. data/test/acceptance/sequence_test.rb +0 -190
  173. data/test/acceptance/states_test.rb +0 -72
  174. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -65
  175. data/test/acceptance/stub_any_instance_method_test.rb +0 -282
  176. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -106
  177. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -79
  178. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -74
  179. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -145
  180. data/test/acceptance/stub_everything_test.rb +0 -54
  181. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -92
  182. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -68
  183. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -68
  184. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -137
  185. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -77
  186. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -76
  187. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -68
  188. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -71
  189. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -39
  190. data/test/acceptance/stub_module_method_test.rb +0 -201
  191. data/test/acceptance/stub_test.rb +0 -50
  192. data/test/acceptance/stubba_example_test.rb +0 -94
  193. data/test/acceptance/stubba_test_result_test.rb +0 -72
  194. data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
  195. data/test/acceptance/stubbing_frozen_object_test.rb +0 -89
  196. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -53
  197. data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
  198. data/test/acceptance/stubbing_nil_test.rb +0 -60
  199. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -141
  200. data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
  201. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
  202. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
  203. data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
  204. data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
  205. data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
  206. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -34
  207. data/test/acceptance/throw_test.rb +0 -43
  208. data/test/acceptance/unexpected_invocation_test.rb +0 -24
  209. data/test/acceptance/unstubbing_test.rb +0 -195
  210. data/test/assertions.rb +0 -8
  211. data/test/deprecation_disabler.rb +0 -15
  212. data/test/execution_point.rb +0 -36
  213. data/test/integration/mini_test_test.rb +0 -8
  214. data/test/integration/shared_tests.rb +0 -176
  215. data/test/integration/test_unit_test.rb +0 -8
  216. data/test/method_definer.rb +0 -22
  217. data/test/mini_test_result.rb +0 -96
  218. data/test/minitest_result.rb +0 -48
  219. data/test/simple_counter.rb +0 -11
  220. data/test/test_helper.rb +0 -58
  221. data/test/test_runner.rb +0 -56
  222. data/test/test_unit_result.rb +0 -22
  223. data/test/unit/any_instance_method_test.rb +0 -150
  224. data/test/unit/array_inspect_test.rb +0 -14
  225. data/test/unit/backtrace_filter_test.rb +0 -17
  226. data/test/unit/cardinality_test.rb +0 -54
  227. data/test/unit/central_test.rb +0 -99
  228. data/test/unit/change_state_side_effect_test.rb +0 -37
  229. data/test/unit/class_method_test.rb +0 -254
  230. data/test/unit/class_methods_test.rb +0 -69
  231. data/test/unit/configuration_test.rb +0 -37
  232. data/test/unit/date_time_inspect_test.rb +0 -19
  233. data/test/unit/exception_raiser_test.rb +0 -40
  234. data/test/unit/expectation_list_test.rb +0 -80
  235. data/test/unit/expectation_test.rb +0 -492
  236. data/test/unit/hash_inspect_test.rb +0 -14
  237. data/test/unit/hooks_test.rb +0 -35
  238. data/test/unit/in_state_ordering_constraint_test.rb +0 -39
  239. data/test/unit/method_matcher_test.rb +0 -26
  240. data/test/unit/mock_test.rb +0 -363
  241. data/test/unit/mockery_test.rb +0 -174
  242. data/test/unit/module_methods_test.rb +0 -17
  243. data/test/unit/multiple_yields_test.rb +0 -16
  244. data/test/unit/no_yields_test.rb +0 -16
  245. data/test/unit/object_inspect_test.rb +0 -58
  246. data/test/unit/object_methods_test.rb +0 -62
  247. data/test/unit/parameter_matchers/all_of_test.rb +0 -24
  248. data/test/unit/parameter_matchers/any_of_test.rb +0 -24
  249. data/test/unit/parameter_matchers/anything_test.rb +0 -19
  250. data/test/unit/parameter_matchers/equals_test.rb +0 -23
  251. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -50
  252. data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
  253. data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
  254. data/test/unit/parameter_matchers/has_key_test.rb +0 -54
  255. data/test/unit/parameter_matchers/has_value_test.rb +0 -55
  256. data/test/unit/parameter_matchers/includes_test.rb +0 -106
  257. data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
  258. data/test/unit/parameter_matchers/is_a_test.rb +0 -23
  259. data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
  260. data/test/unit/parameter_matchers/not_test.rb +0 -24
  261. data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
  262. data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
  263. data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
  264. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
  265. data/test/unit/parameters_matcher_test.rb +0 -119
  266. data/test/unit/receivers_test.rb +0 -96
  267. data/test/unit/return_values_test.rb +0 -61
  268. data/test/unit/sequence_test.rb +0 -100
  269. data/test/unit/single_return_value_test.rb +0 -12
  270. data/test/unit/single_yield_test.rb +0 -16
  271. data/test/unit/state_machine_test.rb +0 -96
  272. data/test/unit/string_inspect_test.rb +0 -9
  273. data/test/unit/thrower_test.rb +0 -18
  274. data/test/unit/yield_parameters_test.rb +0 -91
@@ -1,492 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require 'method_definer'
3
- require 'mocha/expectation'
4
- require 'mocha/sequence'
5
- require 'execution_point'
6
- require 'simple_counter'
7
-
8
- class ExpectationTest < Mocha::TestCase
9
- include Mocha
10
-
11
- def new_expectation
12
- Expectation.new(nil, :expected_method)
13
- end
14
-
15
- def test_should_match_calls_to_same_method_with_any_parameters
16
- assert new_expectation.match?(:expected_method, 1, 2, 3)
17
- end
18
-
19
- def test_should_match_calls_to_same_method_with_exactly_zero_parameters
20
- expectation = new_expectation.with
21
- assert expectation.match?(:expected_method)
22
- end
23
-
24
- def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters
25
- expectation = new_expectation.with
26
- assert !expectation.match?(:expected_method, 1, 2, 3)
27
- end
28
-
29
- def test_should_match_calls_to_same_method_with_expected_parameter_values
30
- expectation = new_expectation.with(1, 2, 3)
31
- assert expectation.match?(:expected_method, 1, 2, 3)
32
- end
33
-
34
- def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected
35
- expectation = new_expectation.with { |x, y, z| x + y == z }
36
- assert expectation.match?(:expected_method, 1, 2, 3)
37
- end
38
-
39
- def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
40
- expectation = new_expectation.with { |x, y, z| x + y == z }
41
- assert !expectation.match?(:different_method, 1, 2, 3)
42
- end
43
-
44
- def test_should_not_match_calls_to_different_methods_with_no_parameters
45
- assert !new_expectation.match?(:unexpected_method)
46
- end
47
-
48
- def test_should_not_match_calls_to_same_method_with_too_few_parameters
49
- expectation = new_expectation.with(1, 2, 3)
50
- assert !expectation.match?(:unexpected_method, 1, 2)
51
- end
52
-
53
- def test_should_not_match_calls_to_same_method_with_too_many_parameters
54
- expectation = new_expectation.with(1, 2)
55
- assert !expectation.match?(:unexpected_method, 1, 2, 3)
56
- end
57
-
58
- def test_should_not_match_calls_to_same_method_with_unexpected_parameter_values
59
- expectation = new_expectation.with(1, 2, 3)
60
- assert !expectation.match?(:unexpected_method, 1, 0, 3)
61
- end
62
-
63
- def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected
64
- expectation = new_expectation.with { |x, y, z| x + y == z }
65
- assert !expectation.match?(:expected_method, 1, 0, 3)
66
- end
67
-
68
- def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two
69
- expectation = new_expectation.times(1)
70
- assert expectation.invocations_allowed?
71
- expectation.invoke
72
- assert !expectation.invocations_allowed?
73
- end
74
-
75
- def test_should_allow_invocations_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three
76
- expectation = new_expectation.times(2)
77
- assert expectation.invocations_allowed?
78
- expectation.invoke
79
- assert expectation.invocations_allowed?
80
- expectation.invoke
81
- assert !expectation.invocations_allowed?
82
- end
83
-
84
- def test_should_allow_invocations_until_expected_invocation_count_is_a_range_from_two_to_three_and_actual_invocation_count_would_be_four
85
- expectation = new_expectation.times(2..3)
86
- assert expectation.invocations_allowed?
87
- expectation.invoke
88
- assert expectation.invocations_allowed?
89
- expectation.invoke
90
- assert expectation.invocations_allowed?
91
- expectation.invoke
92
- assert !expectation.invocations_allowed?
93
- end
94
-
95
- def test_should_store_provided_backtrace
96
- backtrace = Object.new
97
- expectation = Expectation.new(nil, :expected_method, backtrace)
98
- assert_equal backtrace, expectation.backtrace
99
- end
100
-
101
- # rubocop:disable Style/Semicolon
102
- def test_should_default_backtrace_to_caller
103
- execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
104
- assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
105
- end
106
- # rubocop:enable Style/Semicolon
107
-
108
- def test_should_not_yield
109
- yielded = false
110
- new_expectation.invoke { yielded = true }
111
- assert_equal false, yielded
112
- end
113
-
114
- def test_should_yield_no_parameters
115
- expectation = new_expectation.yields
116
- yielded_parameters = nil
117
- expectation.invoke { |*parameters| yielded_parameters = parameters }
118
- assert_equal [], yielded_parameters
119
- end
120
-
121
- def test_should_yield_with_specified_parameters
122
- expectation = new_expectation.yields(1, 2, 3)
123
- yielded_parameters = nil
124
- expectation.invoke { |*parameters| yielded_parameters = parameters }
125
- assert_equal [1, 2, 3], yielded_parameters
126
- end
127
-
128
- def test_should_yield_different_parameters_on_consecutive_invocations
129
- expectation = new_expectation.yields(1, 2, 3).yields(4, 5)
130
- yielded_parameters = []
131
- expectation.invoke { |*parameters| yielded_parameters << parameters }
132
- expectation.invoke { |*parameters| yielded_parameters << parameters }
133
- assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
134
- end
135
-
136
- def test_should_yield_multiple_times_for_single_invocation
137
- expectation = new_expectation.multiple_yields([1, 2, 3], [4, 5])
138
- yielded_parameters = []
139
- expectation.invoke { |*parameters| yielded_parameters << parameters }
140
- assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
141
- end
142
-
143
- def test_should_yield_multiple_times_for_first_invocation_and_once_for_second_invocation
144
- expectation = new_expectation.multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7)
145
- yielded_parameters = []
146
- expectation.invoke { |*parameters| yielded_parameters << parameters }
147
- expectation.invoke { |*parameters| yielded_parameters << parameters }
148
- assert_equal [[1, 2, 3], [4, 5], [6, 7]], yielded_parameters
149
- end
150
-
151
- def test_should_return_specified_value
152
- expectation = new_expectation.returns(99)
153
- assert_equal 99, expectation.invoke
154
- end
155
-
156
- def test_should_return_same_specified_value_multiple_times
157
- expectation = new_expectation.returns(99)
158
- assert_equal 99, expectation.invoke
159
- assert_equal 99, expectation.invoke
160
- end
161
-
162
- def test_should_return_specified_values_on_consecutive_calls
163
- expectation = new_expectation.returns(99, 100, 101)
164
- assert_equal 99, expectation.invoke
165
- assert_equal 100, expectation.invoke
166
- assert_equal 101, expectation.invoke
167
- end
168
-
169
- def test_should_return_specified_values_on_consecutive_calls_even_if_values_are_modified
170
- values = [99, 100, 101]
171
- expectation = new_expectation.returns(*values)
172
- values.shift
173
- assert_equal 99, expectation.invoke
174
- assert_equal 100, expectation.invoke
175
- assert_equal 101, expectation.invoke
176
- end
177
-
178
- def test_should_return_nil_by_default
179
- assert_nil new_expectation.invoke
180
- end
181
-
182
- def test_should_return_nil_if_no_value_specified
183
- expectation = new_expectation.returns
184
- assert_nil expectation.invoke
185
- end
186
-
187
- def test_should_raise_runtime_exception
188
- expectation = new_expectation.raises
189
- assert_raise(RuntimeError) { expectation.invoke }
190
- end
191
-
192
- def test_should_raise_custom_exception
193
- exception = Class.new(Exception)
194
- expectation = new_expectation.raises(exception)
195
- assert_raise(exception) { expectation.invoke }
196
- end
197
-
198
- def test_should_raise_same_instance_of_custom_exception
199
- exception_klass = Class.new(StandardError)
200
- expected_exception = exception_klass.new
201
- expectation = new_expectation.raises(expected_exception)
202
- actual_exception = assert_raise(exception_klass) { expectation.invoke }
203
- assert_same expected_exception, actual_exception
204
- end
205
-
206
- def test_should_use_the_default_exception_message
207
- expectation = new_expectation.raises(Exception)
208
- exception = assert_raise(Exception) { expectation.invoke }
209
- assert_equal Exception.new.message, exception.message
210
- end
211
-
212
- def test_should_raise_custom_exception_with_message
213
- exception_msg = 'exception message'
214
- expectation = new_expectation.raises(Exception, exception_msg)
215
- exception = assert_raise(Exception) { expectation.invoke }
216
- assert_equal exception_msg, exception.message
217
- end
218
-
219
- def test_should_return_values_then_raise_exception
220
- expectation = new_expectation.returns(1, 2).then.raises
221
- assert_equal 1, expectation.invoke
222
- assert_equal 2, expectation.invoke
223
- assert_raise(RuntimeError) { expectation.invoke }
224
- end
225
-
226
- def test_should_raise_exception_then_return_values
227
- expectation = new_expectation.raises.then.returns(1, 2)
228
- assert_raise(RuntimeError) { expectation.invoke }
229
- assert_equal 1, expectation.invoke
230
- assert_equal 2, expectation.invoke
231
- end
232
-
233
- def test_should_verify_successfully_if_expected_call_was_made
234
- expectation = new_expectation
235
- expectation.invoke
236
- assert expectation.verified?
237
- end
238
-
239
- def test_should_not_verify_successfully_if_call_expected_once_but_invoked_twice
240
- expectation = new_expectation.once
241
- expectation.invoke
242
- expectation.invoke
243
- assert !expectation.verified?
244
- end
245
-
246
- def test_should_not_verify_successfully_if_call_expected_once_but_not_invoked
247
- expectation = new_expectation.once
248
- assert !expectation.verified?
249
- end
250
-
251
- def test_should_verify_successfully_if_call_expected_once_and_invoked_once
252
- expectation = new_expectation.once
253
- expectation.invoke
254
- assert expectation.verified?
255
- end
256
-
257
- def test_should_not_verify_successfully_if_call_expected_twice_and_invoked_three_times
258
- expectation = new_expectation.twice
259
- expectation.invoke
260
- expectation.invoke
261
- expectation.invoke
262
- assert !expectation.verified?
263
- end
264
-
265
- def test_should_not_verify_successfully_if_call_expected_twice_but_invoked_once
266
- expectation = new_expectation.twice
267
- expectation.invoke
268
- assert !expectation.verified?
269
- end
270
-
271
- def test_should_verify_successfully_if_call_expected_twice_and_invoked_twice
272
- expectation = new_expectation.twice
273
- expectation.invoke
274
- expectation.invoke
275
- assert expectation.verified?
276
- end
277
-
278
- def test_should_verify_successfully_if_expected_call_was_made_at_least_once
279
- expectation = new_expectation.at_least_once
280
- 3.times { expectation.invoke }
281
- assert expectation.verified?
282
- end
283
-
284
- def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once
285
- expectation = new_expectation.with(1, 2, 3).at_least_once
286
- assert !expectation.verified?
287
- assert_match(/expected at least once, not yet invoked/i, expectation.mocha_inspect)
288
- end
289
-
290
- def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times
291
- expectation = new_expectation.times(2)
292
- 2.times { expectation.invoke }
293
- assert expectation.verified?
294
- end
295
-
296
- def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times
297
- expectation = new_expectation.times(2)
298
- 1.times { expectation.invoke }
299
- assert !expectation.verified?
300
- assert_match(/expected exactly twice, invoked once/i, expectation.mocha_inspect)
301
- end
302
-
303
- def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times
304
- expectation = new_expectation.times(2)
305
- 3.times { expectation.invoke }
306
- assert !expectation.verified?
307
- end
308
-
309
- def test_should_increment_assertion_counter_for_expectation_because_it_does_need_verifyng
310
- expectation = new_expectation
311
- expectation.invoke
312
- assertion_counter = SimpleCounter.new
313
- expectation.verified?(assertion_counter)
314
- assert_equal 1, assertion_counter.count
315
- end
316
-
317
- def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_need_verifying
318
- stub = Expectation.new(nil, :expected_method).at_least(0)
319
- assertion_counter = SimpleCounter.new
320
- stub.verified?(assertion_counter)
321
- assert_equal 0, assertion_counter.count
322
- end
323
-
324
- # rubocop:disable Style/Semicolon
325
- def test_should_store_backtrace_from_point_where_expectation_was_created
326
- execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
327
- assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
328
- end
329
- # rubocop:enable Style/Semicolon
330
-
331
- class FakeMock
332
- def initialize(name)
333
- @name = name
334
- end
335
-
336
- def mocha_inspect
337
- @name
338
- end
339
- end
340
-
341
- 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
342
- mock = FakeMock.new('mock')
343
- sequence_one = Sequence.new('one')
344
- sequence_two = Sequence.new('two')
345
- expectation = Expectation.new(mock, :expected_method).with(1, 2, { 'a' => true }, { :b => false }, [1, 2, 3]).in_sequence(sequence_one, sequence_two)
346
- assert !expectation.verified?
347
- assert_match %{mock.expected_method(1, 2, {"a" => true}, {:b => false}, [1, 2, 3]); in sequence "one"; in sequence "two"}, expectation.mocha_inspect
348
- end
349
-
350
- class FakeConstraint
351
- def initialize(allows_invocation_now)
352
- @allows_invocation_now = allows_invocation_now
353
- end
354
-
355
- def allows_invocation_now?
356
- @allows_invocation_now
357
- end
358
- end
359
-
360
- def test_should_be_in_correct_order_if_all_ordering_constraints_allow_invocation_now
361
- constraint_one = FakeConstraint.new(true)
362
- constraint_two = FakeConstraint.new(true)
363
- expectation = Expectation.new(nil, :method_one)
364
- expectation.add_ordering_constraint(constraint_one)
365
- expectation.add_ordering_constraint(constraint_two)
366
- assert expectation.in_correct_order?
367
- end
368
-
369
- def test_should_not_be_in_correct_order_if_one_ordering_constraint_does_not_allow_invocation_now
370
- constraint_one = FakeConstraint.new(true)
371
- constraint_two = FakeConstraint.new(false)
372
- expectation = Expectation.new(nil, :method_one)
373
- expectation.add_ordering_constraint(constraint_one)
374
- expectation.add_ordering_constraint(constraint_two)
375
- assert !expectation.in_correct_order?
376
- end
377
-
378
- def test_should_match_if_all_ordering_constraints_allow_invocation_now
379
- constraint_one = FakeConstraint.new(true)
380
- constraint_two = FakeConstraint.new(true)
381
- expectation = Expectation.new(nil, :method_one)
382
- expectation.add_ordering_constraint(constraint_one)
383
- expectation.add_ordering_constraint(constraint_two)
384
- assert expectation.match?(:method_one)
385
- end
386
-
387
- def test_should_not_match_if_one_ordering_constraints_does_not_allow_invocation_now
388
- constraint_one = FakeConstraint.new(true)
389
- constraint_two = FakeConstraint.new(false)
390
- expectation = Expectation.new(nil, :method_one)
391
- expectation.add_ordering_constraint(constraint_one)
392
- expectation.add_ordering_constraint(constraint_two)
393
- assert !expectation.match?(:method_one)
394
- end
395
-
396
- def test_should_not_be_satisfied_when_required_invocation_has_not_been_made
397
- expectation = Expectation.new(nil, :method_one).times(1)
398
- assert !expectation.satisfied?
399
- end
400
-
401
- def test_should_be_satisfied_when_required_invocation_has_been_made
402
- expectation = Expectation.new(nil, :method_one).times(1)
403
- expectation.invoke
404
- assert expectation.satisfied?
405
- end
406
-
407
- def test_should_not_be_satisfied_when_minimum_number_of_invocations_has_not_been_made
408
- expectation = Expectation.new(nil, :method_one).at_least(2)
409
- expectation.invoke
410
- assert !expectation.satisfied?
411
- end
412
-
413
- def test_should_be_satisfied_when_minimum_number_of_invocations_has_been_made
414
- expectation = Expectation.new(nil, :method_one).at_least(2)
415
- 2.times { expectation.invoke }
416
- assert expectation.satisfied?
417
- end
418
-
419
- class FakeSequence
420
- attr_reader :expectations
421
-
422
- def initialize
423
- @expectations = []
424
- end
425
-
426
- def constrain_as_next_in_sequence(expectation)
427
- @expectations << expectation
428
- end
429
- end
430
-
431
- def test_should_tell_sequences_to_constrain_expectation_as_next_in_sequence
432
- sequence_one = FakeSequence.new
433
- sequence_two = FakeSequence.new
434
- expectation = Expectation.new(nil, :method_one)
435
- assert_equal expectation, expectation.in_sequence(sequence_one, sequence_two)
436
- assert_equal [expectation], sequence_one.expectations
437
- assert_equal [expectation], sequence_two.expectations
438
- end
439
-
440
- class FakeState
441
- def initialize
442
- @active = false
443
- end
444
-
445
- def activate
446
- @active = true
447
- end
448
-
449
- def active?
450
- @active
451
- end
452
- end
453
-
454
- def test_should_change_state_when_expectation_is_invoked
455
- state = FakeState.new
456
- expectation = Expectation.new(nil, :method_one)
457
-
458
- expectation.then(state)
459
-
460
- expectation.invoke
461
- assert state.active?
462
- end
463
-
464
- def test_should_match_when_state_is_active
465
- state = FakeState.new
466
- expectation = Expectation.new(nil, :method_one)
467
-
468
- expectation.when(state)
469
- assert !expectation.match?(:method_one)
470
-
471
- state.activate
472
- assert expectation.match?(:method_one)
473
- end
474
-
475
- def test_should_include_default_representation_of_object_in_inspect
476
- object = Object.new
477
- class << object
478
- define_method(:inspect) { 'mock' }
479
- end
480
- expectation = Expectation.new(object, :method_one)
481
- assert_match Regexp.new('^#<Expectation:0x[0-9A-Fa-f]{1,12} .* >$'), expectation.inspect
482
- end
483
-
484
- def test_should_include_output_of_mocha_inspect_in_inspect
485
- object = Object.new
486
- class << object
487
- define_method(:inspect) { 'mock' }
488
- end
489
- expectation = Expectation.new(object, :method_one)
490
- assert expectation.inspect.include?(expectation.mocha_inspect)
491
- end
492
- end
@@ -1,14 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require 'mocha/inspect'
3
-
4
- class HashInspectTest < Mocha::TestCase
5
- def test_should_keep_spacing_between_key_value
6
- hash = { :a => true }
7
- assert_equal '{:a => true}', hash.mocha_inspect
8
- end
9
-
10
- def test_should_use_mocha_inspect_on_each_item
11
- hash = { :a => 'mocha' }
12
- assert_equal %({:a => "mocha"}), hash.mocha_inspect
13
- end
14
- end
@@ -1,35 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require 'mocha/hooks'
3
- require 'mocha/mockery'
4
-
5
- class HooksTest < Mocha::TestCase
6
- # rubocop:disable Style/ClassAndModuleChildren
7
- class Mocha::Mockery
8
- class << self
9
- attr_writer :instances
10
- end
11
- end
12
- # rubocop:enable Style/ClassAndModuleChildren
13
-
14
- class FakeMockery
15
- def verify(*args); end
16
-
17
- def teardown
18
- raise 'exception within Mockery#teardown'
19
- end
20
- end
21
-
22
- def test_ensure_mockery_instance_is_reset_even_when_an_exception_is_raised_in_mockery_teardown
23
- fake_test_case = Object.new.extend(Mocha::Hooks)
24
- mockery = FakeMockery.new
25
- Mocha::Mockery.instances = [mockery]
26
-
27
- begin
28
- fake_test_case.mocha_teardown
29
- rescue StandardError
30
- nil
31
- end
32
-
33
- assert_kind_of Mocha::Mockery::Null, Mocha::Mockery.instance
34
- end
35
- end
@@ -1,39 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- require 'mocha/in_state_ordering_constraint'
4
-
5
- class InStateOrderingConstraintTest < Mocha::TestCase
6
- include Mocha
7
-
8
- class FakeStatePredicate
9
- attr_writer :active, :description
10
-
11
- def active?
12
- @active
13
- end
14
-
15
- def mocha_inspect
16
- @description
17
- end
18
- end
19
-
20
- def test_should_allow_invocation_when_state_is_active
21
- state_predicate = FakeStatePredicate.new
22
- ordering_constraint = InStateOrderingConstraint.new(state_predicate)
23
-
24
- state_predicate.active = true
25
- assert ordering_constraint.allows_invocation_now?
26
-
27
- state_predicate.active = false
28
- assert !ordering_constraint.allows_invocation_now?
29
- end
30
-
31
- def test_should_describe_itself_in_terms_of_the_state_predicates_description
32
- state_predicate = FakeStatePredicate.new
33
- ordering_constraint = InStateOrderingConstraint.new(state_predicate)
34
-
35
- state_predicate.description = 'the-state-predicate'
36
-
37
- assert_equal 'when the-state-predicate', ordering_constraint.mocha_inspect
38
- end
39
- end
@@ -1,26 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require 'mocha/method_matcher'
3
-
4
- class MethodMatcherTest < Mocha::TestCase
5
- include Mocha
6
-
7
- def test_should_match_if_actual_method_name_is_same_as_expected_method_name
8
- method_matcher = MethodMatcher.new(:method_name)
9
- assert method_matcher.match?(:method_name)
10
- end
11
-
12
- def test_should_match_if_actual_method_name_is_expected_method_name_as_string
13
- method_matcher = MethodMatcher.new(:method_name)
14
- assert method_matcher.match?('method_name')
15
- end
16
-
17
- def test_should_not_match_if_actual_method_name_is_not_same_as_expected_method_name
18
- method_matcher = MethodMatcher.new(:method_name)
19
- assert !method_matcher.match?(:different_method_name)
20
- end
21
-
22
- def test_should_describe_what_method_is_expected
23
- method_matcher = MethodMatcher.new(:method_name)
24
- assert_equal 'method_name', method_matcher.mocha_inspect
25
- end
26
- end