Created
March 19, 2011 03:39
-
-
Save vraravam/877198 to your computer and use it in GitHub Desktop.
using_constants for rspec tests
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 Spec | |
module Extension | |
def using_constants(klass, new_constants) | |
old_constants = {} | |
begin | |
new_constants.each_pair do |name, value| | |
old_constants[name] = klass.__send__(:remove_const, name) | |
klass.const_set(name, value) | |
end | |
yield | |
ensure | |
old_constants.each_pair do |name, value| | |
klass.__send__(:remove_const, name) | |
klass.const_set(name, value) | |
end | |
end | |
end | |
end | |
end | |
ActiveSupport::TestCase.__send__(:include, ::Spec::Extension) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment