Module: Brut::SpecSupport::CLICommandSupport

Defined in:
lib/brut/spec_support/cli_command_support.rb

Overview

Convienience methods included in tests for CLI commands

Defined Under Namespace

Classes: CapturingExecutor

Instance Method Summary collapse

Instance Method Details

#test_execution_context(argv: [], options: {}, env: {}, stdin: StringIO.new, stdout: StringIO.new, stderr: StringIO.new, executor: :default) ⇒ Object

Create an ExecutionContext suitable for any command, but which allows manipulating the data as needed for your test, or to access the various IO streams used by the command.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/brut/spec_support/cli_command_support.rb', line 26

def test_execution_context(
  argv: [],
  options: {},
  env: {},
  stdin: StringIO.new,
  stdout: StringIO.new,
  stderr: StringIO.new,
  executor: :default
)
  Brut::CLI::Commands::ExecutionContext.new(
    argv:,
    options: Brut::CLI::Options.new({ "log-level": "error" }.merge(options)),
    env:,
    stdin:,
    stdout:,
    stderr:,
    executor: executor == :default ? CapturingExecutor.new(out: stdout, err: stderr) : executor,
  )
end