spec/firebrew/command_line_spec.rb in firebrew-0.1.3 vs spec/firebrew/command_line_spec.rb in firebrew-0.2.0

- old
+ new

@@ -8,16 +8,23 @@ end let(:args){''} context 'when the command was invalid' do let(:args){'invalid-command'} - it { expect{subject}.to raise_error(Firebrew::CommandLineError) } + it { expect{subject}.to raise_error(Firebrew::CommandLineError, 'Invalid command: invalid-command') } end context 'when the options was invalid' do - let(:args){'install --invalid-option'} - it { expect{subject}.to raise_error(Firebrew::CommandLineError) } + describe 'invalid option' do + let(:args){'install --invalid-option'} + it { expect{subject}.to raise_error(Firebrew::CommandLineError, 'Invalid option: --invalid-option') } + end + + describe 'MissingArgument' do + let(:args){'install --firefox'} + it { expect{subject}.to raise_error(Firebrew::CommandLineError, 'Missing argument: --firefox') } + end end describe '#arguments()' do subject { super().arguments } @@ -102,10 +109,39 @@ params: {}, config: {} ) end end + + describe 'profile command' do + let(:args){'profile'} + it 'should parse' do + is_expected.to eq( + command: :profile, + params: {}, + config: {} + ) + end + + context 'with options' do + let(:args){'profile -a name --attribute=is_default'} + it 'should parse' do + is_expected.to eq( + command: :profile, + params: { + attribute: 'is_default' + }, + config: {} + ) + end + + context 'with invalid options' do + let(:args){'profile -a hoge'} + it { expect{subject}.to raise_error(Firebrew::CommandLineError, 'Invalid argument: -a hoge') } + end + end + end end describe '::execute(&block)' do subject do begin @@ -128,22 +164,28 @@ it { expect(subject[0]).to eq(0) } end context 'when the `Firebrew::Error` was thrown' do let(:exeption){raise Firebrew::CommandLineError, 'CommandLineError message'} - it { expect(subject[0]).to eq(6) } + it { expect(subject[0]).to eq(1) } it { expect(subject[1]).to eq('CommandLineError message') } end + context 'when the `Firebrew::OperationAlreadyCompletedError` was thrown' do + let(:exeption){raise Firebrew::OperationAlreadyCompletedError, 'OperationAlreadyCompletedError message'} + it { expect(subject[0]).to eq(2) } + it { expect(subject[1]).to eq('OperationAlreadyCompletedError message') } + end + context 'when the `SystemExit` was thrown' do let(:exeption){abort 'abort message'} - it { expect(subject[0]).to eq(1) } + it { expect(subject[0]).to eq(0) } it { expect(subject[1]).to eq('abort message') } end context 'when the unknown exception was thrown' do let(:exeption){raise StandardError, 'StandardError message'} - it { expect(subject[0]).to eq(255) } + it { expect(subject[0]).to eq(1) } it { expect(subject[1]).to match(/^#<StandardError: StandardError message>/) } end end end end