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 StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -13,6 +12,7 @@ class StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
13
12
  teardown_acceptance_test
14
13
  end
15
14
 
15
+ # rubocop:disable Lint/DuplicateMethods
16
16
  def test_should_stub_public_method_on_child_class_and_leave_it_unchanged_after_test
17
17
  superklass = Class.new do
18
18
  class << self
@@ -109,4 +109,37 @@ class StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
109
109
  end
110
110
  assert_passed(test_result)
111
111
  end
112
+
113
+ def test_expect_method_on_superclass_even_if_preceded_by_test_expecting_method_on_subclass
114
+ superklass = Class.new do
115
+ def self.inspect
116
+ 'superklass'
117
+ end
118
+
119
+ def self.my_class_method; end
120
+ end
121
+ klass = Class.new(superklass) do
122
+ def self.inspect
123
+ 'klass'
124
+ end
125
+
126
+ def self.my_class_method; end
127
+ end
128
+ test_result = run_as_tests(
129
+ :test_1 => lambda {
130
+ klass.expects(:my_class_method)
131
+ klass.my_class_method
132
+ },
133
+ :test_2 => lambda {
134
+ superklass.expects(:my_class_method)
135
+ }
136
+ )
137
+ assert_failed(test_result)
138
+ assert_equal [
139
+ 'not all expectations were satisfied',
140
+ 'unsatisfied expectations:',
141
+ '- expected exactly once, not yet invoked: superklass.my_class_method(any_parameters)'
142
+ ], test_result.failure_message_lines
143
+ end
144
+ # rubocop:enable Lint/DuplicateMethods
112
145
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubEverythingTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -15,7 +14,7 @@ class StubEverythingTest < Mocha::TestCase
15
14
 
16
15
  def test_should_build_stub_and_explicitly_add_an_expectation
17
16
  test_result = run_as_test do
18
- foo = stub_everything()
17
+ foo = stub_everything
19
18
  foo.stubs(:bar)
20
19
  foo.bar
21
20
  foo.unexpected_invocation
@@ -52,5 +51,4 @@ class StubEverythingTest < Mocha::TestCase
52
51
  end
53
52
  assert_passed(test_result)
54
53
  end
55
-
56
54
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -15,7 +14,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
15
14
 
16
15
  def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_exist
17
16
  ruby18_instance = Class.new do
18
- def public_methods(include_superclass = true)
17
+ def public_methods(_include_superclass = true)
19
18
  ['my_instance_method']
20
19
  end
21
20
  end.new
@@ -28,7 +27,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
28
27
 
29
28
  def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_exist
30
29
  ruby19_instance = Class.new do
31
- def public_methods(include_superclass = true)
30
+ def public_methods(_include_superclass = true)
32
31
  [:my_instance_method]
33
32
  end
34
33
  end.new
@@ -41,7 +40,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
41
40
 
42
41
  def test_should_be_able_to_stub_method_if_ruby18_protected_methods_include_method_but_method_does_not_exist
43
42
  ruby18_instance = Class.new do
44
- def protected_methods(include_superclass = true)
43
+ def protected_methods(_include_superclass = true)
45
44
  ['my_instance_method']
46
45
  end
47
46
  end.new
@@ -54,7 +53,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
54
53
 
55
54
  def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_exist
56
55
  ruby19_instance = Class.new do
57
- def protected_methods(include_superclass = true)
56
+ def protected_methods(_include_superclass = true)
58
57
  [:my_instance_method]
59
58
  end
60
59
  end.new
@@ -67,7 +66,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
67
66
 
68
67
  def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_exist
69
68
  ruby18_instance = Class.new do
70
- def private_methods(include_superclass = true)
69
+ def private_methods(_include_superclass = true)
71
70
  ['my_instance_method']
72
71
  end
73
72
  end.new
@@ -80,7 +79,7 @@ class StubInstanceMethodDefinedOnActiveRecordAssociationProxyTest < Mocha::TestC
80
79
 
81
80
  def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_exist
82
81
  ruby19_instance = Class.new do
83
- def private_methods(include_superclass = true)
82
+ def private_methods(_include_superclass = true)
84
83
  [:my_instance_method]
85
84
  end
86
85
  end.new
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubInstanceMethodDefinedOnClassAndAliasedTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubInstanceMethodDefinedOnClassTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubInstanceMethodDefinedOnKernelModuleTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -72,4 +71,67 @@ class StubInstanceMethodDefinedOnKernelModuleTest < Mocha::TestCase
72
71
  ensure
73
72
  Kernel.module_eval { remove_method :my_instance_method }
74
73
  end
74
+
75
+ def test_should_stub_public_module_method_and_leave_it_unchanged_after_test
76
+ Kernel.module_eval do
77
+ def my_instance_method
78
+ :original_return_value
79
+ end
80
+ public :my_instance_method
81
+ end
82
+ mod = Module.new
83
+ assert_snapshot_unchanged(mod) do
84
+ test_result = run_as_test do
85
+ mod.stubs(:my_instance_method).returns(:new_return_value)
86
+ assert_method_visibility mod, :my_instance_method, :public
87
+ assert_equal :new_return_value, mod.my_instance_method
88
+ end
89
+ assert_passed(test_result)
90
+ end
91
+ assert_equal :original_return_value, mod.my_instance_method
92
+ ensure
93
+ Kernel.module_eval { remove_method :my_instance_method }
94
+ end
95
+
96
+ def test_should_stub_protected_module_method_and_leave_it_unchanged_after_test
97
+ Kernel.module_eval do
98
+ def my_instance_method
99
+ :original_return_value
100
+ end
101
+ protected :my_instance_method
102
+ end
103
+ mod = Module.new
104
+ assert_snapshot_unchanged(mod) do
105
+ test_result = run_as_test do
106
+ mod.stubs(:my_instance_method).returns(:new_return_value)
107
+ assert_method_visibility mod, :my_instance_method, :protected
108
+ assert_equal :new_return_value, mod.send(:my_instance_method)
109
+ end
110
+ assert_passed(test_result)
111
+ end
112
+ assert_equal :original_return_value, mod.send(:my_instance_method)
113
+ ensure
114
+ Kernel.module_eval { remove_method :my_instance_method }
115
+ end
116
+
117
+ def test_should_stub_private_module_method_and_leave_it_unchanged_after_test
118
+ Kernel.module_eval do
119
+ def my_instance_method
120
+ :original_return_value
121
+ end
122
+ private :my_instance_method
123
+ end
124
+ mod = Module.new
125
+ assert_snapshot_unchanged(mod) do
126
+ test_result = run_as_test do
127
+ mod.stubs(:my_instance_method).returns(:new_return_value)
128
+ assert_method_visibility mod, :my_instance_method, :private
129
+ assert_equal :new_return_value, mod.send(:my_instance_method)
130
+ end
131
+ assert_passed(test_result)
132
+ end
133
+ assert_equal :original_return_value, mod.send(:my_instance_method)
134
+ ensure
135
+ Kernel.module_eval { remove_method :my_instance_method }
136
+ end
75
137
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubInstanceMethodDefinedOnModuleTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubInstanceMethodDefinedOnObjectClassTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -13,6 +12,7 @@ class StubInstanceMethodDefinedOnObjectClassTest < Mocha::TestCase
13
12
  teardown_acceptance_test
14
13
  end
15
14
 
15
+ # rubocop:disable Lint/DuplicateMethods
16
16
  def test_should_stub_public_method_and_leave_it_unchanged_after_test
17
17
  Object.class_eval do
18
18
  def my_instance_method
@@ -72,4 +72,5 @@ class StubInstanceMethodDefinedOnObjectClassTest < Mocha::TestCase
72
72
  ensure
73
73
  Object.class_eval { remove_method :my_instance_method }
74
74
  end
75
+ # rubocop:enable Lint/DuplicateMethods
75
76
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubInstanceMethodDefinedOnSingletonClassTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -66,5 +65,4 @@ class StubInstanceMethodDefinedOnSingletonClassTest < Mocha::TestCase
66
65
  end
67
66
  assert_equal :original_return_value, instance.send(:my_singleton_method)
68
67
  end
69
-
70
68
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubInstanceMethodDefinedOnSuperclassTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubModuleMethodTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -13,6 +12,7 @@ class StubModuleMethodTest < Mocha::TestCase
13
12
  teardown_acceptance_test
14
13
  end
15
14
 
15
+ # rubocop:disable Lint/DuplicateMethods
16
16
  def test_should_stub_method_within_test
17
17
  mod = Module.new do
18
18
  def self.my_module_method
@@ -38,7 +38,7 @@ class StubModuleMethodTest < Mocha::TestCase
38
38
  run_as_test do
39
39
  mod.stubs(:my_module_method).returns(:new_return_value)
40
40
  end
41
- assert mod.public_methods(false).any? { |m| m.to_s == 'my_module_method' }
41
+ assert(mod.public_methods(false).any? { |m| m.to_s == 'my_module_method' })
42
42
  assert_equal :original_return_value, mod.my_module_method
43
43
  end
44
44
 
@@ -57,7 +57,7 @@ class StubModuleMethodTest < Mocha::TestCase
57
57
  run_as_test do
58
58
  mod.stubs(:my_module_method).returns(:new_return_value)
59
59
  end
60
- assert mod.protected_methods(false).any? { |m| m.to_s == 'my_module_method' }
60
+ assert(mod.protected_methods(false).any? { |m| m.to_s == 'my_module_method' })
61
61
  assert_equal :original_return_value, mod.my_unprotected_module_method
62
62
  end
63
63
 
@@ -73,7 +73,7 @@ class StubModuleMethodTest < Mocha::TestCase
73
73
  run_as_test do
74
74
  mod.stubs(:my_module_method).returns(:new_return_value)
75
75
  end
76
- assert mod.private_methods(false).any? { |m| m.to_s == 'my_module_method' }
76
+ assert(mod.private_methods(false).any? { |m| m.to_s == 'my_module_method' })
77
77
  assert_equal :original_return_value, mod.send(:my_module_method)
78
78
  end
79
79
 
@@ -103,15 +103,15 @@ class StubModuleMethodTest < Mocha::TestCase
103
103
  assert_equal :new_return_value, mod.my_superclass_method
104
104
  end
105
105
  assert_passed(test_result)
106
- assert supermod.public_methods.any? { |m| m.to_s == 'my_superclass_method' }
107
- assert !mod.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' }
106
+ assert(supermod.public_methods.any? { |m| m.to_s == 'my_superclass_method' })
107
+ assert(mod.public_methods(false).none? { |m| m.to_s == 'my_superclass_method' })
108
108
  assert_equal :original_return_value, supermod.my_superclass_method
109
109
  end
110
110
 
111
111
  def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
112
112
  ruby18_mod = Module.new do
113
113
  class << self
114
- def public_methods(include_superclass = true)
114
+ def public_methods(_include_superclass = true)
115
115
  ['my_module_method']
116
116
  end
117
117
  end
@@ -126,7 +126,7 @@ class StubModuleMethodTest < Mocha::TestCase
126
126
  def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
127
127
  ruby19_mod = Module.new do
128
128
  class << self
129
- def public_methods(include_superclass = true)
129
+ def public_methods(_include_superclass = true)
130
130
  [:my_module_method]
131
131
  end
132
132
  end
@@ -141,7 +141,7 @@ class StubModuleMethodTest < Mocha::TestCase
141
141
  def test_should_be_able_to_stub_method_if_ruby_18_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
142
142
  ruby18_mod = Module.new do
143
143
  class << self
144
- def protected_methods(include_superclass = true)
144
+ def protected_methods(_include_superclass = true)
145
145
  ['my_module_method']
146
146
  end
147
147
  end
@@ -156,7 +156,7 @@ class StubModuleMethodTest < Mocha::TestCase
156
156
  def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
157
157
  ruby19_mod = Module.new do
158
158
  class << self
159
- def protected_methods(include_superclass = true)
159
+ def protected_methods(_include_superclass = true)
160
160
  [:my_module_method]
161
161
  end
162
162
  end
@@ -171,7 +171,7 @@ class StubModuleMethodTest < Mocha::TestCase
171
171
  def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
172
172
  ruby18_mod = Module.new do
173
173
  class << self
174
- def private_methods(include_superclass = true)
174
+ def private_methods(_include_superclass = true)
175
175
  ['my_module_method']
176
176
  end
177
177
  end
@@ -186,7 +186,7 @@ class StubModuleMethodTest < Mocha::TestCase
186
186
  def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
187
187
  ruby19_mod = Module.new do
188
188
  class << self
189
- def private_methods(include_superclass = true)
189
+ def private_methods(_include_superclass = true)
190
190
  [:my_module_method]
191
191
  end
192
192
  end
@@ -197,5 +197,5 @@ class StubModuleMethodTest < Mocha::TestCase
197
197
  end
198
198
  assert_passed(test_result)
199
199
  end
200
-
200
+ # rubocop:enable Lint/DuplicateMethods
201
201
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -15,7 +14,7 @@ class StubTest < Mocha::TestCase
15
14
 
16
15
  def test_should_build_stub_and_explicitly_add_an_expectation
17
16
  test_result = run_as_test do
18
- foo = stub()
17
+ foo = stub
19
18
  foo.stubs(:bar)
20
19
  foo.bar
21
20
  end
@@ -48,5 +47,4 @@ class StubTest < Mocha::TestCase
48
47
  end
49
48
  assert_passed(test_result)
50
49
  end
51
-
52
50
  end
@@ -2,35 +2,28 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class Widget
5
-
6
5
  def model
7
6
  'original_model'
8
7
  end
9
8
 
10
9
  class << self
11
-
12
- def find(options)
10
+ def find(_options)
13
11
  []
14
12
  end
15
13
 
16
- def create(attributes)
14
+ def create(_attributes)
17
15
  Widget.new
18
16
  end
19
-
20
17
  end
21
-
22
18
  end
23
19
 
24
20
  module Thingy
25
-
26
21
  def self.wotsit
27
22
  :hoojamaflip
28
23
  end
29
-
30
24
  end
31
25
 
32
26
  class StubbaExampleTest < Mocha::TestCase
33
-
34
27
  def test_should_stub_instance_method
35
28
  widget = Widget.new
36
29
  widget.expects(:model).returns('different_model')
@@ -93,10 +86,9 @@ class StubbaExampleTest < Mocha::TestCase
93
86
 
94
87
  def should_stub_instance_method_on_any_instance_of_a_class
95
88
  Widget.any_instance.expects(:model).at_least_once.returns('another_model')
96
- widget_1 = Widget.new
97
- widget_2 = Widget.new
98
- assert_equal 'another_model', widget_1.model
99
- assert_equal 'another_model', widget_2.model
89
+ widget1 = Widget.new
90
+ widget2 = Widget.new
91
+ assert_equal 'another_model', widget1.model
92
+ assert_equal 'another_model', widget2.model
100
93
  end
101
-
102
94
  end
@@ -3,7 +3,6 @@ require 'mocha/setup'
3
3
  require 'execution_point'
4
4
 
5
5
  class StubbaTestResultTest < Mocha::TestCase
6
-
7
6
  include AcceptanceTest
8
7
 
9
8
  def setup
@@ -17,8 +16,7 @@ class StubbaTestResultTest < Mocha::TestCase
17
16
  def test_should_include_expectation_verification_in_assertion_count
