Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

3 participants

@Bodhisattva2-0

No description provided.

@travisbot

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

@dchelimsky dchelimsky referenced this pull request
Closed

Issue134 #149

@dchelimsky dchelimsky commented on the diff
lib/rspec/mocks/message_expectation.rb
@@ -477,6 +477,8 @@ def initialize(error_generator, expectation_ordering, expected_from, message, &i
def and_return(*)
# no-op
+ # @deprecated Please do not use and_return with negative message expectations.
@dchelimsky Owner

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
@dchelimsky
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).

@Bodhisattva2-0

Alright David. Thanks.

@Bodhisattva2-0

Hi David, any updates on this?

@dchelimsky
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.

@dchelimsky
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.

@dchelimsky dchelimsky merged commit 5b36ea4 into rspec:master
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky Changelog for #151 90f3ebb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 11, 2012
  1. Issue #134: Add deprecation warning for should_not_receive followed b…

    Neha Kumari authored
    …y and_return.
This page is out of date. Refresh to see the latest.
View
2  lib/rspec/mocks/message_expectation.rb
@@ -477,6 +477,8 @@ def initialize(error_generator, expectation_ordering, expected_from, message, &i
def and_return(*)
# no-op
+ # @deprecated Please do not use and_return with negative message expectations.
@dchelimsky Owner

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
+ warn "[DEPRECATION] `and_return` with `should_not_receive` is deprecated."
end
# @private
View
5 spec/rspec/mocks/mock_ordering_spec.rb
@@ -98,6 +98,11 @@ module Mocks
@double.b
@double.a
end
+
+ it "warns when should_not_receive is followed by and_return" do
+ @double.should_receive(:warn).with("[DEPRECATION] `and_return` with `should_not_receive` is deprecated.")
+ @double.should_not_receive(:do_something).and_return(1)
+ end
end
end
end
Something went wrong with that request. Please try again.