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,363 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require 'mocha/ruby_version'
3
- require 'mocha/mock'
4
- require 'mocha/expectation_error_factory'
5
- require 'set'
6
- require 'simple_counter'
7
-
8
- class MockTest < Mocha::TestCase
9
- include Mocha
10
-
11
- def test_should_set_single_expectation
12
- mock = build_mock
13
- mock.expects(:method1).returns(1)
14
- assert_nothing_raised(ExpectationErrorFactory.exception_class) do
15
- assert_equal 1, mock.method1
16
- end
17
- end
18
-
19
- def test_should_build_and_store_expectations
20
- mock = build_mock
21
- expectation = mock.expects(:method1)
22
- assert_not_nil expectation
23
- assert_equal [expectation], mock.__expectations__.to_a
24
- end
25
-
26
- def test_should_not_stub_everything_by_default
27
- mock = build_mock
28
- assert_equal false, mock.everything_stubbed
29
- end
30
-
31
- def test_should_stub_everything
32
- mock = build_mock
33
- mock.stub_everything
34
- assert_equal true, mock.everything_stubbed
35
- end
36
-
37
- def test_should_be_able_to_extend_mock_object_with_module
38
- mock = build_mock
39
- assert_nothing_raised(ExpectationErrorFactory.exception_class) { mock.extend(Module.new) }
40
- end
41
-
42
- def test_should_be_equal
43
- mock = build_mock
44
- assert_equal true, mock.eql?(mock)
45
- end
46
-
47
- EXCLUDED_METHODS = {
48
- true => %w[
49
- method_missing
50
- singleton_method_undefined
51
- initialize
52
- ],
53
- false => [
54
- :object_id,
55
- :method_missing,
56
- :singleton_method_undefined,
57
- :initialize,
58
- :String,
59
- :singleton_method_added
60
- ]
61
- }.freeze
62
-
63
- OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject do |m|
64
- m =~ /^__.*__$/ || EXCLUDED_METHODS[PRE_RUBY_V19].include?(m)
65
- end
66
-
67
- def test_should_be_able_to_mock_standard_object_methods
68
- mock = build_mock
69
- OBJECT_METHODS.each { |method| mock.__expects__(method.to_sym).returns(method) }
70
- OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) }
71
- assert mock.__verified__?
72
- end
73
-
74
- def test_should_be_able_to_stub_standard_object_methods
75
- mock = build_mock
76
- OBJECT_METHODS.each { |method| mock.__stubs__(method.to_sym).returns(method) }
77
- OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) }
78
- end
79
-
80
- def test_should_create_and_add_expectations
81
- mock = build_mock
82
- expectation1 = mock.expects(:method1)
83
- expectation2 = mock.expects(:method2)
84
- assert_equal [expectation1, expectation2].to_set, mock.__expectations__.to_set
85
- end
86
-
87
- def test_should_pass_backtrace_into_expectation
88
- mock = build_mock
89
- backtrace = Object.new
90
- expectation = mock.expects(:method1, backtrace)
91
- assert_equal backtrace, expectation.backtrace
92
- end
93
-
94
- def test_should_pass_backtrace_into_stub
95
- mock = build_mock
96
- backtrace = Object.new
97
- stub = mock.stubs(:method1, backtrace)
98
- assert_equal backtrace, stub.backtrace
99
- end
100
-
101
- def test_should_create_and_add_stubs
102
- mock = build_mock
103
- stub1 = mock.stubs(:method1)
104
- stub2 = mock.stubs(:method2)
105
- assert_equal [stub1, stub2].to_set, mock.__expectations__.to_set
106
- end
107
-
108
- def test_should_invoke_expectation_and_return_result
109
- mock = build_mock
110
- mock.expects(:my_method).returns(:result)
111
- result = mock.my_method
112
- assert_equal :result, result
113
- end
114
-
115
- def test_should_not_raise_error_if_stubbing_everything
116
- mock = build_mock
117
- mock.stub_everything
118
- result = nil
119
- assert_nothing_raised(ExpectationErrorFactory.exception_class) do
120
- result = mock.unexpected_method
121
- end
122
- assert_nil result
123
- end
124
-
125
- def test_should_raise_assertion_error_for_unexpected_method_call
126
- mock = build_mock
127
- error = assert_raise(ExpectationErrorFactory.exception_class) do
128
- mock.unexpected_method_called(:my_method, :argument1, :argument2)
129
- end
130
- assert_match(/unexpected invocation/, error.message)
131
- assert_match(/my_method/, error.message)
132
- assert_match(/argument1/, error.message)
133
- assert_match(/argument2/, error.message)
134
- end
135
-
136
- def test_should_not_verify_successfully_because_not_all_expectations_have_been_satisfied
137
- mock = build_mock
138
- mock.expects(:method1)
139
- mock.expects(:method2)
140
- mock.method1
141
- assert !mock.__verified__?
142
- end
143
-
144
- def test_should_increment_assertion_counter_for_every_verified_expectation
145
- mock = build_mock
146
-
147
- mock.expects(:method1)
148
- mock.method1
149
-
150
- mock.expects(:method2)
151
- mock.method2
152
-
153
- assertion_counter = SimpleCounter.new
154
-
155
- mock.__verified__?(assertion_counter)
156
-
157
- assert_equal 2, assertion_counter.count
158
- end
159
-
160
- def test_should_yield_supplied_parameters_to_block
161
- mock = build_mock
162
- parameters_for_yield = [1, 2, 3]
163
- mock.expects(:method1).yields(*parameters_for_yield)
164
- yielded_parameters = nil
165
- mock.method1 { |*parameters| yielded_parameters = parameters }
166
- assert_equal parameters_for_yield, yielded_parameters
167
- end
168
-
169
- def test_should_set_up_multiple_expectations_with_return_values
170
- mock = build_mock
171
- mock.expects(:method1 => :result1, :method2 => :result2)
172
- assert_equal :result1, mock.method1
173
- assert_equal :result2, mock.method2
174
- end
175
-
176
- def test_should_set_up_multiple_stubs_with_return_values
177
- mock = build_mock
178
- mock.stubs(:method1 => :result1, :method2 => :result2)
179
- assert_equal :result1, mock.method1
180
- assert_equal :result2, mock.method2
181
- end
182
-
183
- def test_should_keep_returning_specified_value_for_stubs
184
- mock = build_mock
185
- mock.stubs(:method1).returns(1)
186
- assert_equal 1, mock.method1
187
- assert_equal 1, mock.method1
188
- end
189
-
190
- def test_should_keep_returning_specified_value_for_expects
191
- mock = build_mock
192
- mock.expects(:method1).times(2).returns(1)
193
- assert_equal 1, mock.method1
194
- assert_equal 1, mock.method1
195
- end
196
-
197
- def test_should_match_most_recent_call_to_expects
198
- mock = build_mock
199
- mock.expects(:method1).returns(0)
200
- mock.expects(:method1).returns(1)
201
- assert_equal 1, mock.method1
202
- end
203
-
204
- def test_should_match_most_recent_call_to_stubs
205
- mock = build_mock
206
- mock.stubs(:method1).returns(0)
207
- mock.stubs(:method1).returns(1)
208
- assert_equal 1, mock.method1
209
- end
210
-
211
- def test_should_match_most_recent_call_to_stubs_or_expects
212
- mock = build_mock
213
- mock.stubs(:method1).returns(0)
214
- mock.expects(:method1).returns(1)
215
- assert_equal 1, mock.method1
216
- end
217
-
218
- def test_should_match_most_recent_call_to_expects_or_stubs
219
- mock = build_mock
220
- mock.expects(:method1).returns(0)
221
- mock.stubs(:method1).returns(1)
222
- assert_equal 1, mock.method1
223
- end
224
-
225
- def test_should_respond_to_expected_method
226
- mock = build_mock
227
- mock.expects(:method1)
228
- assert_equal true, mock.respond_to?(:method1)
229
- end
230
-
231
- def test_should_respond_to_expected_method_as_string
232
- mock = build_mock
233
- mock.expects(:method1)
234
- assert_equal true, mock.respond_to?('method1')
235
- end
236
-
237
- def test_should_not_respond_to_unexpected_method
238
- mock = build_mock
239
- assert_equal false, mock.respond_to?(:method1)
240
- end
241
-
242
- def test_should_respond_to_methods_which_the_responder_does_responds_to
243
- instance = Class.new do
244
- define_method(:respond_to?) { |_symbol| true }
245
- end.new
246
- mock = build_mock
247
- mock.responds_like(instance)
248
- assert_equal true, mock.respond_to?(:invoked_method)
249
- end
250
-
251
- def test_should_not_respond_to_methods_which_the_responder_does_not_responds_to
252
- instance = Class.new do
253
- define_method(:respond_to?) { |_symbol| false }
254
- end.new
255
- mock = build_mock
256
- mock.responds_like(instance)
257
- assert_equal false, mock.respond_to?(:invoked_method)
258
- end
259
-
260
- def test_should_respond_to_methods_which_the_responder_instance_does_responds_to
261
- klass = Class.new do
262
- define_method(:respond_to?) { |_symbol| true }
263
- end
264
- mock = build_mock
265
- mock.responds_like_instance_of(klass)
266
- assert_equal true, mock.respond_to?(:invoked_method)
267
- end
268
-
269
- def test_should_not_respond_to_methods_which_the_responder_instance_does_not_responds_to
270
- klass = Class.new do
271
- define_method(:respond_to?) { |_symbol| false }
272
- end
273
- mock = build_mock
274
- mock.responds_like_instance_of(klass)
275
- assert_equal false, mock.respond_to?(:invoked_method)
276
- end
277
-
278
- def test_respond_like_should_return_itself_to_allow_method_chaining
279
- mock = build_mock
280
- assert_same mock.responds_like(Object.new), mock
281
- end
282
-
283
- def test_respond_like_instance_of_should_return_itself_to_allow_method_chaining
284
- mock = build_mock
285
- assert_same mock.responds_like_instance_of(Object), mock
286
- end
287
-
288
- def test_should_not_raise_no_method_error_if_mock_is_not_restricted_to_respond_like_a_responder
289
- mock = build_mock
290
- mock.stubs(:invoked_method)
291
- assert_nothing_raised(NoMethodError) { mock.invoked_method }
292
- end
293
-
294
- def test_should_not_raise_no_method_error_if_responder_does_respond_to_invoked_method
295
- instance = Class.new do
296
- define_method(:respond_to?) { |_symbol| true }
297
- end.new
298
- mock = build_mock
299
- mock.responds_like(instance)
300
- mock.stubs(:invoked_method)
301
- assert_nothing_raised(NoMethodError) { mock.invoked_method }
302
- end
303
-
304
- def test_should_raise_no_method_error_if_responder_does_not_respond_to_invoked_method
305
- instance = Class.new do
306
- define_method(:respond_to?) { |_symbol| false }
307
- define_method(:mocha_inspect) { 'mocha_inspect' }
308
- end.new
309
- mock = build_mock
310
- mock.responds_like(instance)
311
- mock.stubs(:invoked_method)
312
- assert_raises(NoMethodError) { mock.invoked_method }
313
- end
314
-
315
- def test_should_raise_no_method_error_with_message_indicating_that_mock_is_constrained_to_respond_like_responder
316
- instance = Class.new do
317
- define_method(:respond_to?) { |_symbol| false }
318
- define_method(:mocha_inspect) { 'mocha_inspect' }
319
- end.new
320
- mock = build_mock
321
- mock.responds_like(instance)
322
- mock.stubs(:invoked_method)
323
- begin
324
- mock.invoked_method
325
- rescue NoMethodError => e
326
- assert_match(/which responds like mocha_inspect/, e.message)
327
- end
328
- end
329
-
330
- def test_should_handle_respond_to_with_private_methods_param_without_error
331
- mock = build_mock
332
- assert_nothing_raised { mock.respond_to?(:object_id, false) }
333
- end
334
-
335
- def test_should_respond_to_any_method_if_stubbing_everything
336
- mock = build_mock
337
- mock.stub_everything
338
- assert mock.respond_to?(:abc)
339
- assert mock.respond_to?(:xyz)
340
- end
341
-
342
- def test_should_remove_expectation_for_unstubbed_method
343
- mock = build_mock
344
- mock.expects(:method1)
345
- mock.unstub(:method1)
346
- e = assert_raises(ExpectationErrorFactory.exception_class) { mock.method1 }
347
- assert_match(/unexpected invocation/, e.message)
348
- end
349
-
350
- unless PRE_RUBY_V19
351
- def test_expectation_is_defined_on_mock
352
- mock = build_mock
353
- mock.expects(:method1)
354
- assert defined? mock.method1
355
- end
356
- end
357
-
358
- private
359
-
360
- def build_mock
361
- Mock.new(nil)
362
- end
363
- end
@@ -1,174 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require 'mocha/mockery'
3
- require 'mocha/state_machine'
4
- require 'mocha/expectation_error_factory'
5
- require 'deprecation_disabler'
6
-
7
- class MockeryTest < Mocha::TestCase
8
- include Mocha
9
- include DeprecationDisabler
10
-
11
- def setup
12
- Mockery.setup
13
- end
14
-
15
- def teardown
16
- Mockery.teardown
17
- end
18
-
19
- def test_should_return_null_mockery_if_not_setup
20
- Mockery.teardown
21
- mockery = Mockery.instance
22
- assert_not_nil mockery
23
- assert_kind_of Mockery::Null, mockery
24
- end
25
-
26
- def test_should_return_instance_of_mockery
27
- mockery = Mockery.instance
28
- assert_not_nil mockery
29
- assert_kind_of Mockery, mockery
30
- end
31
-
32
- def test_should_cache_instance_of_mockery
33
- mockery1 = Mockery.instance
34
- mockery2 = Mockery.instance
35
- assert_same mockery1, mockery2
36
- end
37
-
38
- def test_should_expire_mockery_instance_cache
39
- mockery1 = Mockery.instance
40
- Mockery.teardown
41
- mockery2 = Mockery.instance
42
- assert_not_same mockery1, mockery2
43
- end
44
-
45
- def test_should_raise_expectation_error_because_not_all_expectations_are_satisfied
46
- mockery = Mockery.new
47
- disable_deprecations do
48
- mock1 = mockery.named_mock('mock-1') { expects(:method_1) }
49
- mock2 = mockery.named_mock('mock-2') { expects(:method_2) }
50
- 1.times { mock1.method_1 }
51
- 0.times { mock2.method_2 }
52
- end
53
- assert_raises(ExpectationErrorFactory.exception_class) { mockery.verify }
54
- end
55
-
56
- def test_should_reset_list_of_mocks_on_teardown
57
- mockery = Mockery.new
58
- disable_deprecations do
59
- mockery.unnamed_mock { expects(:my_method) }
60
- end
61
- mockery.teardown
62
- assert_nothing_raised(ExpectationErrorFactory.exception_class) { mockery.verify }
63
- end
64
-
65
- def test_should_build_instance_of_stubba_on_instantiation
66
- mockery = Mockery.new
67
- assert_not_nil mockery.stubba
68
- assert_kind_of Central, mockery.stubba
69
- end
70
-
71
- def test_should_build_new_instance_of_stubba_on_teardown
72
- mockery = Mockery.new
73
- stubba1 = mockery.stubba
74
- mockery.teardown
75
- stubba2 = mockery.stubba
76
- assert_not_same stubba1, stubba2
77
- end
78
-
79
- def test_should_build_and_store_new_state_machine
80
- mockery = Mockery.new
81
- mockery.new_state_machine('state-machine-name')
82
- assert_equal 1, mockery.state_machines.length
83
- assert_kind_of StateMachine, mockery.state_machines[0]
84
- end
85
-
86
- def test_should_reset_list_of_state_machines_on_teardown
87
- mockery = Mockery.new
88
- mockery.new_state_machine('state-machine-name')
89
- mockery.teardown
90
- assert_equal 0, mockery.state_machines.length
91
- end
92
-
93
- class FakeMethod
94
- def stub; end
95
-
96
- def unstub; end
97
-
98
- def matches?(_other)
99
- true
100
- end
101
- end
102
-
103
- def test_should_unstub_all_methods_on_teardown
104
- mockery = Mockery.new
105
- stubba = mockery.stubba
106
- stubba.stub(FakeMethod.new)
107
- mockery.teardown
108
- assert stubba.stubba_methods.empty?
109
- end
110
-
111
- def test_should_display_object_id_for_mocha_inspect_if_mock_has_no_name
112
- mockery = Mockery.new
113
- mock = mockery.unnamed_mock
114
- assert_match Regexp.new('^#<Mock:0x[0-9A-Fa-f]{1,12}>$'), mock.mocha_inspect
115
- end
116
-
117
- def test_should_display_object_id_for_inspect_if_mock_has_no_name
118
- mockery = Mockery.new
119
- mock = mockery.unnamed_mock
120
- assert_match Regexp.new('^#<Mock:0x[0-9A-Fa-f]{1,12}>$'), mock.inspect
121
- end
122
-
123
- def test_should_display_name_for_mocha_inspect_if_mock_has_string_name
124
- mockery = Mockery.new
125
- mock = mockery.named_mock('named_mock')
126
- assert_equal '#<Mock:named_mock>', mock.mocha_inspect
127
- end
128
-
129
- def test_should_display_name_for_mocha_inspect_if_mock_has_symbol_name
130
- mockery = Mockery.new
131
- mock = mockery.named_mock(:named_mock)
132
- assert_equal '#<Mock:named_mock>', mock.mocha_inspect
133
- end
134
-
135
- def test_should_display_name_for_inspect_if_mock_has_string_name
136
- mockery = Mockery.new
137
- mock = mockery.named_mock('named_mock')
138
- assert_equal '#<Mock:named_mock>', mock.inspect
139
- end
140
-
141
- def test_should_display_name_for_inspect_if_mock_has_symbol_name
142
- mockery = Mockery.new
143
- mock = mockery.named_mock(:named_mock)
144
- assert_equal '#<Mock:named_mock>', mock.inspect
145
- end
146
-
147
- def test_should_display_impersonated_object_for_mocha_inspect
148
- mockery = Mockery.new
149
- instance = Object.new
150
- mock = mockery.mock_impersonating(instance)
151
- assert_equal instance.mocha_inspect.to_s, mock.mocha_inspect
152
- end
153
-
154
- def test_should_display_impersonated_object_for_inspect
155
- mockery = Mockery.new
156
- instance = Object.new
157
- mock = mockery.mock_impersonating(instance)
158
- assert_equal instance.mocha_inspect.to_s, mock.inspect
159
- end
160
-
161
- class FakeClass; end
162
-
163
- def test_should_display_any_instance_prefix_followed_by_class_whose_instances_are_being_impersonated_for_mocha_inspect
164
- mockery = Mockery.new
165
- mock = mockery.mock_impersonating_any_instance_of(FakeClass)
166
- assert_equal '#<AnyInstance:MockeryTest::FakeClass>', mock.mocha_inspect
167
- end
168
-
169
- def test_should_display_any_instance_prefix_followed_by_class_whose_instances_are_being_impersonated_for_inspect
170
- mockery = Mockery.new
171
- mock = mockery.mock_impersonating_any_instance_of(FakeClass)
172
- assert_equal '#<AnyInstance:MockeryTest::FakeClass>', mock.inspect
173
- end
174
- end
@@ -1,17 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require 'mocha/module_methods'
3
- require 'mocha/object_methods'
4
-
5
- class ModuleMethodsTest < Mocha::TestCase
6
- def setup
7
- @module = Module.new.extend(Mocha::ModuleMethods, Mocha::ObjectMethods)
8
- end
9
-
10
- def test_should_use_stubba_module_method_for_module
11
- assert_equal Mocha::ModuleMethod, @module.stubba_method
12
- end
13
-
14
- def test_should_stub_self_for_module
15
- assert_equal @module, @module.stubba_object
16
- end
17
- end
@@ -1,16 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- require 'mocha/multiple_yields'
4
-
5
- class MultipleYieldsTest < Mocha::TestCase
6
- include Mocha
7
-
8
- def test_should_provide_parameters_for_multiple_yields_in_single_invocation
9
- parameter_group = MultipleYields.new([1, 2, 3], [4, 5])
10
- parameter_groups = []
11
- parameter_group.each do |parameters|
12
- parameter_groups << parameters
13
- end
14
- assert_equal [[1, 2, 3], [4, 5]], parameter_groups
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- require 'mocha/no_yields'
4
-
5
- class NoYieldsTest < Mocha::TestCase
6
- include Mocha
7
-
8
- def test_should_provide_parameters_for_no_yields_in_single_invocation
9
- parameter_group = NoYields.new
10
- parameter_groups = []
11
- parameter_group.each do |parameters|
12
- parameter_groups << parameters
13
- end
14
- assert_equal [], parameter_groups
15
- end
16
- end
@@ -1,58 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require 'mocha/ruby_version'
3
- require 'mocha/inspect'
4
- require 'method_definer'
5
-
6
- class ObjectInspectTest < Mocha::TestCase
7
- def test_should_return_default_string_representation_of_object_not_including_instance_variables
8
- object = Object.new
9
- class << object
10
- attr_accessor :attribute
11
- end
12
- object.attribute = 'instance_variable'
13
- assert_match Regexp.new('^#<Object:0x[0-9A-Fa-f]{1,8}.*>$'), object.mocha_inspect
14
- assert_no_match(/instance_variable/, object.mocha_inspect)
15
- end
16
-
17
- def test_should_return_customized_string_representation_of_object
18
- object = Object.new
19
- class << object
20
- define_method(:inspect) { 'custom_inspect' }
21
- end
22
- assert_equal 'custom_inspect', object.mocha_inspect
23
- end
24
-
25
- def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed
26
- calls = []
27
- object = Object.new
28
- if Mocha::PRE_RUBY_V19
29
- object.replace_instance_method(:id) do
30
- calls << :id
31
- return 1
32
- end
33
- end
34
- object.replace_instance_method(:object_id) do
35
- calls << :object_id
36
- return 1
37
- end
38
- object.replace_instance_method(:__id__) do
39
- calls << :__id__
40
- return 1
41
- end
42
- object.replace_instance_method(:inspect) { 'object-description' }
43
-
44
- object.mocha_inspect
45
-
46
- assert_equal [:__id__], calls.uniq
47
- end
48
-
49
- def test_should_not_call_object_instance_format_method
50
- object = Object.new
51
- class << object
52
- def format(*)
53
- 'internal_format'
54
- end
55
- end
56
- assert_no_match(/internal_format/, object.mocha_inspect)
57
- end
58
- end
@@ -1,62 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require 'mocha/object_methods'
3
- require 'mocha/mockery'
4
- require 'mocha/mock'
5
- require 'mocha/expectation_error_factory'
6
- require 'mocha/names'
7
-
8
- class ObjectMethodsTest < Mocha::TestCase
9
- def setup
10
- Mocha::Mockery.setup
11
- @object = Object.new.extend(Mocha::ObjectMethods)
12
- end
13
-
14
- def teardown
15
- Mocha::Mockery.teardown
16
- end
17
-
18
- def test_should_build_mocha_referring_to_self
19
- mocha = @object.mocha
20
- assert_not_nil mocha
21
- assert mocha.is_a?(Mocha::Mock)
22
- expected_name = Mocha::ImpersonatingName.new(@object).mocha_inspect
23
- assert_equal expected_name, mocha.mocha_inspect
24
- end
25
-
26
- def test_should_not_build_mocha_if_instantiate_is_false
27
- assert_nil @object.mocha(false)
28
- end
29
-
30
- def test_should_reuse_existing_mocha
31
- mocha1 = @object.mocha
32
- mocha2 = @object.mocha
33
- assert_equal mocha1, mocha2
34
- end
35
-
36
- def test_should_reuse_existing_mocha_even_if_instantiate_is_false
37
- mocha1 = @object.mocha
38
- mocha2 = @object.mocha(false)
39
- assert_equal mocha1, mocha2
40
- end
41
-
42
- def test_should_reset_mocha
43
- assert_nil @object.reset_mocha
44
- end
45
-
46
- def test_should_use_stubba_instance_method_for_object
47
- assert_equal Mocha::InstanceMethod, Object.new.stubba_method
48
- end
49
-
50
- def test_should_stub_self_for_object
51
- assert_equal @object, @object.stubba_object
52
- end
53
-
54
- def test_nobody_expects_the_spanish_inquisition
55
- assert_raise(Mocha::ExpectationErrorFactory.exception_class) { @object.expects(:the_spanish_inquisition) }
56
- end
57
-
58
- def test_should_alias_object_method
59
- klass = Class.new { def self.method_x; end }
60
- assert_equal klass._method(:method_x), klass.method(:method_x)
61
- end
62
- end