mocha 1.10.1 → 1.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/RELEASE.md +6 -0
  3. data/docs/Mocha.html +2 -2
  4. data/docs/Mocha/API.html +166 -32
  5. data/docs/Mocha/ClassMethods.html +2 -2
  6. data/docs/Mocha/Configuration.html +197 -55
  7. data/docs/Mocha/Expectation.html +2 -2
  8. data/docs/Mocha/ExpectationError.html +2 -2
  9. data/docs/Mocha/ExpectationErrorFactory.html +2 -2
  10. data/docs/Mocha/Hooks.html +2 -2
  11. data/docs/Mocha/Integration.html +2 -2
  12. data/docs/Mocha/Integration/MiniTest.html +2 -2
  13. data/docs/Mocha/Integration/MiniTest/Adapter.html +2 -2
  14. data/docs/Mocha/Integration/TestUnit.html +2 -2
  15. data/docs/Mocha/Integration/TestUnit/Adapter.html +2 -2
  16. data/docs/Mocha/Mock.html +5 -5
  17. data/docs/Mocha/ObjectMethods.html +2 -2
  18. data/docs/Mocha/ParameterMatchers.html +2 -2
  19. data/docs/Mocha/ParameterMatchers/AllOf.html +2 -2
  20. data/docs/Mocha/ParameterMatchers/AnyOf.html +2 -2
  21. data/docs/Mocha/ParameterMatchers/AnyParameters.html +2 -2
  22. data/docs/Mocha/ParameterMatchers/Anything.html +2 -2
  23. data/docs/Mocha/ParameterMatchers/Base.html +2 -2
  24. data/docs/Mocha/ParameterMatchers/Equals.html +2 -2
  25. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +2 -2
  26. data/docs/Mocha/ParameterMatchers/HasEntries.html +2 -2
  27. data/docs/Mocha/ParameterMatchers/HasEntry.html +2 -2
  28. data/docs/Mocha/ParameterMatchers/HasKey.html +2 -2
  29. data/docs/Mocha/ParameterMatchers/HasValue.html +2 -2
  30. data/docs/Mocha/ParameterMatchers/Includes.html +2 -2
  31. data/docs/Mocha/ParameterMatchers/InstanceOf.html +2 -2
  32. data/docs/Mocha/ParameterMatchers/IsA.html +2 -2
  33. data/docs/Mocha/ParameterMatchers/KindOf.html +2 -2
  34. data/docs/Mocha/ParameterMatchers/Not.html +2 -2
  35. data/docs/Mocha/ParameterMatchers/Optionally.html +2 -2
  36. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +2 -2
  37. data/docs/Mocha/ParameterMatchers/RespondsWith.html +2 -2
  38. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +2 -2
  39. data/docs/Mocha/Sequence.html +2 -2
  40. data/docs/Mocha/StateMachine.html +2 -2
  41. data/docs/Mocha/StateMachine/State.html +2 -2
  42. data/docs/Mocha/StateMachine/StatePredicate.html +2 -2
  43. data/docs/Mocha/StubbingError.html +2 -2
  44. data/docs/_index.html +3 -3
  45. data/docs/file.COPYING.html +2 -2
  46. data/docs/file.MIT-LICENSE.html +2 -2
  47. data/docs/file.README.html +2 -2
  48. data/docs/file.RELEASE.html +13 -2
  49. data/docs/frames.html +1 -1
  50. data/docs/index.html +2 -2
  51. data/docs/method_list.html +40 -32
  52. data/docs/top-level-namespace.html +2 -2
  53. data/lib/mocha/api.rb +78 -18
  54. data/lib/mocha/configuration.rb +57 -1
  55. data/lib/mocha/deprecation.rb +2 -1
  56. data/lib/mocha/expectation.rb +1 -1
  57. data/lib/mocha/invocation.rb +14 -2
  58. data/lib/mocha/mock.rb +3 -3
  59. data/lib/mocha/version.rb +1 -1
  60. data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +99 -0
  61. data/test/unit/expectation_test.rb +16 -1
  62. metadata +3 -2
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Mocha 1.10.1
9
+ &mdash; Mocha 1.10.2
10
10
 
11
11
  </title>
12
12
 
@@ -108,7 +108,7 @@
108
108
  </div>
109
109
 
110
110
  <div id="footer">
