Sha256: 927b001cb00cb90afba445c16828e75294ecb92dbe81c912b9af7d85d7b28dc8

Contents?: true

Size: 737 Bytes

Versions: 47

Compression:

Stored size: 737 Bytes

Contents

module InEnvironment
  private

  # Create an environment for a test. At the completion of the yielded
  # block, the environment is restored to its original conditions.
  def in_environment(settings=nil)
    settings ||= {}
    full_settings = {"RAKEOPT" => nil}.merge(settings)
    original_settings = set_env(full_settings)
    yield
  ensure
    set_env(original_settings) rescue nil
  end

  # Set the environment according to the settings hash.
  def set_env(settings) # :nodoc:
    result = {}

    settings.each do |k, v|
      result[k] = ENV[k]

      if k == 'PWD'
        result[k] = Dir.pwd
        Dir.chdir(v)
      elsif v.nil?
        ENV.delete(k)
      else
        ENV[k] = v
      end
    end

    result
  end

end

Version data entries

47 entries across 34 versions & 5 rubygems

Version Path
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.6.2 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.6.1 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.6.0 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.5.4 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.5.3 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.5.2 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.5.2 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.5.1 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.5.1 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.5.0 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb
dirty_history-0.5.0 dirty_history/ruby/1.9.1/gems/rake-0.9.2/test/in_environment.rb