Sha256: 9833df0cef6147685a708aad096d360b59fb0af31d31d0f8f200246c5d40a88b

Contents?: true

Size: 887 Bytes

Versions: 11

Compression:

Stored size: 887 Bytes

Contents

# encoding: utf-8

require 'tmpdir'
require 'fileutils'

shared_context 'isolated environment', :isolated_environment do
  around do |example|
    Dir.mktmpdir do |tmpdir|
      original_home = ENV['HOME']

      # Make sure to expand all symlinks in the path first. Otherwise we may
      # get mismatched pathnames when loading config files later on.
      tmpdir = File.realpath(tmpdir)

      # Make upwards search for .rubocop.yml files stop at this directory.
      Rubocop::ConfigLoader.root_level = tmpdir

      begin
        virtual_home = File.expand_path(File.join(tmpdir, 'home'))
        Dir.mkdir(virtual_home)
        ENV['HOME'] = virtual_home

        working_dir = File.join(tmpdir, 'work')
        Dir.mkdir(working_dir)

        Dir.chdir(working_dir) do
          example.run
        end
      ensure
        ENV['HOME'] = original_home
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
ridecharge-rubocop-0.0.1 spec/support/isolated_environment.rb
rubocop-0.22.0 spec/support/isolated_environment.rb
rubocop-0.21.0 spec/support/isolated_environment.rb
rubocop-0.20.1 spec/support/isolated_environment.rb
rubocop-0.20.0 spec/support/isolated_environment.rb
rubocop-0.19.1 spec/support/isolated_environment.rb
rubocop-0.19.0 spec/support/isolated_environment.rb
rubocop-0.18.1 spec/support/isolated_environment.rb
rubocop-0.18.0 spec/support/isolated_environment.rb
rubocop-0.17.0 spec/support/isolated_environment.rb
rubocop-0.16.0 spec/support/isolated_environment.rb