111
- Generated on Wed Dec 4 09:20:46 2019 by
111
+ Generated on Thu Dec 12 10:57:46 2019 by
112
112
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
113
113
  0.9.20 (ruby-2.6.5).
114
114
  </div>
@@ -51,7 +51,7 @@ module Mocha
51
51
  #
52
52
  # @overload def mock(name)
53
53
  # @param [String, Symbol] name identifies mock object in error messages.
54
- # @note Prior to v1.10.0 when +name+ was a +Symbol+, this method returned an unnamed +Mock+ that stubbed the method identified by +name+. This was undocumented behaviour and it no longer exists.
54
+ # @note Prior to v1.10.0 when +name+ was a +Symbol+, this method returned an unnamed +Mock+ that expected the method identified by +name+. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using {Configuration#reinstate_undocumented_behaviour_from_v1_9=}.
55
55
  # @overload def mock(expected_methods_vs_return_values = {})
56
56
  # @param [Hash] expected_methods_vs_return_values expected method name symbols as keys and corresponding return values as values - these expectations are setup as if {Mock#expects} were called multiple times.
57
57
  # @overload def mock(name, expected_methods_vs_return_values = {})
@@ -65,9 +65,33 @@ module Mocha
65
65
  # assert motor.stop
66
66
  # # an error will be raised unless both Motor#start and Motor#stop have been called
67
67
  # end
68
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
68
69
  def mock(*arguments)
69
- create_mock(arguments) { |mock, expectations| mock.expects(expectations) }
70
+ if Mocha.configuration.reinstate_undocumented_behaviour_from_v1_9?
71
+ if arguments.first.is_a?(Symbol)
72
+ method_name = arguments[0]
73
+ Deprecation.warning(
74
+ "Explicitly include `#{method_name}` in Hash of expected methods vs return values,",
75
+ " e.g. `mock(:#{method_name} => nil)`."
76
+ )
77
+ if arguments[1]
78
+ Deprecation.warning(
79
+ "In this case the 2nd argument for `mock(:##{method_name}, ...)` is ignored,",
80
+ ' but in the future a Hash of expected methods vs return values will be respected.'
81
+ )
82
+ end
83
+ elsif arguments.first.is_a?(String)
84
+ name = arguments.shift
85
+ end
86
+ elsif arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
87
+ name = arguments.shift
88
+ end
89
+ expectations = arguments.shift || {}
90
+ mock = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
91
+ mock.expects(expectations)
92
+ mock
70
93
  end
94
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
71
95
 
72
96
  # Builds a new mock object
73
97
  #
@@ -75,7 +99,7 @@ module Mocha
75
99
  #
76
100
  # @overload def stub(name)
77
101
  # @param [String, Symbol] name identifies mock object in error messages.
78
- # @note Prior to v1.10.0 when +name+ was a +Symbol+, this method returned an unnamed +Mock+ that stubbed the method identified by +name+. This was undocumented behaviour and it no longer exists.
102
+ # @note Prior to v1.10.0 when +name+ was a +Symbol+, this method returned an unnamed +Mock+ that stubbed the method identified by +name+. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using {Configuration#reinstate_undocumented_behaviour_from_v1_9=}.
79
103
  # @overload def stub(stubbed_methods_vs_return_values = {})
80
104
  # @param [Hash] stubbed_methods_vs_return_values stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if {Mock#stubs} were called multiple times.
81
105
  # @overload def stub(name, stubbed_methods_vs_return_values = {})
@@ -88,9 +112,33 @@ module Mocha
88
112
  # assert motor.stop
89
113
  # # an error will not be raised even if either Motor#start or Motor#stop has not been called
90
114
  # end
115
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
91
116
  def stub(*arguments)
92
- create_mock(arguments) { |stub, expectations| stub.stubs(expectations) }
117
+ if Mocha.configuration.reinstate_undocumented_behaviour_from_v1_9?
118
+ if arguments.first.is_a?(Symbol)
119
+ method_name = arguments[0]
120
+ Deprecation.warning(
121
+ "Explicitly include `#{method_name}` in Hash of stubbed methods vs return values,",
122
+ " e.g. `stub(:#{method_name} => nil)`."
123
+ )
124
+ if arguments[1]
125
+ Deprecation.warning(
126
+ "In this case the 2nd argument for `stub(:##{method_name}, ...)` is ignored,",
127
+ ' but in the future a Hash of stubbed methods vs return values will be respected.'
128
+ )
129
+ end
130
+ elsif arguments.first.is_a?(String)
131
+ name = arguments.shift
132
+ end
133
+ elsif arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
134
+ name = arguments.shift
135
+ end
136
+ expectations = arguments.shift || {}
137
+ stub = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
138
+ stub.stubs(expectations)
139
+ stub
93
140
  end
