mocha 1.4.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +58 -0
  3. data/.rubocop_todo.yml +50 -0
  4. data/README.md +12 -71
  5. data/RELEASE.md +19 -0
  6. data/Rakefile +35 -28
  7. data/bin/build-matrix +17 -18
  8. data/lib/mocha/any_instance_method.rb +19 -25
  9. data/lib/mocha/api.rb +1 -5
  10. data/lib/mocha/argument_iterator.rb +4 -8
  11. data/lib/mocha/backtrace_filter.rb +1 -5
  12. data/lib/mocha/cardinality.rb +20 -27
  13. data/lib/mocha/central.rb +21 -12
  14. data/lib/mocha/change_state_side_effect.rb +0 -4
  15. data/lib/mocha/class_method.rb +31 -37
  16. data/lib/mocha/class_methods.rb +11 -15
  17. data/lib/mocha/configuration.rb +69 -10
  18. data/lib/mocha/debug.rb +3 -2
  19. data/lib/mocha/deprecation.rb +4 -11
  20. data/lib/mocha/detection/mini_test.rb +0 -2
  21. data/lib/mocha/detection/test_unit.rb +4 -4
  22. data/lib/mocha/error_with_filtered_backtrace.rb +13 -0
  23. data/lib/mocha/exception_raiser.rb +2 -5
  24. data/lib/mocha/expectation.rb +15 -18
  25. data/lib/mocha/expectation_error.rb +2 -0
  26. data/lib/mocha/expectation_error_factory.rb +0 -1
  27. data/lib/mocha/expectation_list.rb +2 -6
  28. data/lib/mocha/hooks.rb +1 -3
  29. data/lib/mocha/in_state_ordering_constraint.rb +0 -4
  30. data/lib/mocha/inspect.rb +3 -5
  31. data/lib/mocha/instance_method.rb +0 -2
  32. data/lib/mocha/integration/mini_test/adapter.rb +2 -4
  33. data/lib/mocha/integration/mini_test/exception_translation.rb +1 -1
  34. data/lib/mocha/integration/mini_test/nothing.rb +4 -4
  35. data/lib/mocha/integration/mini_test/version_13.rb +4 -1
  36. data/lib/mocha/integration/mini_test/version_140.rb +4 -1
  37. data/lib/mocha/integration/mini_test/version_141.rb +4 -1
  38. data/lib/mocha/integration/mini_test/version_142_to_172.rb +4 -1
  39. data/lib/mocha/integration/mini_test/version_200.rb +4 -1
  40. data/lib/mocha/integration/mini_test/version_201_to_222.rb +4 -1
  41. data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +4 -1
  42. data/lib/mocha/integration/mini_test/version_2112_to_320.rb +4 -1
  43. data/lib/mocha/integration/mini_test/version_230_to_2101.rb +4 -1
  44. data/lib/mocha/integration/monkey_patcher.rb +5 -7
  45. data/lib/mocha/integration/test_unit/adapter.rb +5 -6
  46. data/lib/mocha/integration/test_unit/gem_version_200.rb +5 -2
  47. data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +5 -2
  48. data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +5 -2
  49. data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +5 -2
  50. data/lib/mocha/integration/test_unit/nothing.rb +4 -4
  51. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +4 -1
  52. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +4 -1
  53. data/lib/mocha/integration.rb +3 -4
  54. data/lib/mocha/is_a.rb +0 -2
  55. data/lib/mocha/logger.rb +0 -4
  56. data/lib/mocha/method_matcher.rb +1 -5
  57. data/lib/mocha/minitest.rb +1 -1
  58. data/lib/mocha/mock.rb +25 -30
  59. data/lib/mocha/mockery.rb +62 -43
  60. data/lib/mocha/module_method.rb +0 -10
  61. data/lib/mocha/module_methods.rb +0 -4
  62. data/lib/mocha/multiple_yields.rb +0 -5
  63. data/lib/mocha/names.rb +1 -11
  64. data/lib/mocha/no_yields.rb +1 -7
  65. data/lib/mocha/not_initialized_error.rb +7 -0
  66. data/lib/mocha/object_methods.rb +16 -16
  67. data/lib/mocha/parameter_matchers/all_of.rb +1 -7
  68. data/lib/mocha/parameter_matchers/any_of.rb +1 -7
  69. data/lib/mocha/parameter_matchers/any_parameters.rb +3 -9
  70. data/lib/mocha/parameter_matchers/anything.rb +2 -8
  71. data/lib/mocha/parameter_matchers/base.rb +6 -12
  72. data/lib/mocha/parameter_matchers/equals.rb +0 -6
  73. data/lib/mocha/parameter_matchers/equivalent_uri.rb +6 -6
  74. data/lib/mocha/parameter_matchers/has_entries.rb +2 -6
  75. data/lib/mocha/parameter_matchers/has_entry.rb +8 -11
  76. data/lib/mocha/parameter_matchers/has_key.rb +2 -6
  77. data/lib/mocha/parameter_matchers/has_value.rb +2 -6
  78. data/lib/mocha/parameter_matchers/includes.rb +2 -6
  79. data/lib/mocha/parameter_matchers/instance_of.rb +0 -6
  80. data/lib/mocha/parameter_matchers/is_a.rb +2 -6
  81. data/lib/mocha/parameter_matchers/kind_of.rb +2 -6
  82. data/lib/mocha/parameter_matchers/not.rb +2 -6
  83. data/lib/mocha/parameter_matchers/object.rb +0 -2
  84. data/lib/mocha/parameter_matchers/optionally.rb +4 -10
  85. data/lib/mocha/parameter_matchers/regexp_matches.rb +0 -6
  86. data/lib/mocha/parameter_matchers/responds_with.rb +3 -8
  87. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +2 -6
  88. data/lib/mocha/parameter_matchers.rb +0 -2
  89. data/lib/mocha/parameters_matcher.rb +6 -9
  90. data/lib/mocha/pretty_parameters.rb +0 -4
  91. data/lib/mocha/receivers.rb +10 -14
  92. data/lib/mocha/return_values.rb +3 -7
  93. data/lib/mocha/sequence.rb +4 -9
  94. data/lib/mocha/single_return_value.rb +0 -4
  95. data/lib/mocha/single_yield.rb +0 -5
  96. data/lib/mocha/state_machine.rb +6 -10
  97. data/lib/mocha/stubbing_error.rb +2 -13
  98. data/lib/mocha/test_unit.rb +1 -1
  99. data/lib/mocha/thrower.rb +2 -5
  100. data/lib/mocha/unexpected_invocation.rb +3 -5
  101. data/lib/mocha/version.rb +1 -1
  102. data/lib/mocha/yield_parameters.rb +3 -7
  103. data/mocha.gemspec +34 -58
  104. data/test/acceptance/acceptance_test_helper.rb +0 -6
  105. data/test/acceptance/bug_18914_test.rb +7 -12
  106. data/test/acceptance/bug_21465_test.rb +0 -2
  107. data/test/acceptance/bug_21563_test.rb +0 -2
  108. data/test/acceptance/exception_rescue_test.rb +7 -8
  109. data/test/acceptance/expectations_on_multiple_methods_test.rb +2 -1
  110. data/test/acceptance/expected_invocation_count_test.rb +27 -29
  111. data/test/acceptance/failure_messages_test.rb +3 -5
  112. data/test/acceptance/issue_272_test.rb +0 -1
  113. data/test/acceptance/issue_65_test.rb +15 -13
  114. data/test/acceptance/issue_70_test.rb +0 -1
  115. data/test/acceptance/mocha_example_test.rb +5 -6
  116. data/test/acceptance/mocha_test_result_test.rb +7 -7
  117. data/test/acceptance/mock_test.rb +2 -4
  118. data/test/acceptance/mock_with_initializer_block_test.rb +0 -2
  119. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -2
  120. data/test/acceptance/multiple_expectations_failure_message_test.rb +16 -17
  121. data/test/acceptance/optional_parameters_test.rb +0 -2
  122. data/test/acceptance/parameter_matcher_test.rb +2 -3
  123. data/test/acceptance/partial_mocks_test.rb +4 -6
  124. data/test/acceptance/prepend_test.rb +14 -16
  125. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +77 -0
  126. data/test/acceptance/raise_exception_test.rb +2 -4
  127. data/test/acceptance/return_value_test.rb +0 -2
  128. data/test/acceptance/sequence_test.rb +9 -11
  129. data/test/acceptance/states_test.rb +6 -4
  130. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +33 -2
  131. data/test/acceptance/stub_any_instance_method_test.rb +19 -17
  132. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +8 -8
  133. data/test/acceptance/stub_class_method_defined_on_class_test.rb +2 -1
  134. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -1
  135. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +34 -1
  136. data/test/acceptance/stub_everything_test.rb +1 -3
  137. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +6 -7
  138. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -1
  139. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -1
  140. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +63 -1
  141. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -1
  142. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +2 -1
  143. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -2
  144. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -1
  145. data/test/acceptance/stub_module_method_test.rb +13 -13
  146. data/test/acceptance/stub_test.rb +1 -3
  147. data/test/acceptance/stubba_example_test.rb +6 -14
  148. data/test/acceptance/stubba_test_result_test.rb +5 -8
  149. data/test/acceptance/stubbing_error_backtrace_test.rb +2 -2
  150. data/test/acceptance/stubbing_frozen_object_test.rb +2 -1
  151. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +12 -7
  152. data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -2
  153. data/test/acceptance/stubbing_nil_test.rb +4 -5
  154. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +1 -3
  155. data/test/acceptance/stubbing_non_existent_class_method_test.rb +3 -3
  156. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +1 -3
  157. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -2
  158. data/test/acceptance/stubbing_non_public_class_method_test.rb +3 -3
  159. data/test/acceptance/stubbing_non_public_instance_method_test.rb +1 -3
  160. data/test/acceptance/stubbing_on_non_mock_object_test.rb +4 -10
  161. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +3 -4
  162. data/test/acceptance/throw_test.rb +0 -2
  163. data/test/acceptance/unexpected_invocation_test.rb +2 -3
  164. data/test/acceptance/unstubbing_test.rb +41 -14
  165. data/test/deprecation_disabler.rb +0 -1
  166. data/test/execution_point.rb +2 -4
  167. data/test/integration/mini_test_test.rb +2 -2
  168. data/test/integration/shared_tests.rb +24 -22
  169. data/test/integration/test_unit_test.rb +2 -2
  170. data/test/method_definer.rb +1 -3
  171. data/test/mini_test_result.rb +17 -11
  172. data/test/minitest_result.rb +0 -1
  173. data/test/simple_counter.rb +0 -2
  174. data/test/test_helper.rb +13 -5
  175. data/test/test_runner.rb +2 -4
  176. data/test/test_unit_result.rb +4 -2
  177. data/test/unit/any_instance_method_test.rb +31 -17
  178. data/test/unit/array_inspect_test.rb +2 -4
  179. data/test/unit/backtrace_filter_test.rb +3 -5
  180. data/test/unit/cardinality_test.rb +0 -2
  181. data/test/unit/central_test.rb +26 -27
  182. data/test/unit/change_state_side_effect_test.rb +0 -4
  183. data/test/unit/class_method_test.rb +59 -34
  184. data/test/unit/class_methods_test.rb +34 -5
  185. data/test/unit/configuration_test.rb +1 -2
  186. data/test/unit/date_time_inspect_test.rb +1 -3
  187. data/test/unit/exception_raiser_test.rb +0 -2
  188. data/test/unit/expectation_list_test.rb +0 -2
  189. data/test/unit/expectation_test.rb +41 -46
  190. data/test/unit/hash_inspect_test.rb +3 -5
  191. data/test/unit/hooks_test.rb +14 -8
  192. data/test/unit/in_state_ordering_constraint_test.rb +0 -4
  193. data/test/unit/method_matcher_test.rb +1 -3
  194. data/test/unit/mock_test.rb +35 -22
  195. data/test/unit/mockery_test.rb +45 -28
  196. data/test/unit/module_methods_test.rb +0 -2
  197. data/test/unit/multiple_yields_test.rb +0 -2
  198. data/test/unit/no_yields_test.rb +0 -2
  199. data/test/unit/object_inspect_test.rb +16 -7
  200. data/test/unit/object_methods_test.rb +22 -6
  201. data/test/unit/parameter_matchers/all_of_test.rb +0 -2
  202. data/test/unit/parameter_matchers/any_of_test.rb +0 -2
  203. data/test/unit/parameter_matchers/anything_test.rb +2 -4
  204. data/test/unit/parameter_matchers/equals_test.rb +1 -3
  205. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -1
  206. data/test/unit/parameter_matchers/has_entries_test.rb +2 -2
  207. data/test/unit/parameter_matchers/has_entry_test.rb +13 -14
  208. data/test/unit/parameter_matchers/has_key_test.rb +0 -1
  209. data/test/unit/parameter_matchers/has_value_test.rb +0 -2
  210. data/test/unit/parameter_matchers/includes_test.rb +8 -9
  211. data/test/unit/parameter_matchers/instance_of_test.rb +1 -3
  212. data/test/unit/parameter_matchers/is_a_test.rb +1 -3
  213. data/test/unit/parameter_matchers/kind_of_test.rb +1 -3
  214. data/test/unit/parameter_matchers/not_test.rb +0 -2
  215. data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -2
  216. data/test/unit/parameter_matchers/responds_with_test.rb +9 -3
  217. data/test/unit/parameter_matchers/stub_matcher.rb +0 -4
  218. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +1 -3
  219. data/test/unit/parameters_matcher_test.rb +2 -4
  220. data/test/unit/receivers_test.rb +35 -5
  221. data/test/unit/return_values_test.rb +3 -5
  222. data/test/unit/sequence_test.rb +1 -5
  223. data/test/unit/single_return_value_test.rb +0 -2
  224. data/test/unit/single_yield_test.rb +0 -2
  225. data/test/unit/state_machine_test.rb +1 -3
  226. data/test/unit/string_inspect_test.rb +2 -4
  227. data/test/unit/thrower_test.rb +0 -2
  228. data/test/unit/yield_parameters_test.rb +0 -2
  229. data/yard-templates/default/layout/html/setup.rb +2 -3
  230. metadata +25 -6
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -67,7 +66,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
67
66
  def test_should_allow_stubbing_method_to_which_any_instance_responds
