module RSpec::SleepingKingStudios::Sandbox
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.
Constants
- Result
-
Value class for the result of calling a sandboxed spec file.
Public Class Methods
Source
# 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
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.
@param files [Array<String>] the file names or patterns for the spec
files to run.
@return [RSpec::SleepingKingStudios::Result] the status and output of
the spec run.
Private Class Methods
Source
# File lib/rspec/sleeping_king_studios/sandbox.rb, line 84 def build_result(err:, out:, status:) *output, raw_json = out.string.lines Result.new( output: output.join, errors: err.string, json: JSON.parse(raw_json), status: ) end
Source
# File lib/rspec/sleeping_king_studios/sandbox.rb, line 95 def format_args(*files) [ '--format=json', '--format=doc', '--order=defined', "--pattern=#{files.join(',')}" ] end