-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework deprecation method for Error Namespaced Errors (#1035)
The version modeled off of activesupport's deprecations methods was causing issues when classes inherited from the deprecated class. Switch to a metaprogrammed class that warns upon initialization. Failing spec for #1033 rename module to DeprecatedClass Fix incorrect usage of rspec raise_error WARNING: Using `expect { }.not_to raise_error(SpecificErrorClass)` risks false positives, since literally any other error would cause the expectation to pass, including those raised by Ruby (e.g. NoMethodError, NameError and ArgumentError), meaning the code you are intending to test may not even get reached. Instead consider using `expect { }.not_to raise_error` or `expect { }.to raise_error(DifferentSpecificErrorClass)`. Update class doc
- Loading branch information
1 parent
b6db521
commit e4c94ad
Showing
4 changed files
with
34 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Faraday | ||
# @param old_klass [String] Old Namespaced Class | ||
# @param new_klass [Class] New Class that the caller should use instead | ||
# | ||
# @return [Class] A modified version of new_klass that warns on | ||
# usage about deprecation. | ||
module DeprecatedClass | ||
def self.proxy_class(old_klass, new_klass) | ||
Class.new(new_klass).tap do |k| | ||
k.send(:define_method, :initialize) do |*args, &block| | ||
@old_klass = old_klass | ||
@new_klass = new_klass | ||
warn | ||
super(*args, &block) | ||
end | ||
|
||
k.send(:define_method, :warn) do | ||
puts( | ||
"DEPRECATION WARNING: #{@old_klass} is deprecated! " \ | ||
"Use #{@new_klass} instead." | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters