mocha 1.9.0 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) 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 +30 -11
  7. data/RELEASE.md +93 -0
  8. data/Rakefile +10 -7
  9. data/docs/CNAME +1 -0
  10. data/docs/Mocha.html +132 -5
  11. data/docs/Mocha/API.html +437 -206
  12. data/docs/Mocha/ClassMethods.html +13 -16
  13. data/docs/Mocha/Configuration.html +1126 -227
  14. data/docs/Mocha/Expectation.html +420 -267
  15. data/docs/Mocha/ExpectationError.html +5 -10
  16. data/docs/Mocha/ExpectationErrorFactory.html +9 -18
  17. data/docs/Mocha/Hooks.html +12 -27
  18. data/docs/Mocha/Integration.html +3 -3
  19. data/docs/Mocha/Integration/MiniTest.html +3 -3
  20. data/docs/Mocha/Integration/MiniTest/Adapter.html +5 -6
  21. data/docs/Mocha/Integration/TestUnit.html +3 -3
  22. data/docs/Mocha/Integration/TestUnit/Adapter.html +5 -6
  23. data/docs/Mocha/Mock.html +202 -162
  24. data/docs/Mocha/ObjectMethods.html +121 -68
  25. data/docs/Mocha/ParameterMatchers.html +21 -109
  26. data/docs/Mocha/ParameterMatchers/AllOf.html +4 -5
  27. data/docs/Mocha/ParameterMatchers/AnyOf.html +4 -5
  28. data/docs/Mocha/ParameterMatchers/AnyParameters.html +3 -3
  29. data/docs/Mocha/ParameterMatchers/Anything.html +3 -3
  30. data/docs/Mocha/ParameterMatchers/Base.html +8 -15
  31. data/docs/Mocha/ParameterMatchers/Equals.html +4 -5
  32. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +3 -3
  33. data/docs/Mocha/ParameterMatchers/HasEntries.html +4 -5
  34. data/docs/Mocha/ParameterMatchers/HasEntry.html +4 -5
  35. data/docs/Mocha/ParameterMatchers/HasKey.html +4 -5
  36. data/docs/Mocha/ParameterMatchers/HasValue.html +4 -5
  37. data/docs/Mocha/ParameterMatchers/Includes.html +4 -5
  38. data/docs/Mocha/ParameterMatchers/InstanceOf.html +4 -5
  39. data/docs/Mocha/ParameterMatchers/IsA.html +3 -3
  40. data/docs/Mocha/ParameterMatchers/KindOf.html +4 -5
  41. data/docs/Mocha/ParameterMatchers/Not.html +4 -5
  42. data/docs/Mocha/ParameterMatchers/Optionally.html +3 -3
  43. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +4 -5
  44. data/docs/Mocha/ParameterMatchers/RespondsWith.html +4 -5
  45. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +4 -5
  46. data/docs/Mocha/Sequence.html +3 -3
  47. data/docs/Mocha/StateMachine.html +13 -25
  48. data/docs/Mocha/StateMachine/State.html +4 -5
  49. data/docs/Mocha/StateMachine/StatePredicate.html +4 -5
  50. data/docs/Mocha/StubbingError.html +3 -3
  51. data/docs/_index.html +4 -22
  52. data/docs/class_list.html +1 -1
  53. data/docs/file.COPYING.html +3 -3
  54. data/docs/file.MIT-LICENSE.html +3 -3
  55. data/docs/file.README.html +36 -14
  56. data/docs/file.RELEASE.html +126 -3
  57. data/docs/frames.html +1 -1
  58. data/docs/index.html +36 -14
  59. data/docs/method_list.html +117 -37
  60. data/docs/top-level-namespace.html +3 -3
  61. data/gemfiles/Gemfile.minitest.5.11.3 +7 -0
  62. data/init.rb +1 -3
  63. data/lib/mocha.rb +8 -0
  64. data/lib/mocha/any_instance_method.rb +9 -25
  65. data/lib/mocha/api.rb +120 -56
  66. data/lib/mocha/block_matcher.rb +31 -0
  67. data/lib/mocha/cardinality.rb +26 -11
  68. data/lib/mocha/class_methods.rb +17 -15
  69. data/lib/mocha/configuration.rb +351 -67
  70. data/lib/mocha/deprecation.rb +2 -1
  71. data/lib/mocha/detection/test_unit.rb +1 -3
  72. data/lib/mocha/exception_raiser.rb +2 -1
  73. data/lib/mocha/expectation.rb +102 -63
  74. data/lib/mocha/expectation_error.rb +1 -3
  75. data/lib/mocha/expectation_list.rb +6 -6
  76. data/lib/mocha/inspect.rb +28 -26
  77. data/lib/mocha/instance_method.rb +19 -2
  78. data/lib/mocha/integration.rb +1 -3
  79. data/lib/mocha/integration/mini_test.rb +7 -0
  80. data/lib/mocha/integration/test_unit.rb +7 -0
  81. data/lib/mocha/invocation.rb +77 -0
  82. data/lib/mocha/macos_version.rb +5 -0
  83. data/lib/mocha/minitest.rb +6 -1
  84. data/lib/mocha/mock.rb +46 -31
  85. data/lib/mocha/mockery.rb +25 -61
  86. data/lib/mocha/names.rb +1 -1
  87. data/lib/mocha/object_methods.rb +13 -19
  88. data/lib/mocha/parameter_matchers.rb +1 -1
  89. data/lib/mocha/parameter_matchers/all_of.rb +1 -1
  90. data/lib/mocha/parameter_matchers/any_of.rb +1 -1
  91. data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -9
  92. data/lib/mocha/parameter_matchers/includes.rb +2 -0
  93. data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
  94. data/lib/mocha/raised_exception.rb +11 -0
  95. data/lib/mocha/return_values.rb +3 -3
  96. data/lib/mocha/setup.rb +5 -0
  97. data/lib/mocha/single_return_value.rb +2 -1
  98. data/lib/mocha/singleton_class.rb +9 -0
  99. data/lib/mocha/{class_method.rb → stubbed_method.rb} +23 -43
  100. data/lib/mocha/test_unit.rb +6 -1
  101. data/lib/mocha/thrower.rb +2 -1
  102. data/lib/mocha/thrown_object.rb +12 -0
  103. data/lib/mocha/version.rb +1 -1
  104. data/lib/mocha/yield_parameters.rb +5 -11
  105. data/mocha.gemspec +1 -3
  106. data/test/acceptance/acceptance_test_helper.rb +7 -0
  107. data/test/acceptance/bug_18914_test.rb +0 -1
  108. data/test/acceptance/bug_21465_test.rb +0 -1
  109. data/test/acceptance/bug_21563_test.rb +0 -1
  110. data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +69 -0
  111. data/test/acceptance/exception_rescue_test.rb +1 -2
  112. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -1
  113. data/test/acceptance/expected_invocation_count_test.rb +2 -3
  114. data/test/acceptance/failure_messages_test.rb +16 -1
  115. data/test/acceptance/issue_272_test.rb +1 -2
  116. data/test/acceptance/issue_65_test.rb +0 -1
  117. data/test/acceptance/issue_70_test.rb +0 -1
  118. data/test/acceptance/mocha_example_test.rb +0 -1
  119. data/test/acceptance/mocha_test_result_test.rb +0 -1
  120. data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +98 -0
  121. data/test/acceptance/mock_test.rb +63 -6
  122. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -1
  123. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -1
  124. data/test/acceptance/multiple_yielding_test.rb +59 -0
  125. data/test/acceptance/optional_parameters_test.rb +0 -1
  126. data/test/acceptance/parameter_matcher_test.rb +0 -1
  127. data/test/acceptance/partial_mocks_test.rb +0 -1
  128. data/test/acceptance/prepend_test.rb +0 -1
  129. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -1
  130. data/test/acceptance/raise_exception_test.rb +0 -1
  131. data/test/acceptance/return_value_test.rb +0 -1
  132. data/test/acceptance/sequence_test.rb +0 -1
  133. data/test/acceptance/states_test.rb +0 -1
  134. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +1 -2
  135. data/test/acceptance/stub_any_instance_method_test.rb +20 -1
  136. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -1
  137. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -1
  138. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -1
  139. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +1 -2
  140. data/test/acceptance/stub_everything_test.rb +0 -1
  141. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -1
  142. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -1
  143. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -1
  144. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -1
  145. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -1
  146. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -1
  147. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -1
  148. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -1
  149. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -1
  150. data/test/acceptance/stub_module_method_test.rb +0 -1
  151. data/test/acceptance/stub_test.rb +0 -1
  152. data/test/acceptance/stubba_example_test.rb +0 -1
  153. data/test/acceptance/stubba_test_result_test.rb +0 -1
  154. data/test/acceptance/stubbing_error_backtrace_test.rb +4 -5
  155. data/test/acceptance/stubbing_frozen_object_test.rb +0 -1
  156. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -1
  157. data/test/acceptance/stubbing_method_unnecessarily_test.rb +5 -5
  158. data/test/acceptance/stubbing_nil_test.rb +5 -5
  159. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +27 -11
  160. data/test/acceptance/stubbing_non_existent_class_method_test.rb +11 -11
  161. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +11 -11
  162. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +8 -8
  163. data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
  164. data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
  165. data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
  166. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -1
  167. data/test/acceptance/throw_test.rb +0 -1
  168. data/test/acceptance/unexpected_invocation_test.rb +0 -1
  169. data/test/acceptance/unstubbing_test.rb +0 -1
  170. data/test/acceptance/yielding_test.rb +80 -0
  171. data/test/integration/shared_tests.rb +5 -3
  172. data/test/method_definer.rb +11 -17
  173. data/test/test_runner.rb +2 -0
  174. data/test/unit/any_instance_method_test.rb +41 -40
  175. data/test/unit/cardinality_test.rb +41 -23
  176. data/test/unit/central_test.rb +0 -1
  177. data/test/unit/class_methods_test.rb +1 -1
  178. data/test/unit/configuration_test.rb +12 -12
  179. data/test/unit/exception_raiser_test.rb +10 -5
  180. data/test/unit/expectation_list_test.rb +13 -11
  181. data/test/unit/expectation_test.rb +115 -103
  182. data/test/unit/instance_method_test.rb +282 -0
  183. data/test/unit/mock_test.rb +28 -19
  184. data/test/unit/mockery_test.rb +8 -11
  185. data/test/unit/module_methods_test.rb +2 -3
  186. data/test/unit/object_inspect_test.rb +6 -4
  187. data/test/unit/object_methods_test.rb +3 -2
  188. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -9
  189. data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
  190. data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
  191. data/test/unit/parameter_matchers/has_key_test.rb +1 -1
  192. data/test/unit/parameter_matchers/has_value_test.rb +1 -1
  193. data/test/unit/parameter_matchers/includes_test.rb +1 -1
  194. data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
  195. data/test/unit/return_values_test.rb +25 -20
  196. data/test/unit/single_return_value_test.rb +6 -1
  197. data/test/unit/thrower_test.rb +7 -2
  198. data/test/unit/yield_parameters_test.rb +35 -53
  199. metadata +19 -34
  200. data/docs/Mocha/UnexpectedInvocation.html +0 -140
  201. data/lib/mocha/mini_test.rb +0 -5
  202. data/lib/mocha/module_method.rb +0 -6
  203. data/lib/mocha/module_methods.rb +0 -10
  204. data/lib/mocha/multiple_yields.rb +0 -15
  205. data/lib/mocha/no_yields.rb +0 -5
  206. data/lib/mocha/parameter_matchers/object.rb +0 -15
  207. data/lib/mocha/single_yield.rb +0 -13
  208. data/lib/mocha/standalone.rb +0 -4
  209. data/lib/mocha/unexpected_invocation.rb +0 -24
  210. data/lib/mocha_standalone.rb +0 -4
  211. data/test/acceptance/mock_with_initializer_block_test.rb +0 -56
  212. data/test/unit/class_method_test.rb +0 -276
  213. data/test/unit/multiple_yields_test.rb +0 -16
  214. data/test/unit/no_yields_test.rb +0 -16
  215. 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 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
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class StubAnyInstanceMethodDefinedOnSuperclassTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -59,7 +58,7 @@ class StubAnyInstanceMethodDefinedOnSuperclassTest < Mocha::TestCase
59
58
  assert_equal [
60
59
  'not all expectations were satisfied',
61
60
  'unsatisfied expectations:',
62
- '- expected exactly once, not yet invoked: #<AnyInstance:superklass>.my_instance_method(any_parameters)'
61
+ '- expected exactly once, invoked never: #<AnyInstance:superklass>.my_instance_method(any_parameters)'
63
62
  ], test_result.failure_message_lines
64
63
  end
65
64
  end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class StubAnyInstanceMethodTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -43,6 +42,26 @@ class StubAnyInstanceMethodTest < Mocha::TestCase
43
42
  assert_equal :original_return_value, instance.my_instance_method
44
43
  end
45
44
 
45
+ def test_should_leave_stubbed_public_method_unchanged_after_test_when_it_was_originally_private_in_owning_module
46
+ module_with_private_method = Module.new do
47
+ def my_included_method
48
+ :original_return_value
49
+ end
50
+ private :my_included_method
51
+ end
52
+ klass = Class.new do
53
+ include module_with_private_method
54
+ public :my_included_method
55
+ end
56
+ instance = klass.new
57
+ test_result = run_as_test do
58
+ klass.any_instance.stubs(:my_included_method).returns(:new_return_value)
59
+ assert_equal :new_return_value, instance.my_included_method
60
+ end
61
+ assert_passed(test_result)
62
+ assert_equal :original_return_value, instance.my_included_method
63
+ end
64
+
46
65
  def test_should_leave_stubbed_protected_method_unchanged_after_test
47
66
  klass = Class.new do
48
67
  def my_instance_method
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < 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 StubClassMethodDefinedOnClassTest < 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 StubClassMethodDefinedOnModuleTest < 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 StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -138,7 +137,7 @@ class StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
138
137
  assert_equal [
139
138
  'not all expectations were satisfied',
140
139
  'unsatisfied expectations:',
141
- '- expected exactly once, not yet invoked: superklass.my_class_method(any_parameters)'
140
+ '- expected exactly once, invoked never: superklass.my_class_method(any_parameters)'
142
141
  ], test_result.failure_message_lines
