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
-
#test_execution_context(argv: [], options: {}, env: {}, stdin: StringIO.new, stdout: StringIO.new, stderr: StringIO.new, executor: :default, logger: :default) {|executor| ... } ⇒ 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.
Instance Method Details
#test_execution_context(argv: [], options: {}, env: {}, stdin: StringIO.new, stdout: StringIO.new, stderr: StringIO.new, executor: :default, logger: :default) {|executor| ... } ⇒ 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. don’t want to pass in a value for this. The default is an implementation that captures all the commands that were executed for your later inspection via the ‘have_executed` matcher.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/brut/spec_support/cli_command_support.rb', line 73 def test_execution_context( argv: [], options: {}, env: {}, stdin: StringIO.new, stdout: StringIO.new, stderr: StringIO.new, executor: :default, logger: :default, &block ) logger = if logger == :default Brut::CLI::Logger.new(app_name: $0, stdout:, stderr:) else logger end executor = if executor == :default CapturingExecutor.new(out: stdout, err: stderr, logger:) else executor end if block block.(executor) end = .map { |key,value| [ key.to_sym, value ] }.to_h Brut::CLI::Commands::ExecutionContext.new( argv:, options: Brut::CLI::Options.new({ "log-level": "error" }.merge()), env: { "NO_COLOR" => "1" }.merge(env), stdin:, stdout:, stderr:, executor: ) end |