68
67
  Mocha::Configuration.prevent(:stubbing_non_existent_method)
69
68
  klass = Class.new do
70
- def respond_to?(method, include_private = false)
69
+ def respond_to?(method, _include_private = false)
71
70
  (method == :method_to_which_instance_responds)
72
71
  end
73
72
  end
@@ -139,5 +138,4 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
139
138
  end
140
139
  assert_passed(test_result)
141
140
  end
142
-
143
141
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingNonExistentClassMethodTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -52,6 +51,7 @@ class StubbingNonExistentClassMethodTest < Mocha::TestCase
52
51
  assert_passed(test_result)
53
52
  end
54
53
 
54
+ # rubocop:disable Lint/DuplicateMethods
55
55
  def test_should_allow_stubbing_existing_public_class_method
56
56
  Mocha::Configuration.prevent(:stubbing_non_existent_method)
57
57
  klass = Class.new do
@@ -70,7 +70,7 @@ class StubbingNonExistentClassMethodTest < Mocha::TestCase
70
70
  Mocha::Configuration.prevent(:stubbing_non_existent_method)
71
71
  klass = Class.new do
72
72
  class << self
73
- def respond_to?(method, include_private = false)
73
+ def respond_to?(method, _include_private = false)
74
74
  (method == :method_to_which_class_responds)
75
75
  end
76
76
  end
@@ -153,5 +153,5 @@ class StubbingNonExistentClassMethodTest < Mocha::TestCase
153
153
  end
154
154
  assert_passed(test_result)
155
155
  end
156
-
156
+ # rubocop:enable Lint/DuplicateMethods
157
157
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingNonExistentInstanceMethodTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -68,7 +67,7 @@ class StubbingNonExistentInstanceMethodTest < Mocha::TestCase
68
67
  def test_should_allow_stubbing_method_to_which_instance_responds
69
68
  Mocha::Configuration.prevent(:stubbing_non_existent_method)
70
69
  klass = Class.new do
71
- def respond_to?(method, include_private = false)
70
+ def respond_to?(method, _include_private = false)
72
71
  (method == :method_to_which_instance_responds)
73
72
  end
74
73
  end
@@ -143,5 +142,4 @@ class StubbingNonExistentInstanceMethodTest < Mocha::TestCase
143
142
  end
144
143
  assert_passed(test_result)
145
144
  end
146
-
147
145
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -126,5 +125,4 @@ class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
126
125
  end
127
126
  assert_passed(test_result)
128
127
  end
129
-
130
128
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingNonPublicClassMethodTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -13,6 +12,7 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
13
12
  teardown_acceptance_test
14
13
  end
15
14
 
15
+ # rubocop:disable Lint/DuplicateMethods
16
16
  def test_should_allow_stubbing_private_class_method
17
17
  Mocha::Configuration.allow(:stubbing_non_public_method)
18
18
  klass = Class.new do
@@ -144,12 +144,13 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
144
144
  end
145
145
  assert_passed(test_result)
146
146
  end
147
+ # rubocop:enable Lint/DuplicateMethods
147
148
 
148
149
  def test_should_allow_stubbing_method_to_which_class_responds
149
150
  Mocha::Configuration.prevent(:stubbing_non_public_method)
150
151
  klass = Class.new do
151
152
  class << self
152
- def respond_to?(method, include_private_methods = false)
153
+ def respond_to?(method, _include_private_methods = false)
153
154
  (method == :method_to_which_class_responds)
154
155
  end
155
156
  end
@@ -159,5 +160,4 @@ class StubbingNonPublicClassMethodTest < Mocha::TestCase
159
160
  end
160
161
  assert_passed(test_result)
161
162
  end
162
-
163
163
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -130,7 +129,7 @@ class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
130
129
  def test_should_allow_stubbing_method_to_which_instance_responds
131
130
  Mocha::Configuration.prevent(:stubbing_non_public_method)
132
131
  instance = Class.new do
133
- def respond_to?(method, include_private_methods = false)
132
+ def respond_to?(method, _include_private_methods = false)
134
133
  (method == :method_to_which_instance_responds)
