Sha256: b798668e37372d6e530ef04c38f03257b89634487cd0199f6843ebb35e28d7ea

Contents?: true

Size: 964 Bytes

Versions: 7

Compression:

Stored size: 964 Bytes

Contents

# encoding: utf-8
# 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

7 entries across 7 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/rspec/host_environment_simulation_helper.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/rspec/host_environment_simulation_helper.rb
rubocop-0.43.0 lib/rubocop/rspec/host_environment_simulation_helper.rb
rubocop-0.42.0 lib/rubocop/rspec/host_environment_simulation_helper.rb
rubocop-0.41.2 lib/rubocop/rspec/host_environment_simulation_helper.rb
rubocop-0.41.1 lib/rubocop/rspec/host_environment_simulation_helper.rb
rubocop-0.41.0 lib/rubocop/rspec/host_environment_simulation_helper.rb