Skip to content

Instantly share code, notes, and snippets.

@vraravam
Created March 19, 2011 03:39
Show Gist options
  • Save vraravam/877198 to your computer and use it in GitHub Desktop.
Save vraravam/877198 to your computer and use it in GitHub Desktop.
using_constants for rspec tests
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