18
17
  test_result = run_as_test do
19
18
  object = Class.new do
20
- def message
21
- end
19
+ def message; end
22
20
  end.new
23
21
  object.expects(:message)
24
22
  object.message
@@ -36,8 +34,7 @@ class StubbaTestResultTest < Mocha::TestCase
36
34
  def test_should_not_include_stubbing_expectation_verification_in_assertion_count
37
35
  test_result = run_as_test do
38
36
  object = Class.new do
39
- def message
40
- end
37
+ def message; end
41
38
  end.new
42
39
  object.stubs(:message)
43
40
  object.message
@@ -48,8 +45,7 @@ class StubbaTestResultTest < Mocha::TestCase
48
45
  def test_should_include_expectation_verification_failure_in_failure_count
49
46
  test_result = run_as_test do
50
47
  object = Class.new do
51
- def message
52
- end
48
+ def message; end
53
49
  end.new
54
50
  object.expects(:message)
55
51
  end
@@ -63,6 +59,7 @@ class StubbaTestResultTest < Mocha::TestCase
63
59
  assert_equal 1, test_result.failure_count
64
60
  end
65
61
 
62
+ # rubocop:disable Style/Semicolon
66
63
  def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called
67
64
  execution_point = nil
68
65
  test_result = run_as_test do
@@ -71,5 +68,5 @@ class StubbaTestResultTest < Mocha::TestCase
71
68
  assert_equal 1, test_result.failure_count
72
69
  assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
73
70
  end
74
-
71
+ # rubocop:enable Style/Semicolon
75
72
  end
@@ -3,7 +3,6 @@ require 'mocha/setup'
3
3
  require 'execution_point'
4
4
 
5
5
  class StubbingErrorBacktraceTest < Mocha::TestCase
6
-
7
6
  include AcceptanceTest
8
7
 
9
8
  def setup
@@ -14,6 +13,7 @@ class StubbingErrorBacktraceTest < Mocha::TestCase
14
13
  teardown_acceptance_test
15
14
  end
16
15
 
16
+ # rubocop:disable Style/Semicolon
17
17
  def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_existent_method_was_made
18
18
  execution_point = nil
19
19
  object = Object.new
@@ -60,5 +60,5 @@ class StubbingErrorBacktraceTest < Mocha::TestCase
60
60
  assert_equal 1, test_result.error_count
61
61
  assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
62
62
  end
63
-
63
+ # rubocop:enable Style/Semicolon
64
64
  end
@@ -3,7 +3,6 @@ require 'mocha/setup'
3
3
  require 'execution_point'
4
4
 
5
5
  class StubbingFrozenObjectTest < Mocha::TestCase
6
-
7
6
  include AcceptanceTest
8
7
 
9
8
  def setup
@@ -14,6 +13,7 @@ class StubbingFrozenObjectTest < Mocha::TestCase
14
13
  teardown_acceptance_test
15
14
  end
16
15
 
16
+ # rubocop:disable Style/Semicolon
17
17
  def test_should_fail_fast_if_attempting_to_stub_method_on_frozen_object
18
18
  object = Object.new
19
19
  object.freeze
@@ -85,4 +85,5 @@ class StubbingFrozenObjectTest < Mocha::TestCase
85
85
  assert_equal 1, test_result.error_count
86
86
  assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
87
87
  end
88
+ # rubocop:enable Style/Semicolon
88
89
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingMethodAcceptingBlockParameterTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -15,34 +14,40 @@ class StubbingMethodAcceptingBlockParameterTest < Mocha::TestCase
15
14
 
16
15
  def test_stubbing_class_method_accepting_block_parameter_should_restore_original_method
17
16
  klass = Class.new do
18
- def self.my_class_method(&block); block.call; end
17
+ def self.my_class_method(&block)
18
+ block.call
19
+ end
19
20
  end
20
21
  test_result = run_as_test do
