Sha256: df2d5e86f8487e1d772d9c57fc224de6d8ef66a8b8e9e027bdf0dc33f86e8aca

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'rspec_ext'

rspec do
  def self.swap_metadata scope = :all
    old_metadata = nil
    
    before scope do
      old_metadata = Micon.metadata
      Micon.swap_metadata old_metadata.deep_clone
    end
    
    after scope do
      Micon.swap_metadata old_metadata
    end
  end
  
  def self.with_environment options = {}, &block
    options = options.to_openobject    
    runtime_dir = options.delete(:runtime_dir) || './tmp'
    scope = options.delete(:before) || :each
    environment = options.delete(:environment) || :test
    raise "Invalid options :#{options.to_hash.keys.join(', :')}!" unless options.empty?
    
    swap_metadata
    
    before scope do
      rad.clear      
      Micon.after :config do |config|        
        config.set! environment: environment, runtime_dir: runtime_dir
      end
      
      block.call if block
      
      silence_logger!
      # Rad.initialize_plugin runtime_dir, environment
    end

    after scope do
      rad.clear  
    end    
  end
  
  inject(
    config: :config, 
    logger: :logger
  )
  
  def silence_logger!
    self.logger = Logger.new nil
  end  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rad_core-0.0.13 lib/rad/spec/environment.rb