Module: RSpec::SleepingKingStudios::Sandbox

Defined in:
lib/rspec/sleeping_king_studios/sandbox.rb

Overview

Helper for running RSpec files in isolation.

Sandboxed files can be used to test enhancements to RSpec itself, such as custom matchers or shared or deferred example groups.

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Class Method Details

.run(*files) ⇒ RSpec::SleepingKingStudios::Result

Runs the specified spec files in a sandbox.

The examples and other RSpec code in the files will not be added to the current RSpec process.

Parameters:

  • files (Array<String>)

    the file names or patterns for the spec files to run.

Returns:

  • (RSpec::SleepingKingStudios::Result)

    the status and output of the spec run.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rspec/sleeping_king_studios/sandbox.rb', line 63

def run(*files) # rubocop:disable Metrics/MethodLength
  if files.empty?
    raise ArgumentError, 'must specify at least one file or pattern'
  end

  err    = StringIO.new
  out    = StringIO.new
  status = nil
  args   = format_args(*files)

  RSpec::Core::Sandbox.sandboxed do |config|
    config.filter_run_when_matching :focus

    status = RSpec::Core::Runner.run(args, err, out)
  end

  build_result(err:, out:, status:)
end