143
142
  end
144
143
  # rubocop:enable Lint/DuplicateMethods
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
3
2
 
4
3
  class StubEverythingTest < 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 StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < 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 StubInstanceMethodDefinedOnClassAndAliasedTest < 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 StubInstanceMethodDefinedOnClassTest < 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 StubInstanceMethodDefinedOnKernelModuleTest < 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 StubInstanceMethodDefinedOnModuleTest < 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 StubInstanceMethodDefinedOnObjectClassTest < 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 StubInstanceMethodDefinedOnSingletonClassTest < 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 StubInstanceMethodDefinedOnSuperclassTest < 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
  unless Mocha::PRE_RUBY_V19
5
4
  class StubMethodDefinedOnModuleAndAliasedTest < 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 StubModuleMethodTest < 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 StubTest < 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 Widget
5
4
  def model
@@ -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 StubbaTestResultTest < Mocha::TestCase
@@ -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 StubbingErrorBacktraceTest < Mocha::TestCase
@@ -17,7 +16,7 @@ class StubbingErrorBacktraceTest < Mocha::TestCase
17
16
  def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_existent_method_was_made
18
17
  execution_point = nil
19
18
  object = Object.new
20
- Mocha::Configuration.prevent(:stubbing_non_existent_method)
19
+ Mocha.configure { |c| c.stubbing_non_existent_method = :prevent }
21
20
  test_result = run_as_test do
22
21
  execution_point = ExecutionPoint.current; object.stubs(:non_existent_method)
23
22
  end
@@ -31,7 +30,7 @@ class StubbingErrorBacktraceTest < Mocha::TestCase
31
30
  def non_public_method; end
32
31
  private :non_public_method
33
32
  end.new
34
- Mocha::Configuration.prevent(:stubbing_non_public_method)
33
+ Mocha.configure { |c| c.stubbing_non_public_method = :prevent }
35
34
  test_result = run_as_test do
36
35
  execution_point = ExecutionPoint.current; object.stubs(:non_public_method)
37
36
  end
@@ -42,7 +41,7 @@ class StubbingErrorBacktraceTest < Mocha::TestCase
42
41
  def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_method_on_non_mock_object_was_made
43
42
  execution_point = nil
44
43
  object = Object.new
45
- Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object)
44
+ Mocha.configure { |c| c.stubbing_method_on_non_mock_object = :prevent }
46
45
  test_result = run_as_test do
47
46
  execution_point = ExecutionPoint.current; object.stubs(:any_method)
48
47
  end
@@ -53,7 +52,7 @@ class StubbingErrorBacktraceTest < Mocha::TestCase
53
52
  def test_should_display_backtrace_indicating_line_number_where_method_was_unnecessarily_stubbed