141
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
94
142
 
95
143
  # Builds a mock object that accepts calls to any method. By default it will return +nil+ for any method call.
96
144
  #
@@ -98,7 +146,7 @@ module Mocha
98
146
  #
99
147
  # @overload def stub_everything(name)
100
148
  # @param [String, Symbol] name identifies mock object in error messages.
101
- # @note Prior to v1.10.0 when +name+ was a +Symbol+, this method returned an unnamed +Mock+ that stubbed everything. This was undocumented behaviour and it no longer exists.
149
+ # @note Prior to v1.10.0 when +name+ was a +Symbol+, this method returned an unnamed +Mock+ that stubbed the method identified by +name+. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using {Configuration#reinstate_undocumented_behaviour_from_v1_9=}.
102
150
  # @overload def stub_everything(stubbed_methods_vs_return_values = {})
103
151
  # @param [Hash] stubbed_methods_vs_return_values stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if {Mock#stubs} were called multiple times.
104
152
  # @overload def stub_everything(name, stubbed_methods_vs_return_values = {})
@@ -112,12 +160,34 @@ module Mocha
112
160
  # assert_nil motor.irrelevant_method_2 # => no error raised
113
161
  # assert motor.stop
114
162
  # end
163
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
115
164
  def stub_everything(*arguments)
116
- create_mock(arguments) do |stub, expectations|
117
- stub.stub_everything
118
- stub.stubs(expectations)
165
+ if Mocha.configuration.reinstate_undocumented_behaviour_from_v1_9?
166
+ if arguments.first.is_a?(Symbol)
167
+ method_name = arguments[0]
168
+ Deprecation.warning(
169
+ "Explicitly include `#{method_name}` in Hash of stubbed methods vs return values,",
170
+ " e.g. `stub_everything(:#{method_name} => nil)`."
171
+ )
172
+ if arguments[1]
173
+ Deprecation.warning(
174
+ "In this case the 2nd argument for `stub_everything(:##{method_name}, ...)` is ignored,",
175
+ ' but in the future a Hash of stubbed methods vs return values will be respected.'
176
+ )
177
+ end
178
+ elsif arguments.first.is_a?(String)
179
+ name = arguments.shift
180
+ end
181
+ elsif arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
182
+ name = arguments.shift
119
183
  end
184
+ expectations = arguments.shift || {}
185
+ stub = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
186
+ stub.stub_everything
187
+ stub.stubs(expectations)
188
+ stub
120
189
  end
190
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
121
191
 
122
192
  # Builds a new sequence which can be used to constrain the order in which expectations can occur.
123
193
  #
@@ -168,15 +238,5 @@ module Mocha
168
238
  def states(name)
169
239
  Mockery.instance.new_state_machine(name)
170
240
  end
171
-
172
- private
173
-
174
- def create_mock(arguments)
175
- name = arguments.shift.to_s if arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
176
- expectations = arguments.shift || {}
177
- mock = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
178
- yield mock, expectations
179
- mock
180
- end
181
241
  end
182
242
  end
@@ -42,7 +42,8 @@ module Mocha
42
42
  :stubbing_non_existent_method => :allow,
43
43
  :stubbing_non_public_method => :allow,
44
44
  :stubbing_method_on_nil => :prevent,
45
- :display_matching_invocations_on_failure => false
45
+ :display_matching_invocations_on_failure => false,
46
+ :reinstate_undocumented_behaviour_from_v1_9 => false
46
47
  }.freeze
47
48
 
48
49
  attr_reader :options
@@ -247,6 +248,61 @@ module Mocha
247
248
  @options[:display_matching_invocations_on_failure]
248
249
  end
249
250
 
