mocha 1.8.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) 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/README.md +40 -13
  7. data/RELEASE.md +97 -0
  8. data/Rakefile +10 -7
  9. data/bin/build-matrix +1 -2
  10. data/docs/CNAME +1 -1
  11. data/docs/Mocha.html +132 -5
  12. data/docs/Mocha/API.html +437 -206
  13. data/docs/Mocha/ClassMethods.html +13 -16
  14. data/docs/Mocha/Configuration.html +1126 -227
  15. data/docs/Mocha/Expectation.html +420 -267
  16. data/docs/Mocha/ExpectationError.html +5 -10
  17. data/docs/Mocha/ExpectationErrorFactory.html +9 -18
  18. data/docs/Mocha/Hooks.html +12 -27
  19. data/docs/Mocha/Integration.html +3 -3
  20. data/docs/Mocha/Integration/MiniTest.html +3 -3
  21. data/docs/Mocha/Integration/MiniTest/Adapter.html +5 -6
  22. data/docs/Mocha/Integration/TestUnit.html +3 -3
  23. data/docs/Mocha/Integration/TestUnit/Adapter.html +5 -6
  24. data/docs/Mocha/Mock.html +202 -162
  25. data/docs/Mocha/ObjectMethods.html +121 -68
  26. data/docs/Mocha/ParameterMatchers.html +21 -109
  27. data/docs/Mocha/ParameterMatchers/AllOf.html +4 -5
  28. data/docs/Mocha/ParameterMatchers/AnyOf.html +4 -5
  29. data/docs/Mocha/ParameterMatchers/AnyParameters.html +3 -3
  30. data/docs/Mocha/ParameterMatchers/Anything.html +3 -3
  31. data/docs/Mocha/ParameterMatchers/Base.html +8 -15
  32. data/docs/Mocha/ParameterMatchers/Equals.html +4 -5
  33. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +3 -3
  34. data/docs/Mocha/ParameterMatchers/HasEntries.html +4 -5
  35. data/docs/Mocha/ParameterMatchers/HasEntry.html +4 -5
  36. data/docs/Mocha/ParameterMatchers/HasKey.html +4 -5
  37. data/docs/Mocha/ParameterMatchers/HasValue.html +4 -5
  38. data/docs/Mocha/ParameterMatchers/Includes.html +4 -5
  39. data/docs/Mocha/ParameterMatchers/InstanceOf.html +4 -5
  40. data/docs/Mocha/ParameterMatchers/IsA.html +3 -3
  41. data/docs/Mocha/ParameterMatchers/KindOf.html +4 -5
  42. data/docs/Mocha/ParameterMatchers/Not.html +4 -5
  43. data/docs/Mocha/ParameterMatchers/Optionally.html +3 -3
  44. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +4 -5
  45. data/docs/Mocha/ParameterMatchers/RespondsWith.html +4 -5
  46. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +4 -5
  47. data/docs/Mocha/Sequence.html +3 -3
  48. data/docs/Mocha/StateMachine.html +13 -25
  49. data/docs/Mocha/StateMachine/State.html +4 -5
  50. data/docs/Mocha/StateMachine/StatePredicate.html +4 -5
  51. data/docs/Mocha/StubbingError.html +3 -3
  52. data/docs/_index.html +4 -22
  53. data/docs/class_list.html +1 -1
  54. data/docs/file.COPYING.html +3 -3
  55. data/docs/file.MIT-LICENSE.html +3 -3
  56. data/docs/file.README.html +46 -16
  57. data/docs/file.RELEASE.html +130 -3
  58. data/docs/frames.html +1 -1
  59. data/docs/index.html +46 -16
  60. data/docs/js/app.js +11 -0
  61. data/docs/method_list.html +117 -37
  62. data/docs/top-level-namespace.html +3 -3
  63. data/gemfiles/Gemfile.minitest.5.11.3 +7 -0
  64. data/init.rb +1 -3
  65. data/lib/mocha.rb +8 -0
  66. data/lib/mocha/any_instance_method.rb +11 -53
  67. data/lib/mocha/api.rb +120 -56
  68. data/lib/mocha/block_matcher.rb +31 -0
  69. data/lib/mocha/cardinality.rb +26 -11
  70. data/lib/mocha/class_methods.rb +17 -15
  71. data/lib/mocha/configuration.rb +351 -67
  72. data/lib/mocha/deprecation.rb +2 -1
  73. data/lib/mocha/detection/test_unit.rb +1 -3
  74. data/lib/mocha/exception_raiser.rb +2 -1
  75. data/lib/mocha/expectation.rb +102 -63
  76. data/lib/mocha/expectation_error.rb +1 -3
  77. data/lib/mocha/expectation_list.rb +6 -6
  78. data/lib/mocha/inspect.rb +28 -26
  79. data/lib/mocha/instance_method.rb +19 -2
  80. data/lib/mocha/integration.rb +1 -3
  81. data/lib/mocha/integration/mini_test.rb +7 -0
  82. data/lib/mocha/integration/test_unit.rb +7 -0
  83. data/lib/mocha/invocation.rb +77 -0
  84. data/lib/mocha/macos_version.rb +5 -0
  85. data/lib/mocha/minitest.rb +6 -1
  86. data/lib/mocha/mock.rb +46 -31
  87. data/lib/mocha/mockery.rb +25 -61
  88. data/lib/mocha/names.rb +1 -1
  89. data/lib/mocha/object_methods.rb +13 -19
  90. data/lib/mocha/parameter_matchers.rb +1 -1
  91. data/lib/mocha/parameter_matchers/all_of.rb +1 -1
  92. data/lib/mocha/parameter_matchers/any_of.rb +1 -1
  93. data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -9
  94. data/lib/mocha/parameter_matchers/includes.rb +2 -0
  95. data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
  96. data/lib/mocha/raised_exception.rb +11 -0
  97. data/lib/mocha/return_values.rb +3 -3
  98. data/lib/mocha/setup.rb +5 -0
  99. data/lib/mocha/single_return_value.rb +2 -1
  100. data/lib/mocha/singleton_class.rb +9 -0
  101. data/lib/mocha/stubbed_method.rb +127 -0
  102. data/lib/mocha/test_unit.rb +6 -1
  103. data/lib/mocha/thrower.rb +2 -1
  104. data/lib/mocha/thrown_object.rb +12 -0
  105. data/lib/mocha/version.rb +1 -1
  106. data/lib/mocha/yield_parameters.rb +5 -11
  107. data/mocha.gemspec +1 -3
  108. data/test/acceptance/acceptance_test_helper.rb +7 -0
  109. data/test/acceptance/bug_18914_test.rb +0 -1
  110. data/test/acceptance/bug_21465_test.rb +0 -1
  111. data/test/acceptance/bug_21563_test.rb +0 -1
  112. data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +69 -0
  113. data/test/acceptance/exception_rescue_test.rb +1 -2
  114. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -1
  115. data/test/acceptance/expected_invocation_count_test.rb +2 -3
  116. data/test/acceptance/failure_messages_test.rb +16 -1
  117. data/test/acceptance/issue_272_test.rb +1 -2
  118. data/test/acceptance/issue_65_test.rb +0 -1
  119. data/test/acceptance/issue_70_test.rb +0 -1
  120. data/test/acceptance/mocha_example_test.rb +0 -1
  121. data/test/acceptance/mocha_test_result_test.rb +0 -1
  122. data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +99 -0
  123. data/test/acceptance/mock_test.rb +47 -6
  124. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -1
  125. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -1
  126. data/test/acceptance/multiple_yielding_test.rb +56 -0
  127. data/test/acceptance/optional_parameters_test.rb +0 -1
  128. data/test/acceptance/parameter_matcher_test.rb +0 -1
  129. data/test/acceptance/partial_mocks_test.rb +0 -1
  130. data/test/acceptance/prepend_test.rb +0 -1
  131. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -1
  132. data/test/acceptance/raise_exception_test.rb +0 -1
  133. data/test/acceptance/return_value_test.rb +0 -1
  134. data/test/acceptance/sequence_test.rb +0 -1
  135. data/test/acceptance/states_test.rb +0 -1
  136. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +1 -2
  137. data/test/acceptance/stub_any_instance_method_test.rb +20 -1
  138. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -1
  139. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -1
  140. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -1
  141. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +1 -2
  142. data/test/acceptance/stub_everything_test.rb +0 -1
  143. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -1
  144. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -1
  145. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -1
  146. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -1
  147. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -1
  148. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -1
  149. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -1
  150. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -1
  151. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -1
  152. data/test/acceptance/stub_module_method_test.rb +0 -1
  153. data/test/acceptance/stub_test.rb +0 -1
  154. data/test/acceptance/stubba_example_test.rb +0 -1
  155. data/test/acceptance/stubba_test_result_test.rb +0 -1
  156. data/test/acceptance/stubbing_error_backtrace_test.rb +4 -5
  157. data/test/acceptance/stubbing_frozen_object_test.rb +0 -1
  158. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -1
  159. data/test/acceptance/stubbing_method_unnecessarily_test.rb +5 -5
  160. data/test/acceptance/stubbing_nil_test.rb +5 -5
  161. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +27 -11
  162. data/test/acceptance/stubbing_non_existent_class_method_test.rb +11 -11
  163. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +11 -11
  164. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +8 -8
  165. data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
  166. data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
  167. data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
  168. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -1
  169. data/test/acceptance/throw_test.rb +0 -1
  170. data/test/acceptance/unexpected_invocation_test.rb +0 -1
  171. data/test/acceptance/unstubbing_test.rb +0 -1
  172. data/test/acceptance/yielding_test.rb +78 -0
  173. data/test/integration/shared_tests.rb +5 -3
  174. data/test/method_definer.rb +11 -17
  175. data/test/test_runner.rb +2 -0
  176. data/test/unit/any_instance_method_test.rb +60 -35
  177. data/test/unit/cardinality_test.rb +41 -23
  178. data/test/unit/central_test.rb +0 -1
  179. data/test/unit/class_methods_test.rb +1 -1
  180. data/test/unit/configuration_test.rb +12 -12
  181. data/test/unit/exception_raiser_test.rb +10 -5
  182. data/test/unit/expectation_list_test.rb +13 -11
  183. data/test/unit/expectation_test.rb +117 -103
  184. data/test/unit/instance_method_test.rb +282 -0
  185. data/test/unit/mock_test.rb +28 -19
  186. data/test/unit/mockery_test.rb +8 -11
  187. data/test/unit/module_methods_test.rb +2 -3
  188. data/test/unit/object_inspect_test.rb +6 -4
  189. data/test/unit/object_methods_test.rb +3 -2
  190. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -9
  191. data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
  192. data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
  193. data/test/unit/parameter_matchers/has_key_test.rb +1 -1
  194. data/test/unit/parameter_matchers/has_value_test.rb +1 -1
  195. data/test/unit/parameter_matchers/includes_test.rb +1 -1
  196. data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
  197. data/test/unit/return_values_test.rb +25 -20
  198. data/test/unit/single_return_value_test.rb +6 -1
  199. data/test/unit/thrower_test.rb +7 -2
  200. data/test/unit/yield_parameters_test.rb +35 -53
  201. metadata +18 -35
  202. data/docs/Mocha/UnexpectedInvocation.html +0 -140
  203. data/lib/mocha/class_method.rb +0 -113
  204. data/lib/mocha/mini_test.rb +0 -5
  205. data/lib/mocha/module_method.rb +0 -6
  206. data/lib/mocha/module_methods.rb +0 -10
  207. data/lib/mocha/multiple_yields.rb +0 -15
  208. data/lib/mocha/no_yields.rb +0 -5
  209. data/lib/mocha/parameter_matchers/object.rb +0 -15
  210. data/lib/mocha/single_yield.rb +0 -13
  211. data/lib/mocha/standalone.rb +0 -4
  212. data/lib/mocha/unexpected_invocation.rb +0 -24
  213. data/lib/mocha_standalone.rb +0 -4
  214. data/test/acceptance/mock_with_initializer_block_test.rb +0 -56
  215. data/test/unit/class_method_test.rb +0 -254
  216. data/test/unit/multiple_yields_test.rb +0 -16
  217. data/test/unit/no_yields_test.rb +0 -16
  218. data/test/unit/single_yield_test.rb +0 -16
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class ExceptionRescueTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -48,7 +47,7 @@ class ExceptionRescueTest < Mocha::TestCase
48
47
  assert_equal [
49
48
  'not all expectations were satisfied',
50
49
  'unsatisfied expectations:',
51
- '- expected exactly once, not yet invoked: #<Mock:mock>.some_method(any_parameters)'
50
+ '- expected exactly once, invoked never: #<Mock:mock>.some_method(any_parameters)'
52
51
  ], test_result.failure_message_lines