54
53
  execution_point = nil
55
54
  object = Object.new
56
- Mocha::Configuration.prevent(:stubbing_method_unnecessarily)
55
+ Mocha.configure { |c| c.stubbing_method_unnecessarily = :prevent }
57
56
  test_result = run_as_test do
58
57
  execution_point = ExecutionPoint.current; object.stubs(:unused_method)
59
58
  end
@@ -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 StubbingFrozenObjectTest < 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 StubbingMethodAcceptingBlockParameterTest < Mocha::TestCase
5
4
  include AcceptanceTest
@@ -1,5 +1,5 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
2
+ require 'mocha/configuration'
3
3
 
4
4
  class StubbingMethodUnnecessarilyTest < Mocha::TestCase
5
5
  include AcceptanceTest
@@ -13,7 +13,7 @@ class StubbingMethodUnnecessarilyTest < Mocha::TestCase
13
13
  end
14
14
 
15
15
  def test_should_allow_stubbing_method_unnecessarily
16
- Mocha::Configuration.allow(:stubbing_method_unnecessarily)
16
+ Mocha.configure { |c| c.stubbing_method_unnecessarily = :allow }
17
17
  test_result = run_as_test do
18
18
  mock = mock('mock')
19
19
  mock.stubs(:public_method)
@@ -23,7 +23,7 @@ class StubbingMethodUnnecessarilyTest < Mocha::TestCase
23
23
  end
24
24
 
25
25
  def test_should_warn_when_stubbing_method_unnecessarily
26
- Mocha::Configuration.warn_when(:stubbing_method_unnecessarily)
26
+ Mocha.configure { |c| c.stubbing_method_unnecessarily = :warn }
27
27
  test_result = run_as_test do
28
28
  mock = mock('mock')
29
29
  mock.stubs(:public_method)
@@ -33,7 +33,7 @@ class StubbingMethodUnnecessarilyTest < Mocha::TestCase
33
33
  end
34
34
 
35
35
  def test_should_prevent_stubbing_method_unnecessarily
36
- Mocha::Configuration.prevent(:stubbing_method_unnecessarily)
36
+ Mocha.configure { |c| c.stubbing_method_unnecessarily = :prevent }
37
37
  test_result = run_as_test do
