mocha 1.11.1 → 1.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/RELEASE.md +14 -0
  3. data/docs/Mocha.html +2 -2
  4. data/docs/Mocha/API.html +16 -18
  5. data/docs/Mocha/ClassMethods.html +2 -2
  6. data/docs/Mocha/Configuration.html +2 -2
  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 +12 -39
  17. data/docs/Mocha/ObjectMethods.html +2 -2
  18. data/docs/Mocha/ParameterMatchers.html +14 -26
  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 +5 -5
  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 +20 -2
  49. data/docs/frames.html +1 -1
  50. data/docs/index.html +2 -2
  51. data/docs/top-level-namespace.html +2 -2
  52. data/lib/mocha/api.rb +2 -3
  53. data/lib/mocha/mock.rb +40 -14
  54. data/lib/mocha/mockery.rb +10 -7
  55. data/lib/mocha/parameter_matchers/has_entries.rb +2 -3
  56. data/lib/mocha/parameter_matchers/has_entry.rb +2 -3
  57. data/lib/mocha/parameter_matchers/has_key.rb +2 -3
  58. data/lib/mocha/parameter_matchers/has_value.rb +2 -3
  59. data/lib/mocha/parameter_matchers/is_a.rb +2 -3
  60. data/lib/mocha/parameter_matchers/not.rb +2 -3
  61. data/lib/mocha/state_machine.rb +2 -3
  62. data/lib/mocha/stubbed_method.rb +4 -6
  63. data/lib/mocha/version.rb +1 -1
  64. data/test/acceptance/issue_457_test.rb +31 -0
  65. data/test/acceptance/mocha_example_test.rb +11 -1
  66. data/test/acceptance/mock_test.rb +36 -0
  67. data/test/acceptance/stubba_example_test.rb +11 -1
  68. metadata +3 -3
  69. data/lib/mocha/pretty_parameters.rb +0 -24
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Class: Mocha::ParameterMatchers::RegexpMatches
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -143,7 +143,7 @@
143
143
  </div>
144
144
 
145
145
  <div id="footer">
146
- Generated on Tue Dec 17 12:49:36 2019 by
146
+ Generated on Sat Jan 4 17:36:48 2020 by
147
147
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
148
148
  0.9.20 (ruby-2.6.5).
149
149
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Class: Mocha::ParameterMatchers::RespondsWith
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -143,7 +143,7 @@
143
143
  </div>
144
144
 
145
145
  <div id="footer">
146
- Generated on Tue Dec 17 12:49:36 2019 by
146
+ Generated on Sat Jan 4 17:36:48 2020 by
147
147
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
148
148
  0.9.20 (ruby-2.6.5).
149
149
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Class: Mocha::ParameterMatchers::YamlEquivalent
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -143,7 +143,7 @@
143
143
  </div>
144
144
 
145
145
  <div id="footer">
146
- Generated on Tue Dec 17 12:49:36 2019 by
146
+ Generated on Sat Jan 4 17:36:48 2020 by
147
147
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
148
148
  0.9.20 (ruby-2.6.5).
149
149
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Class: Mocha::Sequence
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -139,7 +139,7 @@
139
139
  </div>
140
140
 
141
141
  <div id="footer">
142
- Generated on Tue Dec 17 12:49:36 2019 by
142
+ Generated on Sat Jan 4 17:36:48 2020 by
143
143
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
144
144
  0.9.20 (ruby-2.6.5).
145
145
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Class: Mocha::StateMachine
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -394,7 +394,7 @@
394
394
  </h3><div class="docstring">
395
395
  <div class="discussion">
396
396
 
397
- <p>Provides a mechanism to determine whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> is not in the state specified by <code>state_name</code> at some point in the future. rubocop:disable Naming/PredicateName</p>
397
+ <p>Provides a mechanism to determine whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> is not in the state specified by <code>state_name</code> at some point in the future.</p>
398
398
 
399
399
 
400
400
  </div>
@@ -415,8 +415,8 @@
415
415
  <td>
416
416
  <pre class="code"><span class="info file"># File 'lib/mocha/state_machine.rb', line 88</span>
417
417
 
418
- <span class='kw'>def</span> <span class='id identifier rubyid_is_not'>is_not</span><span class='lparen'>(</span><span class='id identifier rubyid_state_name'>state_name</span><span class='rparen'>)</span>
419
- <span class='const'><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_state_name'>state_name</span><span class='rparen'>)</span>
418
+ <span class='kw'>def</span> <span class='id identifier rubyid_is_not'>is_not</span><span class='lparen'>(</span><span class='id identifier rubyid_state_name'>state_name</span><span class='rparen'>)</span> <span class='comment'># rubocop:disable Naming/PredicateName
419
+ </span> <span class='const'><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_state_name'>state_name</span><span class='rparen'>)</span>
420
420
  <span class='kw'>end</span></pre>
421
421
  </td>
422
422
  </tr>
@@ -517,7 +517,7 @@
517
517
  </div>
518
518
 
519
519
  <div id="footer">
520
- Generated on Tue Dec 17 12:49:36 2019 by
520
+ Generated on Sat Jan 4 17:36:48 2020 by
521
521
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
522
522
  0.9.20 (ruby-2.6.5).
523
523
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Class: Mocha::StateMachine::State
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -130,7 +130,7 @@
130
130
  </div>
131
131
 
132
132
  <div id="footer">
133
- Generated on Tue Dec 17 12:49:36 2019 by
133
+ Generated on Sat Jan 4 17:36:48 2020 by
134
134
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
135
135
  0.9.20 (ruby-2.6.5).
136
136
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Class: Mocha::StateMachine::StatePredicate
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -130,7 +130,7 @@
130
130
  </div>
131
131
 
132
132
  <div id="footer">
133
- Generated on Tue Dec 17 12:49:36 2019 by
133
+ Generated on Sat Jan 4 17:36:48 2020 by
134
134
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
135
135
  0.9.20 (ruby-2.6.5).
136
136
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Class: Mocha::StubbingError
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -140,7 +140,7 @@
140
140
  </div>
141
141
 
142
142
  <div id="footer">
143
- Generated on Tue Dec 17 12:49:37 2019 by
143
+ Generated on Sat Jan 4 17:36:48 2020 by
144
144
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
145
145
  0.9.20 (ruby-2.6.5).
146
146
  </div>
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>
7
- Mocha 1.11.1
7
+ Mocha 1.11.2
8
8
 
9
9
  </title>
10
10
 
@@ -52,7 +52,7 @@
52
52
  <div class="clear"></div>
53
53
  </div>
54
54
 
55
- <div id="content"><h1 class="noborder title">Mocha 1.11.1</h1>
55
+ <div id="content"><h1 class="noborder title">Mocha 1.11.2</h1>
56
56
  <div id="listing">
57
57
  <h1 class="alphaindex">Alphabetic Index</h1>
58
58
 
@@ -509,7 +509,7 @@
509
509
  </div>
510
510
 
511
511
  <div id="footer">
512
- Generated on Tue Dec 17 12:49:34 2019 by
512
+ Generated on Sat Jan 4 17:36:46 2020 by
513
513
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
514
514
  0.9.20 (ruby-2.6.5).
515
515
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  File: COPYING
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -71,7 +71,7 @@
71
71
  </div>
72
72
 
73
73
  <div id="footer">
74
- Generated on Tue Dec 17 12:49:34 2019 by
74
+ Generated on Sat Jan 4 17:36:46 2020 by
75
75
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
76
76
  0.9.20 (ruby-2.6.5).
77
77
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  File: MIT-LICENSE
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -75,7 +75,7 @@
75
75
  </div>
76
76
 
77
77
  <div id="footer">
78
- Generated on Tue Dec 17 12:49:34 2019 by
78
+ Generated on Sat Jan 4 17:36:46 2020 by
79
79
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
80
80
  0.9.20 (ruby-2.6.5).
81
81
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  File: README
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -438,7 +438,7 @@ Pushed mocha 1.2.0 to rubygems.org.
438
438
  </div>
439
439
 
440
440
  <div id="footer">
441
- Generated on Tue Dec 17 12:49:34 2019 by
441
+ Generated on Sat Jan 4 17:36:46 2020 by
442
442
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
443
443
  0.9.20 (ruby-2.6.5).
444
444
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  File: RELEASE
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -59,6 +59,24 @@
59
59
 
60
60
  <div id="content"><div id='filecontents'><h1>Release Notes</h1>
61
61
 