251
+ # Reinstate undocumented behaviour from v1.9
252
+ #
253
+ # Previously when {API#mock}, {API#stub}, or {API#stub_everything} were called with the first argument being a symbol, they built an *unnamed* mock object *and* expected or stubbed the method identified by the symbol argument; subsequent arguments were ignored.
254
+ # Now these methods build a *named* mock with the name specified by the symbol argument; *no* methods are expected or stubbed and subsequent arguments *are* taken into account.
255
+ #
256
+ # Previously if {Expectation#yields} or {Expectation#multiple_yields} was called on an expectation, but no block was given when the method was invoked, the instruction to yield was ignored.
257
+ # Now a +LocalJumpError+ is raised.
258
+ #
259
+ # Enabling this configuration option reinstates the previous behaviour, but displays a deprecation warning.
260
+ #
261
+ # @param [Boolean] value +true+ to reinstate undocumented behaviour; disabled by default.
262
+ #
263
+ # @example Reinstate undocumented behaviour for {API#mock}
264
+ # Mocha.configure do |c|
265
+ # c.reinstate_undocumented_behaviour_from_v1_9 = true
266
+ # end
267
+ #
268
+ # foo = mock(:bar)
269
+ # foo.inspect # => #<Mock>
270
+ #
271
+ # not all expectations were satisfied
272
+ # unsatisfied expectations:
273
+ # - expected exactly once, invoked never: #<Mock>.foo
274
+ #
275
+ # @example Reinstate undocumented behaviour for {API#stub}
276
+ # Mocha.configure do |c|
277
+ # c.reinstate_undocumented_behaviour_from_v1_9 = true
278
+ # end
279
+ #
280
+ # foo = stub(:bar)
281
+ # foo.inspect # => #<Mock>
282
+ # foo.bar # => nil
283
+ #
284
+ # @example Reinstate undocumented behaviour for {Expectation#yields}
285
+ # foo = mock('foo')
286
+ # foo.stubs(:my_method).yields(1, 2)
287
+ # foo.my_method # => raises LocalJumpError when no block is supplied
288
+ #
289
+ # Mocha.configure do |c|
290
+ # c.reinstate_undocumented_behaviour_from_v1_9 = true
291
+ # end
292
+ #
293
+ # foo = mock('foo')
294
+ # foo.stubs(:my_method).yields(1, 2)
295
+ # foo.my_method # => does *not* raise LocalJumpError when no block is supplied
296
+ #
297
+ def reinstate_undocumented_behaviour_from_v1_9=(value)
298
+ @options[:reinstate_undocumented_behaviour_from_v1_9] = value
299
+ end
300
+
301
+ # @private
302
+ def reinstate_undocumented_behaviour_from_v1_9?
303
+ @options[:reinstate_undocumented_behaviour_from_v1_9]
304
+ end
305
+
250
306
  class << self
251
307
  # Allow the specified +action+.
252
308
  #
@@ -5,7 +5,8 @@ module Mocha
5
5
  class << self
6
6
  attr_accessor :mode, :messages
7
7
 
8
- def warning(message)
8
+ def warning(*messages)
9
+ message = messages.join
9
10
  @messages << message
10
11
  return if mode == :disabled
11
12
  filter = BacktraceFilter.new
@@ -568,7 +568,7 @@ module Mocha
568
568
  def invoke(invocation)
569
569
  perform_side_effects
570
570
  @cardinality << invocation
571
- invocation.call(@yield_parameters, @return_values) { |*yield_args| yield(*yield_args) }
571
+ invocation.call(@yield_parameters, @return_values)
572
572
  end
573
573
 
574
574
  # @private
@@ -3,15 +3,18 @@ require 'mocha/raised_exception'
3
3
  require 'mocha/return_values'
4
4
  require 'mocha/thrown_object'
5
5
  require 'mocha/yield_parameters'
6
+ require 'mocha/configuration'
7
+ require 'mocha/deprecation'
6
8
 
7
9
  module Mocha
8
10
  class Invocation
9
11
  attr_reader :method_name
10
12
 
11
- def initialize(mock, method_name, *arguments)
13
+ def initialize(mock, method_name, *arguments, &block)
12
14
  @mock = mock
13
15
  @method_name = method_name
14
16
  @arguments = arguments
17
+ @block = block
15
18
  @yields = []
16
19
  @result = nil
17
20
  end
@@ -19,7 +22,16 @@ module Mocha
19
22
  def call(yield_parameters = YieldParameters.new, return_values = ReturnValues.new)
20
23
  yield_parameters.next_invocation.each do |yield_args|
21
24
  @yields << ParametersMatcher.new(yield_args)