38
38
  mock = mock('mock')
39
39
  mock.stubs(:public_method)
@@ -52,7 +52,7 @@ class StubbingMethodUnnecessarilyTest < Mocha::TestCase
52
52
  end
53
53
 
54
54
  def test_should_allow_stubbing_method_when_stubbed_method_is_invoked
55
- Mocha::Configuration.prevent(:stubbing_method_unnecessarily)
55
+ Mocha.configure { |c| c.stubbing_method_unnecessarily = :prevent }
56
56
  test_result = run_as_test do
57
57
  mock = mock('mock')
58
58
  mock.stubs(:public_method)
@@ -1,5 +1,5 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
2
+ require 'mocha/configuration'
3
3
 
4
4
  class StubbingNilTest < Mocha::TestCase
5
5
  include AcceptanceTest
@@ -14,7 +14,7 @@ class StubbingNilTest < Mocha::TestCase
14
14
 
15
15
  if RUBY_VERSION < '2.2.0'
16
16
  def test_should_allow_stubbing_method_on_nil
17
- Mocha::Configuration.allow(:stubbing_method_on_nil)
17
+ Mocha.configure { |c| c.stubbing_method_on_nil = :allow }
18
18
  test_result = run_as_test do
19
19
  nil.stubs(:stubbed_method)
20
20
  end
@@ -23,7 +23,7 @@ class StubbingNilTest < Mocha::TestCase
23
23
  end
24
24
 
25
25
  def test_should_warn_on_stubbing_method_on_nil
26
- Mocha::Configuration.warn_when(:stubbing_method_on_nil)
26
+ Mocha.configure { |c| c.stubbing_method_on_nil = :warn }
27
27
  test_result = run_as_test do
28
28
  nil.stubs(:stubbed_method)
29
29
  end
@@ -32,7 +32,7 @@ class StubbingNilTest < Mocha::TestCase
32
32
  end
33
33
 
34
34
  def test_should_prevent_stubbing_method_on_nil
35
- Mocha::Configuration.prevent(:stubbing_method_on_nil)
35
+ Mocha.configure { |c| c.stubbing_method_on_nil = :prevent }
36
36
  test_result = run_as_test do
37
37
  nil.stubs(:stubbed_method)
38
38
  end
@@ -49,7 +49,7 @@ class StubbingNilTest < Mocha::TestCase
49
49
  end
50
50
 
51
51
  def test_should_allow_stubbing_method_on_non_nil_object
52
- Mocha::Configuration.prevent(:stubbing_method_on_nil)
52
+ Mocha.configure { |c| c.stubbing_method_on_nil = :prevent }
53
53
  object = Object.new
54
54
  test_result = run_as_test do
55
55
  object.stubs(:stubbed_method)
@@ -1,5 +1,5 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha/setup'
2
+ require 'mocha/configuration'
3
3
 
4
4
  class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
5
5
  include AcceptanceTest
@@ -13,7 +13,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
13
13
  end
14
14
 
15
15
  def test_should_allow_stubbing_non_existent_any_instance_method
16
- Mocha::Configuration.allow(:stubbing_non_existent_method)
16
+ Mocha.configure { |c| c.stubbing_non_existent_method = :allow }
17
17
  klass = Class.new
18
18
  test_result = run_as_test do
19
19
  klass.any_instance.stubs(:non_existent_method)
@@ -23,7 +23,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
23
23
  end
24
24
 
25
25
  def test_should_warn_when_stubbing_non_existent_any_instance_method
26
- Mocha::Configuration.warn_when(:stubbing_non_existent_method)
26
+ Mocha.configure { |c| c.stubbing_non_existent_method = :warn }
27
27
  klass = Class.new
28
28
  test_result = run_as_test do
29
29
  klass.any_instance.stubs(:non_existent_method)
@@ -33,7 +33,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
33
33
  end
34
34
 
35
35
  def test_should_prevent_stubbing_non_existent_any_instance_method
36
- Mocha::Configuration.prevent(:stubbing_non_existent_method)
36
+ Mocha.configure { |c| c.stubbing_non_existent_method = :prevent }
37
37
  klass = Class.new
38
38
  test_result = run_as_test do
39
39
  klass.any_instance.stubs(:non_existent_method)
@@ -52,7 +52,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
52
52
  end
53
53
 
54
54
  def test_should_allow_stubbing_existing_public_any_instance_method
55
- Mocha::Configuration.prevent(:stubbing_non_existent_method)
55
+ Mocha.configure { |c| c.stubbing_non_existent_method = :prevent }
56
56
  klass = Class.new do
57
57
  def existing_public_method; end
58
58
  public :existing_public_method
@@ -64,7 +64,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
64
64
  end
65
65
 
66
66
  def test_should_allow_stubbing_method_to_which_any_instance_responds
67
- Mocha::Configuration.prevent(:stubbing_non_existent_method)
67
+ Mocha.configure { |c| c.stubbing_non_existent_method = :prevent }
68
68
  klass = Class.new do
69
69
  def respond_to?(method, _include_private = false)
70
70
  (method == :method_to_which_instance_responds)
@@ -76,8 +76,24 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
76
76
  assert_passed(test_result)
77
77
  end
78
78
 
79
+ def test_should_default_to_allowing_stubbing_method_if_responds_to_depends_on_calling_initialize
80
+ klass = Class.new do
81
+ def initialize(attrs = {})
82
+ @attributes = attrs
83
+ end
84
+
85
+ def respond_to?(method, _include_private = false)
86
+ @attributes.key?(method) ? @attributes[method] : super
87
+ end
88
+ end
89
+ test_result = run_as_test do
90
+ klass.any_instance.stubs(:foo)
91
+ end
92
+ assert_passed(test_result)
93
+ end
94
+
79
95
  def test_should_allow_stubbing_existing_protected_any_instance_method
80
- Mocha::Configuration.prevent(:stubbing_non_existent_method)
96
+ Mocha.configure { |c| c.stubbing_non_existent_method = :prevent }
81
97
  klass = Class.new do
82
98
  def existing_protected_method; end
83
99
  protected :existing_protected_method
@@ -89,7 +105,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
89
105
  end
90
106
 
91
107
  def test_should_allow_stubbing_existing_private_any_instance_method
92
- Mocha::Configuration.prevent(:stubbing_non_existent_method)
108
+ Mocha.configure { |c| c.stubbing_non_existent_method = :prevent }
93
109
  klass = Class.new do
94
110
  def existing_private_method; end
95
111
  private :existing_private_method
@@ -101,7 +117,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
101
117
  end
102
118
 
103
119
  def test_should_allow_stubbing_existing_public_any_instance_superclass_method
104
- Mocha::Configuration.prevent(:stubbing_non_existent_method)
120
+ Mocha.configure { |c| c.stubbing_non_existent_method = :prevent }
105
121
  superklass = Class.new do
106
122
  def existing_public_method; end
107
123
  public :existing_public_method
@@ -114,7 +130,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
114
130
  end
115
131
 
116
132
  def test_should_allow_stubbing_existing_protected_any_instance_superclass_method
117
- Mocha::Configuration.prevent(:stubbing_non_existent_method)
133
+ Mocha.configure { |c| c.stubbing_non_existent_method = :prevent }
118
134
  superklass = Class.new do
119
135
  def existing_protected_method; end
120
136
  protected :existing_protected_method
@@ -127,7 +143,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
127
143
  end
128
144
 
129
145
  def test_should_allow_stubbing_existing_private_any_instance_superclass_method
130
- Mocha::Configuration.prevent(:stubbing_non_existent_method)
146
+ Mocha.configure { |c| c.stubbing_non_existent_method = :prevent }
131
147
  superklass = Class.new do
132
148
  def existing_private_method; end
133
149
  private :existing_private_method