Module: RSpec::SleepingKingStudios::Concerns::WrapEnv::ClassMethods

Defined in:
lib/rspec/sleeping_king_studios/concerns/wrap_env.rb

Overview

Class methods to define when including RSpec::SleepingKingStudios::Concerns::WrapEnv in a class.

Instance Method Summary collapse

Instance Method Details

#wrap_env(key, value = nil, &block) ⇒ Object Also known as: stub_env



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec/sleeping_king_studios/concerns/wrap_env.rb', line 16

def wrap_env key, value = nil, &block
  around(:example) do |wrapped_example|
    begin
      if block_given?
        example = wrapped_example.example
        value   = example.instance_exec(&block)
      end # if

      prior_value = ENV[key]
      ENV[key]    = value

      wrapped_example.call
    ensure
      ENV[key]    = prior_value
    end # begin-ensure
  end # around example
end