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.8.6 spec/environment_spec.rb
fedux_org-stdlib-0.8.5 spec/environment_spec.rb
fedux_org-stdlib-0.8.4 spec/environment_spec.rb
fedux_org-stdlib-0.8.3 spec/environment_spec.rb
fedux_org-stdlib-0.8.0 spec/environment_spec.rb
fedux_org-stdlib-0.7.33 spec/environment_spec.rb
fedux_org-stdlib-0.7.31 spec/environment_spec.rb
fedux_org-stdlib-0.7.30 spec/environment_spec.rb
fedux_org-stdlib-0.7.29 spec/environment_spec.rb
fedux_org-stdlib-0.7.28 spec/environment_spec.rb
fedux_org-stdlib-0.7.27 spec/environment_spec.rb
fedux_org-stdlib-0.7.26 spec/environment_spec.rb
fedux_org-stdlib-0.7.25 spec/environment_spec.rb
fedux_org-stdlib-0.7.24 spec/environment_spec.rb
fedux_org-stdlib-0.7.23 spec/environment_spec.rb
fedux_org-stdlib-0.7.22 spec/environment_spec.rb