Sha256: 1cf8434147ba2dc40826a70772883cabda733854b8632c75b8f91fe923585b9b

Contents?: true

Size: 1.43 KB

Versions: 56

Compression:

Stored size: 1.43 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'

          # rubocop:disable Lint/HandleExceptions
          begin
            isolated_environment({}, { clear: true }) do
              fail
            end
          rescue
          end
          # rubocop:enable Lint/HandleExceptions

          ENV['TEST_VAR']
        end
      end

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

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.11.18 spec/environment_spec.rb
fedux_org-stdlib-0.11.17 spec/environment_spec.rb
fedux_org-stdlib-0.11.16 spec/environment_spec.rb
fedux_org-stdlib-0.11.15 spec/environment_spec.rb
fedux_org-stdlib-0.11.14 spec/environment_spec.rb
fedux_org-stdlib-0.11.12 spec/environment_spec.rb
fedux_org-stdlib-0.11.11 spec/environment_spec.rb
fedux_org-stdlib-0.11.9 spec/environment_spec.rb
fedux_org-stdlib-0.11.8 spec/environment_spec.rb
fedux_org-stdlib-0.11.7 spec/environment_spec.rb
fedux_org-stdlib-0.11.6 spec/environment_spec.rb
fedux_org-stdlib-0.11.5 spec/environment_spec.rb
fedux_org-stdlib-0.11.4 spec/environment_spec.rb
fedux_org-stdlib-0.11.3 spec/environment_spec.rb
fedux_org-stdlib-0.11.2 spec/environment_spec.rb
fedux_org-stdlib-0.11.1 spec/environment_spec.rb
fedux_org-stdlib-0.11.0 spec/environment_spec.rb
fedux_org-stdlib-0.10.9 spec/environment_spec.rb
fedux_org-stdlib-0.10.8 spec/environment_spec.rb
fedux_org-stdlib-0.10.7 spec/environment_spec.rb