Skip to content

Instantly share code, notes, and snippets.

@neilmiddleton
Created May 29, 2012 11:01
Show Gist options
  • Save neilmiddleton/2827467 to your computer and use it in GitHub Desktop.
Save neilmiddleton/2827467 to your computer and use it in GitHub Desktop.
constant_macros
module ConstantMacros
def with_constants(constants, &block)
saved_constants = {}
constants.each do |constant, val|
saved_constants[ constant ] = Object.const_get( constant )
Kernel::silence_warnings { Object.const_set( constant, val ) }
end
begin
block.call
ensure
constants.each do |constant, val|
Kernel::silence_warnings { Object.const_set( constant, saved_constants[ constant ] ) }
end
end
end
end
RSpec.configure do |config|
config.include ConstantMacros
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment