Sha256: b7ed50a1b7c489326ee1903e647273e02e572aa9a72dce3418aa00b693615b4c

Contents?: true

Size: 1.38 KB

Versions: 16

Compression:

Stored size: 1.38 KB

Contents

module RSpec
  module Support
    module InSubProcess
      if Process.respond_to?(:fork) && !(Ruby.jruby? && RUBY_VERSION == '1.8.7')

        # Useful as a way to isolate a global change to a subprocess.

        # rubocop:disable MethodLength
        def in_sub_process(prevent_warnings=true)
          readme, writeme = IO.pipe

          pid = Process.fork do
            exception = nil
            warning_preventer = $stderr = RSpec::Support::StdErrSplitter.new($stderr)

            begin
              yield
              warning_preventer.verify_no_warnings! if prevent_warnings
            rescue Exception => e
              exception = e
            end

            writeme.write Marshal.dump(exception)

            readme.close
            writeme.close
            exit! # prevent at_exit hooks from running (e.g. minitest)
          end

          writeme.close
          Process.waitpid(pid)

          exception = Marshal.load(readme.read)
          readme.close

          raise exception if exception
        end
        # rubocop:enable MethodLength
        alias :in_sub_process_if_possible :in_sub_process
      else
        def in_sub_process(*)
          skip "This spec requires forking to work properly, " \
               "and your platform does not support forking"
        end

        def in_sub_process_if_possible(*)
          yield
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 9 rubygems

Version Path
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
sublimetheme-1.0.1 path/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
sublimetheme-1.0.0 path/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
geminfo-0.1.0 path/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rspec-support-3.3.0/lib/rspec/support/spec/in_sub_process.rb
rspec-support-3.3.0 lib/rspec/support/spec/in_sub_process.rb