62
+ <h2>1.11.2</h2>
63
+
64
+ <h3>External changes</h3>
65
+
66
+ <ul>
67
+ <li>Fix regression introduced in v1.10.0 that meant <code>Object#inspect</code> was called unnecessarily (368abd98)</li>
68
+ <li>Warn when mock object receives invocations in another test - thanks to @nitishr (#442)</li>
69
+ <li>Avoid rubocop comments appearing in YARD-generated docs (d8019eed)</li>
70
+ </ul>
71
+
72
+ <h3>Internal changes</h3>
73
+
74
+ <ul>
75
+ <li>Replace <code>StubbedMethod#original_method</code> &amp; <code>#original_visibility</code> attribute reader methods with instance variables - thanks to @nitishr (d917f332)</li>
76
+ <li>Set up <code>MochaExampleTest</code> &amp; <code>StubbaExampleTest</code> as acceptance tests - thanks to @nitishr (4881cc58)</li>
77
+ <li>Delete unused <code>PrettyParameters</code> class - thanks to @nitishr (314ea922)</li>
78
+ </ul>
79
+
62
80
  <h2>1.11.1</h2>
63
81
 
64
82
  <h3>External changes</h3>
@@ -1000,7 +1018,7 @@ Hash with wrong number of entries.</li>
1000
1018
  </div>
1001
1019
 
1002
1020
  <div id="footer">
1003
- Generated on Tue Dec 17 12:49:34 2019 by
1021
+ Generated on Sat Jan 4 17:36:46 2020 by
1004
1022
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1005
1023
  0.9.20 (ruby-2.6.5).
1006
1024
  </div>
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8">
5
- <title>Mocha 1.11.1</title>
5
+ <title>Mocha 1.11.2</title>
6
6
  </head>
7
7
  <script type="text/javascript" charset="utf-8">
8
8
  var match = unescape(window.location.hash).match(/^#!(.+)/);
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  File: README
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.2
10
10
 
11
11
  </title>
12
12
 
@@ -438,7 +438,7 @@ Pushed mocha 1.2.0 to rubygems.org.
438
438
  </div>
439
439
 
440
440
  <div id="footer">
441
- Generated on Tue Dec 17 12:49:34 2019 by
441
+ Generated on Sat Jan 4 17:36:46 2020 by
442
442
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
443
443
  0.9.20 (ruby-2.6.5).
444
444
  </div>
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Mocha 1.11.1
9
+ &mdash; Mocha 1.11.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 Tue Dec 17 12:49:34 2019 by
111
+ Generated on Sat Jan 4 17:36:46 2020 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>
@@ -65,8 +65,8 @@ 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
69
- def mock(*arguments)
68
+ #
69
+ def mock(*arguments) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
70
70
  if Mocha.configuration.reinstate_undocumented_behaviour_from_v1_9?
71
71
  if arguments.first.is_a?(Symbol)
72
72
  method_name = arguments[0]
@@ -91,7 +91,6 @@ module Mocha
91
91
  mock.expects(expectations)
92
92
  mock
93
93
  end
94
- # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
95
94
 
96
95
  # Builds a new mock object
97
96
  #
@@ -275,6 +275,7 @@ module Mocha
275
275
  @everything_stubbed = false
276
276
  @responder = nil
277
277
  @unexpected_invocation = nil
278
+ @expired = false
278
279
  end
279
280
 
280
281
  # @private
@@ -305,26 +306,16 @@ module Mocha
305
306
  end
306
307
 
307
308
  # @private
308
- # rubocop:disable Style/MethodMissingSuper,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
309
- def method_missing(symbol, *arguments, &block)
310
- if @responder && !@responder.respond_to?(symbol)
311
- raise NoMethodError, "undefined method `#{symbol}' for #{mocha_inspect} which responds like #{@responder.mocha_inspect}"
312
- end
309
+ def method_missing(symbol, *arguments, &block) # rubocop:disable Style/MethodMissingSuper
310
+ check_expiry
311
+ check_responder_responds_to(symbol)
313
312
  invocation = Invocation.new(self, symbol, *arguments, &block)
314
313
  if (matching_expectation_allowing_invocation = all_expectations.match_allowing_invocation(invocation))
315
314
  matching_expectation_allowing_invocation.invoke(invocation)
316
315
  elsif (matching_expectation = all_expectations.match(invocation)) || (!matching_expectation && !@everything_stubbed)
317
- if @unexpected_invocation.nil?
318
- @unexpected_invocation = invocation
319
- matching_expectation.invoke(invocation) if matching_expectation
320
- message = "#{@unexpected_invocation.call_description}\n#{@mockery.mocha_inspect}"
321
- else
322
- message = @unexpected_invocation.short_call_description
323
- end
324
- raise ExpectationErrorFactory.build("unexpected invocation: #{message}", caller)
316
+ raise_unexpected_invocation_error(invocation, matching_expectation)
325
317
  end
326
318
  end
327
- # rubocop:enable Style/MethodMissingSuper,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
328
319
 
329
320
  # @private
330
321
  def respond_to_missing?(symbol, include_private = false)
@@ -351,6 +342,11 @@ module Mocha
351
342
  @expectations.verified?(assertion_counter)
352
343
  end
353
344
 
345
+ # @private
346
+ def __expire__
347
+ @expired = true
348
+ end
349
+
354
350
  # @private
355
351
  def mocha_inspect
356
352
  @name.mocha_inspect
@@ -370,5 +366,35 @@ module Mocha
370
366
  def any_expectations?
371
367
  @expectations.any?
372
368
  end
369
+
370
+ private
371
+
372
+ def raise_unexpected_invocation_error(invocation, matching_expectation)
373
+ if @unexpected_invocation.nil?
374
+ @unexpected_invocation = invocation
375
+ matching_expectation.invoke(invocation) if matching_expectation
376
+ message = "#{@unexpected_invocation.call_description}\n#{@mockery.mocha_inspect}"
377
+ else
378
+ message = @unexpected_invocation.short_call_description
379
+ end
380
+ raise ExpectationErrorFactory.build("unexpected invocation: #{message}", caller)
381
+ end
382
+
383
+ def check_responder_responds_to(symbol)
384
+ if @responder && !@responder.respond_to?(symbol) # rubocop:disable Style/GuardClause
385
+ raise NoMethodError, "undefined method `#{symbol}' for #{mocha_inspect} which responds like #{@responder.mocha_inspect}"
386
+ end
387
+ end
388
+
389
+ def check_expiry
390
+ if @expired # rubocop:disable Style/GuardClause
391
+ Deprecation.warning(
392
+ "#{mocha_inspect} was instantiated in one test but it is receiving invocations within another test.",
393
+ ' This can lead to unintended interactions between tests and hence unexpected test failures.',
394
+ ' Ensure that every test correctly cleans up any state that it introduces.',
395
+ ' A Mocha::StubbingError will be raised in this scenario in the future.'
396
+ )
397
+ end
398
+ end
373
399
  end
374
400
  end
@@ -102,6 +102,7 @@ module Mocha
102
102
 
103
103
  def teardown
104
104
  stubba.unstub_all
105
+ mocks.each(&:__expire__)
105
106
  reset
106
107
  end
107
108
 
@@ -127,19 +128,20 @@ module Mocha
127
128
 
128
129
  def on_stubbing(object, method)
129
130
  method = PRE_RUBY_V19 ? method.to_s : method.to_sym
130
- method_signature = "#{object.mocha_inspect}.#{method}"
131
- check(:stubbing_non_existent_method, 'non-existent method', method_signature) do
131
+ signature_proc = lambda { "#{object.mocha_inspect}.#{method}" }
132
+ check(:stubbing_non_existent_method, 'non-existent method', signature_proc) do
132
133
  !(object.stubba_class.__method_exists__?(method, true) || object.respond_to?(method.to_sym))
133
134
  end
134
- check(:stubbing_non_public_method, 'non-public method', method_signature) do
135
+ check(:stubbing_non_public_method, 'non-public method', signature_proc) do
135
136
  object.stubba_class.__method_exists__?(method, false)
136
137
  end
137
- check(:stubbing_method_on_nil, 'method on nil', method_signature) { object.nil? }
138
- check(:stubbing_method_on_non_mock_object, 'method on non-mock object', method_signature)
138
+ check(:stubbing_method_on_nil, 'method on nil', signature_proc) { object.nil? }
139
+ check(:stubbing_method_on_non_mock_object, 'method on non-mock object', signature_proc)
139
140
  end
140
141
 
141
142
  def on_stubbing_method_unnecessarily(expectation)
142
- check(:stubbing_method_unnecessarily, 'method unnecessarily', expectation.method_signature, expectation.backtrace)
143
+ signature_proc = lambda { expectation.method_signature }
144
+ check(:stubbing_method_unnecessarily, 'method unnecessarily', signature_proc, expectation.backtrace)
143
145
  end
144
146
 
145
147
  attr_writer :logger
@@ -150,9 +152,10 @@ module Mocha
150
152
 
151
153
  private
152
154
 
153
- def check(action, description, method_signature, backtrace = caller)
155
+ def check(action, description, signature_proc, backtrace = caller)
154
156
  treatment = Mocha.configuration.send(action)
155
157
  return if (treatment == :allow) || (block_given? && !yield)
158
+ method_signature = signature_proc.call
156
159
  message = "stubbing #{description}: #{method_signature}"
157
160
  raise StubbingError.new(message, backtrace) if treatment == :prevent
158
161
  logger.warn(message) if treatment == :warn