Skip to content

Commit

Permalink
Remove old deprecation API.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Jul 15, 2013
1 parent 99b0ece commit 9396aa1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
5 changes: 1 addition & 4 deletions lib/rspec/core/deprecation.rb
Expand Up @@ -4,10 +4,7 @@ module Deprecation
# @private
#
# Used internally to print deprecation warnings
def deprecate(deprecated, replacement_or_hash={}, ignore_version=nil)
# Temporarily support old and new APIs while we transition the other
# rspec libs to use a hash for the 2nd arg and no version arg
data = Hash === replacement_or_hash ? replacement_or_hash : { :replacement => replacement_or_hash }
def deprecate(deprecated, data = {})
call_site = caller.find { |line| line !~ %r{/lib/rspec/(core|mocks|expectations|matchers|rails)/} }

RSpec.configuration.reporter.deprecation(
Expand Down
39 changes: 10 additions & 29 deletions spec/rspec/core/deprecation_spec.rb
Expand Up @@ -2,38 +2,19 @@

describe RSpec::Core::Deprecation do
describe "#deprecate" do
context "old API with individual args" do
it "includes the method to deprecate" do
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method")
RSpec.deprecate("deprecated_method")
end

it "includes the replacement when provided" do
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method", :replacement => "replacement")
RSpec.deprecate("deprecated_method", "replacement")
end

it "adds the call site" do
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
RSpec.deprecate("deprecated_method")
end

it "doesn't override the existing callsite" do
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :call_site => "/path")
RSpec.deprecate("deprecated_method", :call_site => "/path")
end
it "passes the hash to the reporter" do
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method", :replacement => "replacement")
RSpec.deprecate("deprecated_method", :replacement => "replacement")
end

context "new API with a hash after the first arg" do
it "passes the hash to the reporter" do
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method", :replacement => "replacement")
RSpec.deprecate("deprecated_method", :replacement => "replacement")
end
it "adds the call site" do
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
RSpec.deprecate("deprecated_method")
end

it "adds the call site" do
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
RSpec.deprecate("deprecated_method")
end
it "doesn't override a passed call site" do
expect_deprecation_with_call_site("some_file.rb", 17)
RSpec.deprecate("deprecated_method", :call_site => "/some_file.rb:17")
end
end

Expand Down

0 comments on commit 9396aa1

Please sign in to comment.