Last active
December 9, 2015 22:48
-
-
Save lunich/4339922 to your computer and use it in GitHub Desktop.
Deprecation wrapper for standard ruby tests assert_* methods
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
module DeprecateAssertions | |
protected | |
def self.methods_to_replace | |
[ | |
:assert, | |
:assert_block, | |
:assert_equal, | |
:assert_no_match, | |
:assert_not_equal, | |
:assert_nothing_raised, | |
:assert_nothing_thrown, | |
:assert_not_nil, | |
:assert_not_same, | |
:assert_raise, | |
:assert_respond_to, | |
] | |
end | |
public | |
def self.included a | |
a.class_eval do | |
DeprecateAssertions.methods_to_replace.each do |m| | |
alias :"old_#{m}" :"#{m}" | |
alias :"#{m}" :"new_#{m}" | |
end | |
end | |
end | |
DeprecateAssertions.methods_to_replace.each do |m| | |
define_method(:"new_#{m}") do |*args, &block| | |
warn "[DEPRECATED] '#{m}' is deprecated. Please use RSpec methods instead." | |
warn "from: #{caller[0]}" | |
send(:"old_#{m}", *args, &block) | |
end | |
end | |
end | |
require "test/unit" | |
Test::Unit::Assertions.class_eval do | |
include DeprecateAssertions | |
end | |
class TestMe < Test::Unit::TestCase | |
def test_me | |
assert_equal 12, 3 * 4 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment