spec/balboa/cli/parser_spec.rb in balboa-0.1.6 vs spec/balboa/cli/parser_spec.rb in balboa-0.1.7
- old
+ new
@@ -4,168 +4,140 @@
require_relative '../../../lib/balboa/cli/parser'
describe Balboa::CLI::Parser do
it 'parses a password option into a hash of configurations' do
- config = {}
argv = ['-p', 'test']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expect(config).to eq('password' => 'test')
end
it 'parses a password full option into a hash of configurations' do
- config = {}
argv = ['--password', 'test']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expect(config).to eq('password' => 'test')
end
it 'parses a project option into a hash of configurations' do
- config = {}
argv = ['-w', 'test']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expect(config).to eq('project' => 'test')
end
it 'parses a project full option into a hash of configurations' do
- config = {}
argv = ['--project', 'test']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expect(config).to eq('project' => 'test')
end
it 'parses a email option into a hash of configurations' do
- config = {}
argv = ['-e', 'test']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expect(config).to eq('email' => 'test')
end
it 'parses a email full option into a hash of configurations' do
- config = {}
argv = ['--email', 'test']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expect(config).to eq('email' => 'test')
end
it 'parses a config option into a hash of configurations' do
- config = {}
argv = ['-c', 'spec/fixtures/file.yml']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expectation = {
- 'email' => 'email',
- 'password' => 'password',
- 'project' => 'project',
- 'start_at' => '8',
- 'lunch_at' => '12',
- 'restart_at' => '13',
- 'leave_at' => '17',
- 'skips' => []
+ 'email' => 'email',
+ 'password' => 'password',
+ 'project' => 'project',
+ 'start_at' => '8',
+ 'lunch_at' => '12',
+ 'restart_at' => '13',
+ 'skip_defaults' => true,
+ 'leave_at' => '17',
+ 'skips' => []
}
expect(config).to eq(expectation)
end
it 'parses a config full option into a hash of configurations' do
- config = {}
argv = ['--config', 'spec/fixtures/file.yml']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expectation = {
- 'email' => 'email',
- 'password' => 'password',
- 'project' => 'project',
- 'start_at' => '8',
- 'lunch_at' => '12',
- 'restart_at' => '13',
- 'leave_at' => '17',
- 'skips' => []
+ 'email' => 'email',
+ 'password' => 'password',
+ 'project' => 'project',
+ 'start_at' => '8',
+ 'lunch_at' => '12',
+ 'restart_at' => '13',
+ 'skip_defaults' => true,
+ 'leave_at' => '17',
+ 'skips' => []
}
expect(config).to eq(expectation)
end
it 'raises ENOENT on invalid path to file' do
- config = {}
argv = ['-c', 'wrong path to file']
- parser = described_class.new(argv, config)
+ parser = described_class.new(argv)
expect { parser.parse }.to raise_error(Errno::ENOENT)
end
it 'parses a skipped date option into a hash of configurations' do
- config = {}
argv = ['-s', '13/06/1992,15/06/2002']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expectation = {
'skips' => [
Date.new(1992, 6, 13), Date.new(2002, 6, 15)
]
}
expect(config).to eq(expectation)
end
it 'raises argument error in case of a wrong date format' do
- config = {}
argv = ['-s', 'test']
+ parser = described_class.new(argv)
- parser = described_class.new(argv, config)
-
expect { parser.parse }.to raise_error(ArgumentError)
end
it 'parses a skipped date full option into a hash of configurations' do
- config = {}
argv = ['--skip', '12/06/1992,12/06/1992']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expectation = {
'skips' => [
Date.new(1992, 6, 12), Date.new(1992, 6, 12)
]
}
expect(config).to eq(expectation)
end
it 'parses options that override or fulfill config' do
- config = {
- 'password' => '1',
- 'project' => '3'
- }
argv = ['-p', '3', '-e', '2', '-w', '1']
+ config = described_class.parse(argv)
- described_class.parse(argv, config)
-
expectation = {
'password' => '3',
'email' => '2',
'project' => '1'
}
-
expect(config).to eq(expectation)
end
it 'raises on invalid arguments' do
- config = {}
argv = ['-z']
- parser = described_class.new(argv, config)
+ parser = described_class.new(argv)
expect { parser.parse }.to raise_error(OptionParser::InvalidOption)
end
end