Skip to content

Instantly share code, notes, and snippets.

@seeflanigan
Created January 1, 2011 04:12
Show Gist options
  • Save seeflanigan/761546 to your computer and use it in GitHub Desktop.
Save seeflanigan/761546 to your computer and use it in GitHub Desktop.
A helper method to simplify deprecations.
module DeprecationHelpers
def deprecated_in_favor_of(new_method_name)
warning = "[DEPRECATION] '##{deprecated_method_name}' "
warning << "has been deprecated.\n"
warning << "Please use '##{new_method_name.to_s}' instead."
logger.warn(warning)
end
protected
def deprecated_method_name
/`(.*)'/.match(caller[1]).captures[0].to_sym rescue nil
end
end
require File.dirname(__FILE__) + '/../../test_helper'
require 'deprecation_helpers'
class DeprecationHelpersTest < ActiveSupport::TestCase
include DeprecationHelpers
context "#deprecated_in_favor_of" do
setup do
def foo
deprecated_in_favor_of(:bar)
end
end
should "log a deprecation warning" do
logger.expects(:warn).with(includes("[DEPRECATION]"))
foo
end
should "include the name of the deprecated method" do
logger.expects(:warn).with(includes("foo"))
foo
end
should "include the name of the new method if one exists" do
logger.expects(:warn).with(includes("bar"))
foo
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment