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

Version Path
active_scaffold_vho-4.0.0 test/const_mocker.rb
active_scaffold_vho-3.2.14 test/const_mocker.rb
active_scaffold_vho-3.2.13 test/const_mocker.rb
active_scaffold-sequel-0.8.0 test/const_mocker.rb
active_scaffold-sequel-0.7.1 test/const_mocker.rb
active_scaffold_vho-3.2.12 test/const_mocker.rb
active_scaffold_vho-3.2.11 test/const_mocker.rb
active_scaffold_vho-3.2.10 test/const_mocker.rb
active_scaffold_vho-3.2.9 test/const_mocker.rb
active_scaffold_vho-3.2.8 test/const_mocker.rb
active_scaffold_vho-3.2.7 test/const_mocker.rb
active_scaffold_vho-3.2.6 test/const_mocker.rb
active_scaffold_vho-3.2.5 test/const_mocker.rb
active_scaffold_vho-3.2.4 test/const_mocker.rb
active_scaffold_vho-3.2.3 test/const_mocker.rb
active_scaffold_vho-3.2.2 test/const_mocker.rb
active_scaffold_vho-3.2.1 test/const_mocker.rb
active_scaffold-sequel-0.7.0 test/const_mocker.rb
active_scaffold_vho-3.2.0 test/const_mocker.rb
active_scaffold_vho-3.0.31 test/const_mocker.rb