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