Skip to content
This repository

Issue #134: Add deprecation warning for should_not_receive followed by and_return #151

Merged
merged 1 commit into from over 1 year ago

3 participants

Neha Don't Add Me To Your Organization a.k.a The Travis Bot David Chelimsky
Neha

No description provided.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 15c84d7 into f04d527).

David Chelimsky dchelimsky referenced this pull request June 11, 2012
Closed

Issue134 #149

David Chelimsky dchelimsky commented on the diff June 11, 2012
lib/rspec/mocks/message_expectation.rb
@@ -477,6 +477,8 @@ def initialize(error_generator, expectation_ordering, expected_from, message, &i
477 477
 
478 478
       def and_return(*)
479 479
         # no-op
  480
+        # @deprecated Please do not use and_return with negative message expectations.
1
David Chelimsky Owner
dchelimsky added a note June 11, 2012

This comment should move to before the method (like an rdoc comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
David Chelimsky
Owner

All of RSpec's other deprecation notices use either RSpec.deprecate or RSpec.warn_deprecation. Unfortunately, neither are a great option right now because RSpec.deprecate displays a message saying the behavior will be removed from a future version, which is a bit confusing in this case. I'm going to update that method to take an options hash, and then ask that you use that method instead, as it displays the line from which the deprecated method is called. Please stand by (probably a few days).

Neha

Alright David. Thanks.

Neha

Hi David, any updates on this?

David Chelimsky
Owner

Sorry, no. Haven't had much time for the last few weeks. This weekend I'm going to try to get the 2.11 release out. If I'm able to address this in the process I will, but I make no promises.

David Chelimsky
Owner

Hey - sorry I haven't followed up on this. I still haven't figured out how I want to centralize the deprecation warning behavior. I want to get this in sooner than later, so I'm going to merge it and then modify it slightly. Thanks for the pull and for your patience.

David Chelimsky dchelimsky merged commit 5b36ea4 into from August 19, 2012
David Chelimsky dchelimsky closed this August 19, 2012
David Chelimsky dchelimsky referenced this pull request from a commit August 19, 2012
David Chelimsky Changelog for #151 90f3ebb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 11, 2012
Issue #134: Add deprecation warning for should_not_receive followed b…
…y and_return.
15c84d7
This page is out of date. Refresh to see the latest.
2  lib/rspec/mocks/message_expectation.rb
@@ -477,6 +477,8 @@ def initialize(error_generator, expectation_ordering, expected_from, message, &i
477 477
 
478 478
       def and_return(*)
479 479
         # no-op
  480
+        # @deprecated Please do not use and_return with negative message expectations.
  481
+        warn "[DEPRECATION] `and_return` with `should_not_receive` is deprecated."
480 482
       end
481 483
 
482 484
       # @private
5  spec/rspec/mocks/mock_ordering_spec.rb
@@ -98,6 +98,11 @@ module Mocks
98 98
         @double.b
99 99
         @double.a
100 100
       end
  101
+
  102
+      it "warns when should_not_receive is followed by and_return" do
  103
+        @double.should_receive(:warn).with("[DEPRECATION] `and_return` with `should_not_receive` is deprecated.")
  104
+        @double.should_not_receive(:do_something).and_return(1)
  105
+      end
101 106
     end
102 107
   end
103 108
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.