Sha256: e4f5dac1eb99432e167f2fae57c146b1b91e6501deade4b11079deb6264449ca

Contents?: true

Size: 518 Bytes

Versions: 2

Compression:

Stored size: 518 Bytes

Contents

require 'rails'

module EnvHelpers
  private

  def with_rails_env(env)
    Rails.instance_variable_set :@_env, nil
    switch_env 'RAILS_ENV', env do
      switch_env 'RACK_ENV', nil do
        yield
      end
    end
  end

  def with_rack_env(env)
    Rails.instance_variable_set :@_env, nil
    switch_env 'RACK_ENV', env do
      switch_env 'RAILS_ENV', nil do
        yield
      end
    end
  end

  def switch_env(key, value)
    old, ENV[key] = ENV[key], value
    yield
  ensure
    ENV[key] = old
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activejob-lock-0.0.2 rails/railties/test/env_helpers.rb
activejob-lock-0.0.1 rails/railties/test/env_helpers.rb