Sha256: c84d15121d3d2e69836b73abf5d54e3033b695debe21d3e2ff6ea333facb8029

Contents?: true

Size: 1.34 KB

Versions: 64

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8
require 'spec_helper'

RSpec.describe FeduxOrgStdlib::Environment do
  context '#isolated_environment' do
    it 'runs command in isolated environment' do
      klass = Class.new do
        include FeduxOrgStdlib::Environment 

        def test_env
          isolated_environment 'TEST_VAR' => 'this is a test' do
            ENV['TEST_VAR']
          end
        end
      end

      expect(klass.new.test_env).to eq('this is a test')
    end

    it 'let you define an environment before running a command' do
      klass = Class.new do
        include FeduxOrgStdlib::Environment 

        def test_env
          isolated_environment({}, { clear: true }) do

            #are set by the terminal and can hardly be cleared
            ENV.delete('COLUMNS')
            ENV.delete('LINES')

            ENV.to_hash
          end
        end
      end

      expect(klass.new.test_env).to eq({})
    end

    it 'restores environment although an exception occured' do
      klass = Class.new do
        include FeduxOrgStdlib::Environment 

        def test_env
          ENV['TEST_VAR'] = 'TEST'

          begin
            isolated_environment({}, { clear: true }) do
              raise
            end
          rescue
          end

          ENV['TEST_VAR']
        end
      end

      expect(klass.new.test_env).to eq('TEST')
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.7.21 spec/environment_spec.rb
fedux_org-stdlib-0.7.20 spec/environment_spec.rb
fedux_org-stdlib-0.7.19 spec/environment_spec.rb
fedux_org-stdlib-0.7.18 spec/environment_spec.rb
fedux_org-stdlib-0.7.17 spec/environment_spec.rb
fedux_org-stdlib-0.7.16 spec/environment_spec.rb
fedux_org-stdlib-0.7.15 spec/environment_spec.rb
fedux_org-stdlib-0.7.14 spec/environment_spec.rb
fedux_org-stdlib-0.7.12 spec/environment_spec.rb
fedux_org-stdlib-0.7.11 spec/environment_spec.rb
fedux_org-stdlib-0.7.10 spec/environment_spec.rb
fedux_org-stdlib-0.7.8 spec/environment_spec.rb
fedux_org-stdlib-0.7.7 spec/environment_spec.rb
fedux_org-stdlib-0.7.6 spec/environment_spec.rb
fedux_org-stdlib-0.7.5 spec/environment_spec.rb
fedux_org-stdlib-0.7.4 spec/environment_spec.rb
fedux_org-stdlib-0.7.3 spec/environment_spec.rb
fedux_org-stdlib-0.7.2 spec/environment_spec.rb
fedux_org-stdlib-0.7.1 spec/environment_spec.rb
fedux_org-stdlib-0.7.0 spec/environment_spec.rb