135
134
  end
136
135
  end.new
@@ -139,5 +138,4 @@ class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
139
138
  end
140
139
  assert_passed(test_result)
141
140
  end
142
-
143
141
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingOnNonMockObjectTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -16,8 +15,7 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
16
15
  def test_should_allow_stubbing_method_on_non_mock_object
17
16
  Mocha::Configuration.allow(:stubbing_method_on_non_mock_object)
18
17
  non_mock_object = Class.new do
19
- def existing_method
20
- end
18
+ def existing_method; end
21
19
  end
22
20
  test_result = run_as_test do
23
21
  non_mock_object.stubs(:existing_method)
@@ -29,8 +27,7 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
29
27
  def test_should_warn_on_stubbing_method_on_non_mock_object
30
28
  Mocha::Configuration.warn_when(:stubbing_method_on_non_mock_object)
31
29
  non_mock_object = Class.new do
32
- def existing_method
33
- end
30
+ def existing_method; end
34
31
  end
35
32
  test_result = run_as_test do
36
33
  non_mock_object.stubs(:existing_method)
@@ -42,8 +39,7 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
42
39
  def test_should_prevent_stubbing_method_on_non_mock_object
43
40
  Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object)
44
41
  non_mock_object = Class.new do
45
- def existing_method
46
- end
42
+ def existing_method; end
47
43
  end
48
44
  test_result = run_as_test do
49
45
  non_mock_object.stubs(:existing_method)
@@ -54,8 +50,7 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
54
50
 
55
51
  def test_should_default_to_allow_stubbing_method_on_non_mock_object
56
52
  non_mock_object = Class.new do
57
- def existing_method
58
- end
53
+ def existing_method; end
59
54
  end
60
55
  test_result = run_as_test do
61
56
  non_mock_object.stubs(:existing_method)
@@ -72,5 +67,4 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
72
67
  end
73
68
  assert_passed(test_result)
74
69
  end
75
-
76
70
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingSameClassMethodOnParentAndChildClassTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -16,14 +15,14 @@ class StubbingSameClassMethodOnParentAndChildClassTest < Mocha::TestCase
16
15
  def test_stubbing_same_method_on_parent_and_child_classes
17
16
  parent_class = Class.new do
18
17
  def self.foo
19
- "Parent.foo"
18
+ 'Parent.foo'
20
19
  end
21
20
  end
22
21
  child_class = Class.new(parent_class)