22
- yield(*yield_args)
25
+ if @block
26
+ @block.call(*yield_args)
27
+ else
28
+ raise LocalJumpError unless Mocha.configuration.reinstate_undocumented_behaviour_from_v1_9?
29
+ yield_args_description = ParametersMatcher.new(yield_args).mocha_inspect
30
+ Deprecation.warning([
31
+ "Stubbed method was instructed to yield #{yield_args_description}, but no block was given by invocation: #{call_description}.",
32
+ 'This will raise a LocalJumpError in the future.'
33
+ ].join(' '))
34
+ end
23
35
  end
24
36
  return_values.next(self)
25
37
  end
@@ -310,13 +310,13 @@ module Mocha
310
310
  if @responder && !@responder.respond_to?(symbol)
311
311
  raise NoMethodError, "undefined method `#{symbol}' for #{mocha_inspect} which responds like #{@responder.mocha_inspect}"
312
312
  end
313
- invocation = Invocation.new(self, symbol, *arguments)
313
+ invocation = Invocation.new(self, symbol, *arguments, &block)
314
314
  if (matching_expectation_allowing_invocation = all_expectations.match_allowing_invocation(invocation))
315
- matching_expectation_allowing_invocation.invoke(invocation, &block)
315
+ matching_expectation_allowing_invocation.invoke(invocation)
316
316
  elsif (matching_expectation = all_expectations.match(invocation)) || (!matching_expectation && !@everything_stubbed)
317
317
  if @unexpected_invocation.nil?
318
318
  @unexpected_invocation = invocation
319
- matching_expectation.invoke(invocation, &block) if matching_expectation
319
+ matching_expectation.invoke(invocation) if matching_expectation
320
320
  message = "#{@unexpected_invocation.call_description}\n#{@mockery.mocha_inspect}"
321
321
  else
322
322
  message = @unexpected_invocation.short_call_description
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = '1.10.1'.freeze
2
+ VERSION = '1.10.2'.freeze
3
3
  end