53
52
  end
54
53
  end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class ExpectationsOnMultipleMethodsTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class ExpectedInvocationCountTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -155,7 +154,7 @@ class ExpectedInvocationCountTest < Mocha::TestCase
155
154
  assert_equal [
156
155
  'not all expectations were satisfied',
157
156
  'unsatisfied expectations:',
158
- '- expected at least once, not yet invoked: #<Mock:mock>.method(any_parameters)'
157
+ '- expected at least once, invoked never: #<Mock:mock>.method(any_parameters)'
159
158
  ], test_result.failure_message_lines
160
159
  end
161
160
 
@@ -224,7 +223,7 @@ class ExpectedInvocationCountTest < Mocha::TestCase
224
223
  assert_equal [
225
224
  'unexpected invocation: #<Mock:mock>.method()',
226
225
  'unsatisfied expectations:',
227
- '- expected exactly once, not yet invoked: #<Mock:mock>.method(1)'
226
+ '- expected exactly once, invoked never: #<Mock:mock>.method(1)'
228
227
  ], test_result.failure_message_lines
229
228
  end
230
229
  end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class FailureMessagesTest < Mocha::TestCase
5
4
  OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}'.freeze
@@ -59,4 +58,20 @@ class FailureMessagesTest < Mocha::TestCase
59
58
  end