23
22
  test_result = run_as_tests(
24
23
  :test_1 => lambda {
25
- parent_class.stubs(:foo).returns("stubbed Parent.foo")
26
- child_class.stubs(:foo).returns("stubbed Child.foo")
24
+ parent_class.stubs(:foo).returns('stubbed Parent.foo')
25
+ child_class.stubs(:foo).returns('stubbed Child.foo')
27
26
  },
28
27
  :test_2 => lambda {
29
28
  parent_class.foo
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class ThrowTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -41,5 +40,4 @@ class ThrowTest < Mocha::TestCase
41
40
  end
42
41
  assert_passed(test_result)
43
42
  end
44
-
45
43
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class UnexpectedInvocationTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -20,6 +19,6 @@ class UnexpectedInvocationTest < Mocha::TestCase
20
19
  instance.inspect(1, 2, 'foo')
21
20
  end
22
21
  assert_failed(test_result)
23
- assert_equal "unexpected invocation: inspect(1, 2, foo)", test_result.failure_message_lines[0]
22
+ assert_equal 'unexpected invocation: inspect(1, 2, foo)', test_result.failure_message_lines[0]
24
23
  end
25
- end
24
+ end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class UnstubbingTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -15,7 +14,9 @@ class UnstubbingTest < Mocha::TestCase
15
14
 
16
15
  def test_unstubbing_an_instance_method_should_restore_original_behaviour
17
16
  klass = Class.new do
18
- def my_instance_method; :original_return_value; end
17
+ def my_instance_method
18
+ :original_return_value
19
+ end
19
20
  end
20
21
  test_result = run_as_test do
21
22
  object = klass.new
@@ -28,7 +29,9 @@ class UnstubbingTest < Mocha::TestCase
28
29
 
29
30
  def test_unstubbing_a_class_method_should_restore_original_behaviour
30
31
  klass = Class.new do
31
- def self.my_class_method; :original_return_value; end
32
+ def self.my_class_method
33
+ :original_return_value
34
+ end
32
35
  end
33
36
  test_result = run_as_test do
34
37
  klass.stubs(:my_class_method).returns(:new_return_value)
@@ -40,7 +43,9 @@ class UnstubbingTest < Mocha::TestCase
40
43
 
41
44
  def test_unstubbing_a_module_method_should_restore_original_behaviour
42
45
  mod = Module.new do
43
- def self.my_module_method; :original_return_value; end
46
+ def self.my_module_method
47
+ :original_return_value
48
+ end
44
49
  end
45
50
  test_result = run_as_test do
46
51
  mod.stubs(:my_module_method).returns(:new_return_value)
@@ -52,7 +57,9 @@ class UnstubbingTest < Mocha::TestCase
52
57
 
53
58
  def test_unstubbing_a_module_method_defined_like_fileutils_in_ruby_2_0_should_restore_original_behaviour
54
59
  mod = Module.new do
55
- def my_module_method; :original_return_value; end
60
+ def my_module_method
61
+ :original_return_value
62
+ end
56
63
  private :my_module_method
57
64
  extend self
58
65
  class << self
@@ -69,7 +76,9 @@ class UnstubbingTest < Mocha::TestCase
69
76
 
70
77
  def test_unstubbing_an_any_instance_method_should_restore_original_behaviour
71
78
  klass = Class.new do
72
- def my_instance_method; :original_return_value; end
79
+ def my_instance_method
80
+ :original_return_value
81
+ end
73
82
  end
74
83
  test_result = run_as_test do
75
84
  object = klass.new
@@ -82,8 +91,13 @@ class UnstubbingTest < Mocha::TestCase
82
91
 
83
92
  def test_unstubbing_multiple_methods_should_restore_original_behaviour
84
93
  klass = Class.new do
85
- def my_first_instance_method; :original_return_value; end
86
- def my_second_instance_method; :original_return_value; end
94
+ def my_first_instance_method
95
+ :original_return_value
96
+ end
97
+
98
+ def my_second_instance_method
99
+ :original_return_value
100
+ end
87
101
  end
88
102
  test_result = run_as_test do
89
103
  object = klass.new
@@ -98,7 +112,9 @@ class UnstubbingTest < Mocha::TestCase
98
112
 
99
113
  def test_unstubbing_a_method_multiple_times_should_restore_original_behaviour
100
114
  klass = Class.new do
101
- def my_instance_method; :original_return_value; end
115
+ def my_instance_method
116
+ :original_return_value
117
+ end
102
118
  end
103
119
  test_result = run_as_test do
104
120
  object = klass.new
@@ -112,7 +128,9 @@ class UnstubbingTest < Mocha::TestCase
112
128
 
113
129
  def test_unstubbing_a_non_stubbed_method_should_do_nothing
114
130
  klass = Class.new do
115
- def my_instance_method; :original_return_value; end
131
+ def my_instance_method
132
+ :original_return_value
133
+ end
116
134
  end
117
135
  test_result = run_as_test do
118
136
  object = klass.new
@@ -124,7 +142,9 @@ class UnstubbingTest < Mocha::TestCase
124
142
 
125
143
  def test_unstubbing_a_method_which_was_stubbed_multiple_times_should_restore_orginal_behaviour
126
144
  klass = Class.new do
127
- def my_instance_method; :original_return_value; end
145
+ def my_instance_method
146
+ :original_return_value
147
+ end
128
148
  end
129
149
  test_result = run_as_test do
130
150
  object = klass.new
@@ -138,8 +158,13 @@ class UnstubbingTest < Mocha::TestCase
138
158
 
139
159
  def test_unstubbing_a_method_should_not_unstub_other_stubbed_methods
140
160
  klass = Class.new do
141
- def my_first_instance_method; :first_return_value; end
142
- def my_second_instance_method; :second_return_value; end
161
+ def my_first_instance_method
162
+ :first_return_value
163
+ end
164
+
165
+ def my_second_instance_method
166
+ :second_return_value
167
+ end
143
168
  end
144
169
 
145
170
  test_result = run_as_test do
@@ -155,7 +180,9 @@ class UnstubbingTest < Mocha::TestCase
155
180
 
156
181
  def test_unstubbing_a_method_should_remove_all_expectations_for_that_method
157
182
  klass = Class.new do
158
- def my_instance_method; :original_return_value; end
183
+ def my_instance_method
184
+ :original_return_value
185
+ end
159
186
  end
160
187
  test_result = run_as_test do
161
188
  object = klass.new
@@ -1,7 +1,6 @@
1
1
  require 'mocha/deprecation'
2
2
 
3
3
  module DeprecationDisabler
4
-
5
4
  def disable_deprecations
6
5
  original_mode = Mocha::Deprecation.mode
7
6
  Mocha::Deprecation.mode = :disabled
@@ -1,5 +1,4 @@
1
1
  class ExecutionPoint
2
-
3
2
  attr_reader :backtrace
4
3
 
5
4
  def self.current
@@ -11,7 +10,7 @@ class ExecutionPoint
11
10
  end
12
11
 
13
12
  def first_relevant_line_of_backtrace
14
- @backtrace && (@backtrace.reject { |l| /\Aorg\/jruby\//.match(l) }.first || 'unknown:0')
13
+ @backtrace && (@backtrace.reject { |l| %r{\Aorg/jruby/}.match(l) }.first || 'unknown:0')
15
14
  end
16
15
 
17
16
  def file_name
@@ -24,7 +23,7 @@ class ExecutionPoint
24
23
 
25
24
  def ==(other)
26
25
  return false unless other.is_a?(ExecutionPoint)
27
- (file_name == other.file_name) and (line_number == other.line_number)
26
+ (file_name == other.file_name) && (line_number == other.line_number)
28
27
  end
29
28
 
30
29
  def to_s
@@ -34,5 +33,4 @@ class ExecutionPoint
34
33
  def inspect
35
34
  to_s
36
35
  end
37
-
38
36
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
- require "mocha/minitest"
4
- require "integration/shared_tests"
3
+ require 'mocha/minitest'
4
+ require 'integration/shared_tests'
5
5
 
6
6
  class MiniTestTest < Mocha::TestCase
7
7
  include SharedTests
@@ -11,6 +11,7 @@ module SharedTests
11
11
  assert_passed(test_result)
12
12
  end
13
13
 
14
+ # rubocop:disable Style/Semicolon
14
15
  def test_assertion_unsatisfied
15
16
  execution_point = nil
16
17
  test_result = run_as_test do
@@ -24,19 +25,19 @@ module SharedTests
24
25
  def test_mock_object_unexpected_invocation
25
26
  execution_point = nil
26
27
  test_result = run_as_test do
27
- mock = mock("not expecting invocation")
28
+ mock = mock('not expecting invocation')
28
29
  execution_point = ExecutionPoint.current; mock.unexpected
29
30
  end
30
31
  assert_failed(test_result)
31
32
  failure = test_result.failures.first
32
33
  assert_equal execution_point, ExecutionPoint.new(failure.location)
33
- assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
34
+ assert_equal ['unexpected invocation: #<Mock:not expecting invocation>.unexpected()'], test_result.failure_message_lines
34
35
  end
35
36
 
36
37
  def test_mock_object_explicitly_unexpected_invocation
37
38
  execution_point = nil
38
39
  test_result = run_as_test do
39
- mock = mock("not expecting invocation")
40
+ mock = mock('not expecting invocation')
40
41
  mock.expects(:unexpected).never
41
42
  execution_point = ExecutionPoint.current; mock.unexpected
42
43
  end
@@ -44,25 +45,25 @@ module SharedTests
44
45
  failure = test_result.failures.first
45
46
  assert_equal execution_point, ExecutionPoint.new(failure.location)
46
47
  assert_equal [
47
- "unexpected invocation: #<Mock:not expecting invocation>.unexpected()",
48
- "unsatisfied expectations:",
49
- "- expected never, invoked once: #<Mock:not expecting invocation>.unexpected(any_parameters)"
48
+ 'unexpected invocation: #<Mock:not expecting invocation>.unexpected()',
49
+ 'unsatisfied expectations:',
50
+ '- expected never, invoked once: #<Mock:not expecting invocation>.unexpected(any_parameters)'
50
51
  ], test_result.failure_message_lines
51
52
  end
52
53
 
53
54
  def test_mock_object_unsatisfied_expectation
54
55
  execution_point = nil
55
56
  test_result = run_as_test do
56
- mock = mock("expecting invocation")
57
+ mock = mock('expecting invocation')
57
58
  execution_point = ExecutionPoint.current; mock.expects(:expected)
58
59
  end
59
60
  assert_failed(test_result)
60
61
  failure = test_result.failures.first
61
62
  assert_equal execution_point, ExecutionPoint.new(failure.location)
62
63
  assert_equal [
63
- "not all expectations were satisfied",
64
- "unsatisfied expectations:",
65
- "- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)"
64
+ 'not all expectations were satisfied',
65
+ 'unsatisfied expectations:',
66
+ '- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)'
66
67
  ], test_result.failure_message_lines
67
68
  end
68
69
 
@@ -70,7 +71,7 @@ module SharedTests
70
71
  execution_point = nil
71
72
  test_result = run_as_tests(
72
73
  :setup => lambda {
73
- mock = mock("not expecting invocation")
74
+ mock = mock('not expecting invocation')
74
75
  execution_point = ExecutionPoint.current; mock.unexpected
75
76
  },
76
77
  :test_me => lambda {
@@ -80,14 +81,14 @@ module SharedTests
80
81
  assert_failed(test_result)
81
82
  failure = test_result.failures.first
82
83
  assert_equal execution_point, ExecutionPoint.new(failure.location)
83
- assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
84
+ assert_equal ['unexpected invocation: #<Mock:not expecting invocation>.unexpected()'], test_result.failure_message_lines
84
85
  end
85
86
 
86
87
  def test_mock_object_unsatisfied_expectation_in_setup
87
88
  execution_point = nil
88
89
  test_result = run_as_tests(
89
90
  :setup => lambda {
90
- mock = mock("expecting invocation")
91
+ mock = mock('expecting invocation')
91
92
  execution_point = ExecutionPoint.current; mock.expects(:expected)
92
93
  },
93
94
  :test_me => lambda {
@@ -98,9 +99,9 @@ module SharedTests
98
99
  failure = test_result.failures.first
99
100
  assert_equal execution_point, ExecutionPoint.new(failure.location)
100
101
  assert_equal [
101
- "not all expectations were satisfied",
102
- "unsatisfied expectations:",
103
- "- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)"
102
+ 'not all expectations were satisfied',
103
+ 'unsatisfied expectations:',
104
+ '- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)'
104
105
  ], test_result.failure_message_lines
105
106
  end
106
107
 
@@ -111,14 +112,14 @@ module SharedTests
111
112
  assert true
112
113
  },
113
114
  :teardown => lambda {
114
- mock = mock("not expecting invocation")
115
+ mock = mock('not expecting invocation')
115
116
  execution_point = ExecutionPoint.current; mock.unexpected
116
117
  }
117
118
  )
118
119
  assert_failed(test_result)
119
120
  failure = test_result.failures.first
120
121
  assert_equal execution_point, ExecutionPoint.new(failure.location)
121
- assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
122
+ assert_equal ['unexpected invocation: #<Mock:not expecting invocation>.unexpected()'], test_result.failure_message_lines
122
123
  end
123
124
 
124
125
  def test_real_object_explicitly_unexpected_invocation
@@ -133,7 +134,7 @@ module SharedTests
133
134
  assert_equal execution_point, ExecutionPoint.new(failure.location)
134
135
  assert_equal [
135
136
  "unexpected invocation: #{object.mocha_inspect}.unexpected()",
136
- "unsatisfied expectations:",
137
+ 'unsatisfied expectations:',
137
138
  "- expected never, invoked once: #{object.mocha_inspect}.unexpected(any_parameters)"
138
139
  ], test_result.failure_message_lines
139
140
  end
@@ -148,8 +149,8 @@ module SharedTests
148
149
  failure = test_result.failures.first
149
150
  assert_equal execution_point, ExecutionPoint.new(failure.location)
150
151
  assert_equal [
151
- "not all expectations were satisfied",
152
- "unsatisfied expectations:",
152
+ 'not all expectations were satisfied',
153
+ 'unsatisfied expectations:',
153
154
  "- expected exactly once, not yet invoked: #{object.mocha_inspect}.expected(any_parameters)"
154
155
  ], test_result.failure_message_lines
155
156
  end
@@ -169,6 +170,7 @@ module SharedTests
169
170
  assert_failed(test_result)
170
171
  exception = test_result.errors.first.exception
171
172
  assert_equal execution_point, ExecutionPoint.new(exception.backtrace)
172
- assert_match %r{undefined method `foo'}, exception.message
173
+ assert_match(/undefined method `foo'/, exception.message)
173
174
  end
175
+ # rubocop:enable Style/Semicolon
174
176
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
- require "mocha/test_unit"
4
- require "integration/shared_tests"
3
+ require 'mocha/test_unit'
4
+ require 'integration/shared_tests'
5
5
 
6
6
  class TestUnitTest < Mocha::TestCase
7
7
  include SharedTests
@@ -1,14 +1,13 @@
1
1
  require 'metaclass'
2
2
 
3
3
  module Mocha
4
-
5
4
  module ObjectMethods
6
5
  def define_instance_method(method_symbol, &block)
7
6
  __metaclass__.send(:define_method, method_symbol, block)
8
7
  end
9
8
 
10
9
  def replace_instance_method(method_symbol, &block)
11
- raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless self.respond_to?(method_symbol)
10
+ raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless respond_to?(method_symbol)
12
11
  define_instance_method(method_symbol, &block)
13
12
  end
14
13
 
@@ -16,7 +15,6 @@ module Mocha
16
15
  symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) }
17
16
  end
18
17
  end
19
-
20
18
  end
21
19
 
22
20
  class Object