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