60
59
  assert_match Regexp.new(%("Foo")), test_result.failures[0].message
61
60
  end
61
+
62
+ def test_should_display_that_block_was_expected
63
+ test_result = run_as_test do
64
+ foo = mock
65
+ foo.expects(:bar).with_block_given
66
+ end
67
+ assert_match Regexp.new(' with block given$'), test_result.failures[0].message
68
+ end
69
+
70
+ def test_should_display_that_block_was_not_expected
71
+ test_result = run_as_test do
72
+ foo = mock
73
+ foo.expects(:bar).with_no_block_given
74
+ end
75
+ assert_match Regexp.new(' with no block given$'), test_result.failures[0].message
76
+ end
62
77
  end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class Issue272Test < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -38,7 +37,7 @@ class Issue272Test < Mocha::TestCase
38
37
  Klass.stubs(:foo).returns('stubbed-foo')
39
38
  # hangs in next line executing:
40
39
  # `@original_method = stubbee._method(method)`
41
- # in Mocha::ClassMethod#hide_original_method
40
+ # in Mocha::StubbedMethod#hide_original_method
42
41
  # but only in Ruby v2.3, not v2.2
43
42
  Klass.stubs(:bar).returns('stubbed-bar')
44
43
  assert_equal 'stubbed-foo', Klass.foo
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class Issue65Test < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class Issue70Test < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class MochaExampleTest < Mocha::TestCase
5
4
  class Rover
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
  require 'execution_point'
