Sha256: 2571398cd31e47b4df5e6e2028de45f149af8c846ac94be9d09c4cfda7f99999
Contents?: true
Size: 815 Bytes
Versions: 221
Compression:
Stored size: 815 Bytes
Contents
class ConstMocker def initialize(*const_names) @const_names = const_names @const_states = {} @const_names.each{|const_name| @const_states[const_name] = Object.const_defined?(const_name) ? Object.const_get(const_name) : nil } end def remove @const_names.each{|const_name| Object.send :remove_const, const_name if Object.const_defined?(const_name) } end def declare @const_names.each{|const_name| Object.class_eval "class #{const_name}; end;" unless Object.const_defined?(const_name) } end def restore remove @const_states.each_pair{|const_name, const| Object.const_set const_name, const if const } end def self.mock(*const_names, &block) cm = new(*const_names) yield(cm) cm.restore true end end
Version data entries
221 entries across 221 versions & 8 rubygems