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.10.6 spec/environment_spec.rb
fedux_org-stdlib-0.10.5 spec/environment_spec.rb
fedux_org-stdlib-0.10.4 spec/environment_spec.rb
fedux_org-stdlib-0.10.3 spec/environment_spec.rb
fedux_org-stdlib-0.10.2 spec/environment_spec.rb
fedux_org-stdlib-0.10.1 spec/environment_spec.rb
fedux_org-stdlib-0.10.0 spec/environment_spec.rb
fedux_org-stdlib-0.9.8 spec/environment_spec.rb
fedux_org-stdlib-0.9.7 spec/environment_spec.rb
fedux_org-stdlib-0.9.6 spec/environment_spec.rb
fedux_org-stdlib-0.9.5 spec/environment_spec.rb
fedux_org-stdlib-0.9.4 spec/environment_spec.rb
fedux_org-stdlib-0.9.2 spec/environment_spec.rb
fedux_org-stdlib-0.9.1 spec/environment_spec.rb
fedux_org-stdlib-0.9.0 spec/environment_spec.rb
fedux_org-stdlib-0.8.11 spec/environment_spec.rb
fedux_org-stdlib-0.8.10 spec/environment_spec.rb
fedux_org-stdlib-0.8.9 spec/environment_spec.rb
fedux_org-stdlib-0.8.8 spec/environment_spec.rb
fedux_org-stdlib-0.8.7 spec/environment_spec.rb