4
3
 
5
4
  class MochaTestResultTest < Mocha::TestCase
@@ -0,0 +1,99 @@
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
+ require 'deprecation_disabler'
3
+
4
+ class MockBuiltWithFirstArgumentTypeBeingStringTest < Mocha::TestCase
5
+ include AcceptanceTest
6
+
7
+ def setup
8
+ setup_acceptance_test
9
+ Mocha.configure { |c| c.reinstate_undocumented_behaviour_from_v1_9 = true }
10
+ end
11
+
12
+ def teardown
13
+ teardown_acceptance_test
14
+ end
15
+
16
+ def test_mock_built_with_single_symbol_argument_with_satisfied_expectation
17
+ test_result = run_as_test do
18
+ DeprecationDisabler.disable_deprecations do
19
+ m = mock(:my_method)
20
+ assert_nil m.my_method
21
+ end
22
+ expected_warning = 'Explicitly include `my_method` in Hash of expected methods vs return values, e.g. `mock(:my_method => nil)`.'
23
+ assert_equal expected_warning, Mocha::Deprecation.messages.last
24
+ end
25
+ assert_passed(test_result)
26
+ end
27
+
28
+ def test_mock_built_with_single_symbol_argument_with_unsatisfied_expectation
29
+ test_result = run_as_test do
30
+ DeprecationDisabler.disable_deprecations do
31
+ mock(:my_method)
32
+ end
33
+ end
34
+ assert_failed(test_result)
35
+ assert(test_result.failure_message_lines.any? do |line|
36
+ line[/expected exactly once, invoked never\: #<Mock\:0x[0-9a-f]+>\.my_method\(any_parameters\)/]
37
+ end)
38
+ end
39
+
40
+ def test_stub_built_with_single_symbol_argument
41
+ test_result = run_as_test do
42
+ DeprecationDisabler.disable_deprecations do
43
+ s = stub(:my_method)
44
+ assert_nil s.my_method
45
+ end
46
+ expected_warning = 'Explicitly include `my_method` in Hash of stubbed methods vs return values, e.g. `stub(:my_method => nil)`.'
47
+ assert_equal expected_warning, Mocha::Deprecation.messages.last
48
+ end
49
+ assert_passed(test_result)
50
+ end
51
+
52
+ def test_mock_built_with_first_argument_a_symbol_and_second_argument_a_hash
53
+ test_result = run_as_test do
54
+ DeprecationDisabler.disable_deprecations do
55
+ s = mock(:my_method, :another_method => 123)
56
+ assert_nil s.my_method
57
+ end
58
+ expected_warning = 'In this case the 2nd argument for `mock(:#my_method, ...)` is ignored, but in the future a Hash of expected methods vs return values will be respected.'
59
+ assert Mocha::Deprecation.messages.last(2).include?(expected_warning)
60
+ end
61
+ assert_passed(test_result)
62
+ end
63
+
64
+ def test_stub_built_with_first_argument_a_symbol_and_second_argument_a_hash
65
+ test_result = run_as_test do
66
+ DeprecationDisabler.disable_deprecations do
67
+ s = stub(:my_method, :another_method => 123)
68
+ assert_nil s.my_method
69
+ end
70
+ expected_warning = 'In this case the 2nd argument for `stub(:#my_method, ...)` is ignored, but in the future a Hash of stubbed methods vs return values will be respected.'
71
+ assert Mocha::Deprecation.messages.last(2).include?(expected_warning)
72
+ end
73
+ assert_passed(test_result)
74
+ end
75
+
76
+ def test_stub_everything_built_with_single_symbol_argument
77
+ test_result = run_as_test do
78
+ DeprecationDisabler.disable_deprecations do
79
+ s = stub_everything(:my_method)
80
+ assert_nil s.my_method
81
+ end
82
+ expected_warning = 'Explicitly include `my_method` in Hash of stubbed methods vs return values, e.g. `stub_everything(:my_method => nil)`.'
83
+ assert_equal expected_warning, Mocha::Deprecation.messages.last
84
+ end
85
+ assert_passed(test_result)
86
+ end
87
+
88
+ def test_stub_everything_built_with_first_argument_a_symbol_and_second_argument_a_hash
89
+ test_result = run_as_test do
90
+ DeprecationDisabler.disable_deprecations do
91
+ s = stub_everything(:my_method, :another_method => 123)
92
+ assert_nil s.my_method
93
+ end
94
+ expected_warning = 'In this case the 2nd argument for `stub_everything(:#my_method, ...)` is ignored, but in the future a Hash of stubbed methods vs return values will be respected.' # rubocop:disable Metrics/LineLength
95
+ assert Mocha::Deprecation.messages.last(2).include?(expected_warning)
96
+ end
97
+ assert_passed(test_result)
98
+ end
99
+ end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class MockTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -29,7 +28,7 @@ class MockTest < Mocha::TestCase
29
28
  assert_failed(test_result)
30
29
  end
31
30
 
32
- def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_satisfied
31
+ def test_should_build_string_named_mock_and_explicitly_add_an_expectation_which_is_satisfied
33
32
  test_result = run_as_test do
34
33
  foo = mock('foo')
35
34
  foo.expects(:bar)
@@ -38,7 +37,16 @@ class MockTest < Mocha::TestCase
38
37
  assert_passed(test_result)
39
38
  end
40
39
 
41
- def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_not_satisfied
40
+ def test_should_build_symbol_named_mock_and_explicitly_add_an_expectation_which_is_satisfied
41
+ test_result = run_as_test do
42
+ foo = mock(:foo)
43
+ foo.expects(:bar)
44
+ foo.bar
45
+ end
46
+ assert_passed(test_result)
47
+ end
48
+
49
+ def test_should_build_string_named_mock_and_explicitly_add_an_expectation_which_is_not_satisfied
42
50
  test_result = run_as_test do
43
51
  foo = mock('foo')
44
52
  foo.expects(:bar)
@@ -46,6 +54,14 @@ class MockTest < Mocha::TestCase
46
54
  assert_failed(test_result)
47
55
  end
48
56
 
57
+ def test_should_build_symbol_named_mock_and_explicitly_add_an_expectation_which_is_not_satisfied
58
+ test_result = run_as_test do
59
+ foo = mock(:foo)
60
+ foo.expects(:bar)
61
+ end
62
+ assert_failed(test_result)
63
+ end
64
+
49
65
  def test_should_build_mock_incorporating_two_expectations_which_are_satisifed
50
66
  test_result = run_as_test do
51
67
  foo = mock(:bar => 'bar', :baz => 'baz')
@@ -71,7 +87,7 @@ class MockTest < Mocha::TestCase
71
87
  assert_failed(test_result)
72
88
  end
73
89
 
74
- def test_should_build_named_mock_incorporating_two_expectations_which_are_satisifed
90
+ def test_should_build_string_named_mock_incorporating_two_expectations_which_are_satisifed
75
91
  test_result = run_as_test do
76
92
  foo = mock('foo', :bar => 'bar', :baz => 'baz')
77
93
  foo.bar
@@ -80,7 +96,16 @@ class MockTest < Mocha::TestCase
80
96
  assert_passed(test_result)
81
97
  end
82
98
 
83
- def test_should_build_named_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed
99
+ def test_should_build_symbol_named_mock_incorporating_two_expectations_which_are_satisifed
100
+ test_result = run_as_test do
101
+ foo = mock(:foo, :bar => 'bar', :baz => 'baz')
102
+ foo.bar
103
+ foo.baz
104
+ end
105
+ assert_passed(test_result)
106
+ end
107
+
108
+ def test_should_build_string_named_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed
84
109
  test_result = run_as_test do
85
110
  foo = mock('foo', :bar => 'bar', :baz => 'baz')
86
111
  foo.baz
@@ -88,11 +113,27 @@ class MockTest < Mocha::TestCase
88
113
  assert_failed(test_result)
89
114
  end
90
115
 
91
- def test_should_build_named_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed
116
+ def test_should_build_symbol_named_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed
117
+ test_result = run_as_test do
118
+ foo = mock(:foo, :bar => 'bar', :baz => 'baz')
119
+ foo.baz
120
+ end
121
+ assert_failed(test_result)
122
+ end
123
+
124
+ def test_should_build_string_named_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed
92
125
  test_result = run_as_test do
93
126
  foo = mock('foo', :bar => 'bar', :baz => 'baz')
94
127
  foo.bar
95
128
  end
96
129
  assert_failed(test_result)
97
130
  end
131
+
132
+ def test_should_build_symbol_named_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed
133
+ test_result = run_as_test do
134
+ foo = mock(:foo, :bar => 'bar', :baz => 'baz')
135
+ foo.bar
136
+ end
137
+ assert_failed(test_result)
138
+ end
98
139
  end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class MockedMethodDispatchTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class FailureMessageTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -0,0 +1,56 @@
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
+
3
+ class MultipleYieldingTest < Mocha::TestCase
4
+ include AcceptanceTest
5
+
6
+ def setup
7
+ setup_acceptance_test
8
+ end
9
+
10
+ def teardown
11
+ teardown_acceptance_test
12
+ end
13
+
14
+ def test_yields_values_multiple_times_when_stubbed_method_is_invoked
15
+ test_result = run_as_test do
16
+ m = mock('m')
17
+ m.stubs(:foo).multiple_yields([1], [2, 3])
18
+ yielded = []
19
+ m.foo { |*args| yielded << args }
20
+ assert_equal [[1], [2, 3]], yielded
21
+ end
22
+ assert_passed(test_result)
23
+ end
24
+
25
+ def test_yields_values_multiple_times_when_multiple_yields_arguments_are_not_arrays
26
+ test_result = run_as_test do
27
+ m = mock('m')
28
+ m.stubs(:foo).multiple_yields(1, { :b => 2 }, '3')
29
+ yielded = []
30
+ m.foo { |*args| yielded << args }
31
+ assert_equal [[1], [{ :b => 2 }], ['3']], yielded
32
+ end
33
+ assert_passed(test_result)
34
+ end
35
+
36
+ def test_raises_local_jump_error_if_instructed_to_multiple_yield_but_no_block_given
37
+ test_result = run_as_test do
38
+ m = mock('m')
39
+ m.stubs(:foo).multiple_yields([])
40
+ assert_raises(LocalJumpError) { m.foo }
41
+ end
42
+ assert_passed(test_result)
43
+ end
44
+
45
+ def test_yields_different_values_on_consecutive_invocations
46
+ test_result = run_as_test do
47
+ m = mock('m')
48
+ m.stubs(:foo).multiple_yields([0], [1, 2]).then.multiple_yields([3], [4, 5])
49
+ yielded = []
50
+ m.foo { |*args| yielded << args }
51
+ m.foo { |*args| yielded << args }
52
+ assert_equal [[0], [1, 2], [3], [4, 5]], yielded
53
+ end
54
+ assert_passed(test_result)
55
+ end
56
+ end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class OptionalParameterMatcherTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class ParameterMatcherTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class PartialMockTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
  require 'mocha/ruby_version'
4
3
 
5
4
  class PrependTest < Mocha::TestCase
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
  require 'mocha/not_initialized_error'
4
3
 
5
4
  class PreventUseOfMochaOutsideTestTest < Mocha::TestCase
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class RaiseExceptionTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class ReturnValueTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class SequenceTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class StatesTest < Mocha::TestCase
5
4
  include AcceptanceTest