@@ -0,0 +1,99 @@
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
+ require 'deprecation_disabler'
3
+
4
+ class MockBuiltWithFirstArgumentTypeBeingStringTest < Mocha::TestCase
5
+ include AcceptanceTest
6
+
7
+ def setup
8
+ setup_acceptance_test
9
+ Mocha.configure { |c| c.reinstate_undocumented_behaviour_from_v1_9 = true }
10
+ end
11
+
12
+ def teardown
13
+ teardown_acceptance_test
14
+ end
15
+
16
+ def test_mock_built_with_single_symbol_argument_with_satisfied_expectation
17
+ test_result = run_as_test do
18
+ DeprecationDisabler.disable_deprecations do
19
+ m = mock(:my_method)
20
+ assert_nil m.my_method
21
+ end
22
+ expected_warning = 'Explicitly include `my_method` in Hash of expected methods vs return values, e.g. `mock(:my_method => nil)`.'
23
+ assert_equal expected_warning, Mocha::Deprecation.messages.last
24
+ end
25
+ assert_passed(test_result)
26
+ end
27
+
28
+ def test_mock_built_with_single_symbol_argument_with_unsatisfied_expectation
29
+ test_result = run_as_test do
30
+ DeprecationDisabler.disable_deprecations do
31
+ mock(:my_method)
32
+ end
33
+ end
34
+ assert_failed(test_result)
35
+ assert(test_result.failure_message_lines.any? do |line|
36
+ line[/expected exactly once, invoked never\: #<Mock\:0x[0-9a-f]+>\.my_method\(any_parameters\)/]
37
+ end)
38
+ end
39
+
40
+ def test_stub_built_with_single_symbol_argument
41
+ test_result = run_as_test do
42
+ DeprecationDisabler.disable_deprecations do
43
+ s = stub(:my_method)
44
+ assert_nil s.my_method
45
+ end
46
+ expected_warning = 'Explicitly include `my_method` in Hash of stubbed methods vs return values, e.g. `stub(:my_method => nil)`.'
47
+ assert_equal expected_warning, Mocha::Deprecation.messages.last
48
+ end
49
+ assert_passed(test_result)
50
+ end
51
+
52
+ def test_mock_built_with_first_argument_a_symbol_and_second_argument_a_hash
53
+ test_result = run_as_test do
54
+ DeprecationDisabler.disable_deprecations do
55
+ s = mock(:my_method, :another_method => 123)
56
+ assert_nil s.my_method
57
+ end
58
+ expected_warning = 'In this case the 2nd argument for `mock(:#my_method, ...)` is ignored, but in the future a Hash of expected methods vs return values will be respected.'
59
+ assert Mocha::Deprecation.messages.last(2).include?(expected_warning)
60
+ end
61
+ assert_passed(test_result)
62
+ end
63
+
64
+ def test_stub_built_with_first_argument_a_symbol_and_second_argument_a_hash
65
+ test_result = run_as_test do
66
+ DeprecationDisabler.disable_deprecations do
67
+ s = stub(:my_method, :another_method => 123)
68
+ assert_nil s.my_method
69
+ end
70
+ expected_warning = 'In this case the 2nd argument for `stub(:#my_method, ...)` is ignored, but in the future a Hash of stubbed methods vs return values will be respected.'
71
+ assert Mocha::Deprecation.messages.last(2).include?(expected_warning)
72
+ end
73
+ assert_passed(test_result)
74
+ end
75
+
76
+ def test_stub_everything_built_with_single_symbol_argument
77
+ test_result = run_as_test do
78
+ DeprecationDisabler.disable_deprecations do
79
+ s = stub_everything(:my_method)
80
+ assert_nil s.my_method
81
+ end
82
+ expected_warning = 'Explicitly include `my_method` in Hash of stubbed methods vs return values, e.g. `stub_everything(:my_method => nil)`.'
83
+ assert_equal expected_warning, Mocha::Deprecation.messages.last
84
+ end
85
+ assert_passed(test_result)
86
+ end
87
+
88
+ def test_stub_everything_built_with_first_argument_a_symbol_and_second_argument_a_hash
89
+ test_result = run_as_test do
90
+ DeprecationDisabler.disable_deprecations do
91
+ s = stub_everything(:my_method, :another_method => 123)
92
+ assert_nil s.my_method
93
+ end
94
+ expected_warning = 'In this case the 2nd argument for `stub_everything(:#my_method, ...)` is ignored, but in the future a Hash of stubbed methods vs return values will be respected.' # rubocop:disable Metrics/LineLength
95
+ assert Mocha::Deprecation.messages.last(2).include?(expected_warning)
96
+ end
97
+ assert_passed(test_result)
98
+ end
99
+ end
@@ -2,8 +2,11 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha/expectation'
3
3
  require 'mocha/invocation'
4
4
  require 'mocha/sequence'
5
+ require 'mocha/configuration'
6
+ require 'mocha/deprecation'
5
7
  require 'execution_point'
6
8
  require 'simple_counter'
9
+ require 'deprecation_disabler'
7
10
 
8
11
  class ExpectationTest < Mocha::TestCase
9
12
  include Mocha
@@ -13,7 +16,7 @@ class ExpectationTest < Mocha::TestCase
13
16
  end
14
17
 
15
18
  def invoke(expectation, &block)
16
- expectation.invoke(Invocation.new(:irrelevant, :expected_method), &block)
19
+ expectation.invoke(Invocation.new(:irrelevant, :expected_method, &block))
17
20
  end
18
21
 
19
22
  def test_should_match_calls_to_same_method_with_any_parameters
@@ -116,6 +119,18 @@ class ExpectationTest < Mocha::TestCase
116
119
  assert_raises(LocalJumpError) { invoke(new_expectation.yields(:foo)) }
117
120
  end
118
121
 
122
+ def test_yield_should_display_warning_when_caller_does_not_provide_block_and_behaviour_from_v1_9_retained
123
+ Mocha::Configuration.override(:reinstate_undocumented_behaviour_from_v1_9 => true) do
124
+ DeprecationDisabler.disable_deprecations do
125
+ invoke(new_expectation.yields(:foo, 1, [2, 3]))
126
+ end
127
+ end
128
+ assert message = Deprecation.messages.last
129
+ assert message.include?('Stubbed method was instructed to yield (:foo, 1, [2, 3])')
130
+ assert message.include?('but no block was given by invocation: :irrelevant.expected_method()')
131
+ assert message.include?('This will raise a LocalJumpError in the future.')
132
+ end
133
+
119
134
  def test_should_yield_with_specified_parameters
120
135
  yielded_parameters = nil
121
136
  invoke(new_expectation.yields(1, 2, 3)) { |*parameters| yielded_parameters = parameters }