Module: SpecOompaLoompa::SpecHelpers
- Defined in:
- lib/spec_oompa_loompa/spec_helpers.rb
Instance Method Summary collapse
-
#with_constants(constants, &block) ⇒ Object
TODO : Write specs Easily alter constants within specs to test effects.
Instance Method Details
#with_constants(constants, &block) ⇒ Object
TODO : Write specs Easily alter constants within specs to test effects
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spec_oompa_loompa/spec_helpers.rb', line 11 def with_constants(constants, &block) saved_constants = {} constants.each do |constant, val| parts = constant.to_s.split("::") konst_string = parts.pop konst_owner = parts.inject(Object){|k,p| k.const_get(p)} key = [konst_owner, konst_string] saved_constants[ key ] = konst_owner.const_get( konst_string ) Kernel::silence_warnings { konst_owner.const_set( konst_string, val ) } end begin block.call ensure saved_constants.each do |(konst_owner, konst_string), orig_value| Kernel::silence_warnings { konst_owner.const_set( konst_string, orig_value ) } end end end |