Sha256: c9b721a698808542dbe0b6631e5a4234ba36d8023ad0f6a4cbb67a531d44c845

Contents?: true

Size: 533 Bytes

Versions: 8

Compression:

Stored size: 533 Bytes

Contents

module WithEnvironment
  def with_environment(env)
    prev_env = {
      'PATH' => ENV['PATH']
    }

    # Remove rbenv version specific paths to restore environment to normal,
    # non-versioned state.
    ENV['PATH'] = ENV['PATH'].split(/:/).reject do |path|
      path.match(%r[/\.rbenv/versions/])
    end.join(':')

    env.each do |key, value|
      key = key.to_s

      prev_env[key] = ENV[key]
      ENV[key] = value
    end

    yield

  ensure
    prev_env.each do |key, value|
      ENV[key] = value
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
postageapp-1.4.2 test/with_environment.rb
postageapp-1.4.1 test/with_environment.rb
postageapp-1.4.0 test/with_environment.rb
postageapp-1.3.1 test/with_environment.rb
postageapp-1.3.0 test/with_environment.rb
postageapp-1.2.6 test/with_environment.rb
postageapp-1.2.5 test/with_environment.rb
postageapp-1.2.0 test/with_environment.rb