Improve CLI API related to standard output
This commit is contained in:
parent
d670d5dbdd
commit
dc9e7f1412
@ -3,11 +3,11 @@ module Producer
|
||||
class CLI
|
||||
USAGE = "Usage: #{File.basename $0} recipe_file"
|
||||
|
||||
attr_reader :arguments
|
||||
attr_reader :arguments, :stdout
|
||||
|
||||
def initialize(arguments, stdout = $stdout)
|
||||
@stdout = stdout
|
||||
def initialize(arguments, stdout: $stdout)
|
||||
@arguments = arguments
|
||||
@stdout = stdout
|
||||
end
|
||||
|
||||
def run!
|
||||
|
@ -7,11 +7,15 @@ module Producer::Core
|
||||
|
||||
let(:recipe_file) { fixture_path_for 'recipes/empty.rb' }
|
||||
let(:arguments) { [recipe_file] }
|
||||
subject(:cli) { CLI.new(arguments) }
|
||||
let(:stdout) { StringIO.new }
|
||||
|
||||
subject(:cli) { CLI.new(arguments, stdout: stdout) }
|
||||
|
||||
describe '#initialize' do
|
||||
subject(:cli) { CLI.new(arguments) }
|
||||
|
||||
it 'assigns $stdout as the default standard output' do
|
||||
expect(cli.instance_eval { @stdout }).to be $stdout
|
||||
expect(cli.stdout).to be $stdout
|
||||
end
|
||||
end
|
||||
|
||||
@ -21,6 +25,12 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stdout' do
|
||||
it 'returns the assigned standard output' do
|
||||
expect(cli.stdout).to be stdout
|
||||
end
|
||||
end
|
||||
|
||||
describe '#run!' do
|
||||
it 'checks the arguments' do
|
||||
expect(cli).to receive :check_arguments!
|
||||
@ -43,8 +53,6 @@ module Producer::Core
|
||||
|
||||
context 'when recipe argument is missing' do
|
||||
let(:arguments) { [] }
|
||||
let(:stdout) { StringIO.new }
|
||||
subject(:cli) { CLI.new(arguments, stdout) }
|
||||
|
||||
it 'exits with a return status of 64' do
|
||||
expect { cli.check_arguments! }.to raise_error(SystemExit) { |e|
|
||||
|
Loading…
x
Reference in New Issue
Block a user