Skip to content

Instantly share code, notes, and snippets.

@rfunduk
Created February 6, 2012 23:11
Show Gist options
  • Save rfunduk/1755766 to your computer and use it in GitHub Desktop.
Save rfunduk/1755766 to your computer and use it in GitHub Desktop.
it "should etc, etc" do
using_constants( SomeClass, { :CONST_A => stub, :CONST_B => 1 } ) do
# ...
end
end
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment