Sha256: 2362feba203b0947e18f3c14339781f1dc240db4ece30c504d085e1719b4b3fc

Contents?: true

Size: 946 Bytes

Versions: 3

Compression:

Stored size: 946 Bytes

Contents

# frozen_string_literal: true

# RuboCop can be run in contexts where unexpected other libraries are included,
# which may interfere with its normal behavior. In order to test those
# situations, it may be necessary to require another library for the duration
# of one spec
module HostEnvironmentSimulatorHelper
  def in_its_own_process_with(*files)
    if ::Process.respond_to?(:fork)
      pid = ::Process.fork do
        # Need to write coverage result under different name
        if defined?(SimpleCov)
          SimpleCov.command_name "rspec_#{Process.pid}"
          SimpleCov.pid = Process.pid
        end

        files.each { |file| require file }
        yield
      end
      ::Process.wait(pid)

      # assert that the block did not fail
      expect($CHILD_STATUS).to be_success
    else
      warn 'Process.fork is not available.'
    end
  end
end

RSpec.configure do |config|
  config.include HostEnvironmentSimulatorHelper
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.45.0 lib/rubocop/rspec/host_environment_simulation_helper.rb
rubocop-0.44.1 lib/rubocop/rspec/host_environment_simulation_helper.rb
rubocop-0.44.0 lib/rubocop/rspec/host_environment_simulation_helper.rb