21
22
  klass.stubs(:my_class_method)
22
23
  end
23
24
  assert_passed(test_result)
24
- assert_equal :return_value, klass.my_class_method { :return_value }
25
+ assert_equal :return_value, (klass.my_class_method { :return_value })
25
26
  end
26
27
 
27
28
  def test_stubbing_instance_method_accepting_block_parameter_should_restore_original_method
28
29
  instance = Class.new do
29
- def my_instance_method(&block); block.call; end
30
+ def my_instance_method
31
+ yield
32
+ end
30
33
  end.new
31
34
  test_result = run_as_test do
32
35
  instance.stubs(:my_instance_method)
33
36
  end
34
37
  assert_passed(test_result)
35
- assert_equal :return_value, instance.my_instance_method { :return_value }
38
+ assert_equal :return_value, (instance.my_instance_method { :return_value })
36
39
  end
37
40
 
38
41
  def test_stubbing_any_instance_method_accepting_block_parameter_should_restore_original_method
39
42
  klass = Class.new do
40
- def my_instance_method(&block); block.call; end
43
+ def my_instance_method
44
+ yield
45
+ end
41
46
  end
42
47
  test_result = run_as_test do
43
48
  klass.any_instance.stubs(:my_instance_method)
44
49
  end
45
50
  assert_passed(test_result)
46
- assert_equal :return_value, klass.new.my_instance_method { :return_value }
51
+ assert_equal :return_value, (klass.new.my_instance_method { :return_value })
47
52
  end
48
53
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingMethodUnnecessarilyTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -61,5 +60,4 @@ class StubbingMethodUnnecessarilyTest < Mocha::TestCase
61
60
  end
62
61
  assert_passed(test_result)
63
62
  end
64
-
65
63
  end
@@ -2,7 +2,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
3
 
4
4
  class StubbingNilTest < Mocha::TestCase
5
-
6
5
  include AcceptanceTest
7
6
 
8
7
  def setup
@@ -20,7 +19,7 @@ class StubbingNilTest < Mocha::TestCase
20
19
  nil.stubs(:stubbed_method)
21
20
  end
22
21
  assert_passed(test_result)
23
- assert !@logger.warnings.include?("stubbing method on nil: nil.stubbed_method")
22
+ assert !@logger.warnings.include?('stubbing method on nil: nil.stubbed_method')
24
23
  end
25
24
 
26
25
  def test_should_warn_on_stubbing_method_on_nil
@@ -29,7 +28,7 @@ class StubbingNilTest < Mocha::TestCase
29
28
  nil.stubs(:stubbed_method)
30
29
  end
31
30
  assert_passed(test_result)
32
- assert @logger.warnings.include?("stubbing method on nil: nil.stubbed_method")
31
+ assert @logger.warnings.include?('stubbing method on nil: nil.stubbed_method')
33
32
  end
34
33
 
35
34
  def test_should_prevent_stubbing_method_on_nil
@@ -38,7 +37,7 @@ class StubbingNilTest < Mocha::TestCase
38
37
  nil.stubs(:stubbed_method)
39
38
  end
40
39
  assert_failed(test_result)
41
- assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on nil: nil.stubbed_method")
40
+ assert test_result.error_messages.include?('Mocha::StubbingError: stubbing method on nil: nil.stubbed_method')
42
41
  end
43
42
 
44
43
  def test_should_default_to_prevent_stubbing_method_on_non_mock_object
@@ -46,7 +45,7 @@ class StubbingNilTest < Mocha::TestCase
46
45
  nil.stubs(:stubbed_method)
47
46
  end
48
47
  assert_failed(test_result)
49
- assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on nil: nil.stubbed_method")
48
+ assert test_result.error_messages.include?('Mocha::StubbingError: stubbing method on nil: nil.stubbed_method')
50
49
  end
51
50
 
52
51
  def test_should_allow_stubbing_method_on_non_nil_object