Skip to content

Commit

Permalink
Add caller info to deprecation warning
Browse files Browse the repository at this point in the history
- See #151
  • Loading branch information
dchelimsky committed Aug 20, 2012
1 parent 5b36ea4 commit dd90e89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
7 changes: 5 additions & 2 deletions lib/rspec/mocks/message_expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,11 @@ 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.
warn "[DEPRECATION] `and_return` with `should_not_receive` is deprecated."
# @deprecated and_return is not supported with negative message expectations.
RSpec.warn_deprecation <<-MSG
DEPRECATION: `and_return` with `should_not_receive` is deprecated. Called from #{caller(0)[1]}
MSG
end

# @private
Expand Down
5 changes: 0 additions & 5 deletions spec/rspec/mocks/mock_ordering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ 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
10 changes: 5 additions & 5 deletions spec/rspec/mocks/mock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ module Mocks
@double.rspec_verify
end

it "passes when not receiving message specified as not to be received with and_return" do
# NOTE (DC 2012-05-05) calling `and_return` after `should_not_receive` makes no sense
# and should probably be disallowed.
@double.should_not_receive(:not_expected).and_return nil
@double.rspec_verify
it "warns when should_not_receive is followed by and_return" do
RSpec.should_receive(:warn_deprecation).
with(/`and_return` with `should_not_receive` is deprecated/)

@double.should_not_receive(:do_something).and_return(1)
end

it "passes when receiving message specified as not to be received with different args" do
Expand Down

0 comments on commit dd90e89

Please sign in to comment.