list-tool 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/clt +12 -0
- data/lib/list_tool/app/commands/add_item_command.rb +39 -0
- data/lib/list_tool/app/commands/add_list_command.rb +30 -0
- data/lib/list_tool/app/commands/delete_item_command.rb +39 -0
- data/lib/list_tool/app/commands/delete_list_command.rb +32 -0
- data/lib/list_tool/app/commands/help_command.rb +24 -0
- data/lib/list_tool/app/commands/rename_list_command.rb +34 -0
- data/lib/list_tool/app/commands/replace_item_command.rb +34 -0
- data/lib/list_tool/app/commands/show_items_command.rb +35 -0
- data/lib/list_tool/app/commands/show_lists_command.rb +26 -0
- data/lib/list_tool/app/commands/unknown_command.rb +26 -0
- data/lib/list_tool/app/commands/use_command.rb +31 -0
- data/lib/list_tool/app/commands/version_command.rb +24 -0
- data/lib/list_tool/app/commands.rb +43 -0
- data/lib/list_tool/app/printer.rb +41 -0
- data/lib/list_tool/app/runner.rb +54 -0
- data/lib/list_tool/app/string.rb +9 -0
- data/lib/list_tool/app.rb +9 -0
- data/lib/list_tool/data.rb +75 -0
- data/lib/list_tool/file_manager.rb +27 -0
- data/lib/list_tool/item.rb +23 -0
- data/lib/list_tool/json_parser.rb +11 -0
- data/lib/list_tool/list.rb +88 -0
- data/lib/list_tool/lister.rb +81 -0
- data/lib/list_tool/version.rb +3 -0
- data/lib/list_tool.rb +19 -0
- data/list_tool.gemspec +31 -0
- data/spec/fixtures/data.json +18 -0
- data/spec/list_tool/app/commands/add_item_command_spec.rb +108 -0
- data/spec/list_tool/app/commands/add_list_command_spec.rb +74 -0
- data/spec/list_tool/app/commands/delete_item_command_spec.rb +116 -0
- data/spec/list_tool/app/commands/delete_list_command_spec.rb +89 -0
- data/spec/list_tool/app/commands/help_command_spec.rb +41 -0
- data/spec/list_tool/app/commands/rename_list_command_spec.rb +95 -0
- data/spec/list_tool/app/commands/replace_item_command_spec.rb +97 -0
- data/spec/list_tool/app/commands/show_items_command_spec.rb +111 -0
- data/spec/list_tool/app/commands/show_lists_command_spec.rb +48 -0
- data/spec/list_tool/app/commands/unknown_command_spec.rb +31 -0
- data/spec/list_tool/app/commands/use_command_spec.rb +79 -0
- data/spec/list_tool/app/commands/version_comand_spec.rb +41 -0
- data/spec/list_tool/app/commands_spec.rb +80 -0
- data/spec/list_tool/app/printer_spec.rb +54 -0
- data/spec/list_tool/app/runner_spec.rb +166 -0
- data/spec/list_tool/app/string_spec.rb +32 -0
- data/spec/list_tool/data_spec.rb +257 -0
- data/spec/list_tool/file_manager_spec.rb +84 -0
- data/spec/list_tool/item_spec.rb +42 -0
- data/spec/list_tool/json_parser_spec.rb +14 -0
- data/spec/list_tool/list_spec.rb +221 -0
- data/spec/list_tool/lister_spec.rb +186 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/factory.rb +33 -0
- metadata +213 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
require_relative '../../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe ListTool::App::DeleteListCommand do
|
4
|
+
subject { ListTool::App::DeleteListCommand }
|
5
|
+
|
6
|
+
describe '.match?' do
|
7
|
+
it 'returns true if "dl" or "del-list" given' do
|
8
|
+
expect( subject.match? "dl" ).to be_truthy
|
9
|
+
expect( subject.match? "del-list" ).to be_truthy
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns false otherwise' do
|
13
|
+
expect( subject.match? "some-arg" ).to be_falsey
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe '.parse' do
|
19
|
+
it 'shifts 1 arg from ARGV' do
|
20
|
+
argv = ['2']
|
21
|
+
expect( argv ).to receive(:shift).with(no_args).and_return('2')
|
22
|
+
subject.parse argv
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'success' do
|
26
|
+
it 'returns {list: list_num}' do
|
27
|
+
expect( subject.parse(['2']) ).to eq( {list: 1} )
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'failure' do
|
32
|
+
|
33
|
+
context 'when list number not given' do
|
34
|
+
it 'raises ArgumentError' do
|
35
|
+
expect{ subject.parse[] }.to raise_error(ArgumentError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when list number is not a integer' do
|
40
|
+
it 'raises ArgumentError' do
|
41
|
+
expect{ subject.parse(["not_an_integer"]) }.to raise_error(ArgumentError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when list number is less than 1' do
|
46
|
+
it 'raises ArgumentError' do
|
47
|
+
expect{ subject.parse(['0']) }.to raise_error( ArgumentError )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when not an array given' do
|
52
|
+
it 'raises ArgumentError' do
|
53
|
+
expect{ subject.parse "not_an_array" }.to raise_error( ArgumentError )
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
describe '.execute' do
|
63
|
+
let (:lister) { ListTool::Lister.new }
|
64
|
+
|
65
|
+
context 'success' do
|
66
|
+
it 'calls lister.delete_list with given list number' do
|
67
|
+
expect(lister).to receive(:delete_list).with(2).and_return("not_nil")
|
68
|
+
subject.execute({list: 2}, lister)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'failure' do
|
73
|
+
context 'when list not found' do
|
74
|
+
it 'raises ListNotFoundError' do
|
75
|
+
expect{ subject.execute({list: -2}, lister) }.to raise_error(ListTool::ListNotFoundError )
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
describe '.help' do
|
84
|
+
it 'returns help message' do
|
85
|
+
expect( subject.help ).to be_a String
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative '../../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe ListTool::App::HelpCommand do
|
4
|
+
subject { ListTool::App::HelpCommand }
|
5
|
+
|
6
|
+
describe '.match?' do
|
7
|
+
it 'returns true if "h", "-h", "help" or "--help" given' do
|
8
|
+
expect( subject.match? "h" ).to be_truthy
|
9
|
+
expect( subject.match? "-h" ).to be_truthy
|
10
|
+
expect( subject.match? "help" ).to be_truthy
|
11
|
+
expect( subject.match? "--help" ).to be_truthy
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns false otherwise' do
|
15
|
+
expect( subject.match? "some-arg" ).to be_falsey
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
describe '.parse' do
|
21
|
+
it 'always returns {}' do
|
22
|
+
expect( subject.parse nil ).to eq( {} )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
describe '.execute' do
|
28
|
+
it 'calls Printer.print_usage' do
|
29
|
+
expect(ListTool::App::Printer).to receive(:print_usage)
|
30
|
+
subject.execute( {}, nil )
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe '.help' do
|
36
|
+
it 'returns help message' do
|
37
|
+
expect( subject.help ).to be_a String
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require_relative '../../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe ListTool::App::RenameListCommand do
|
4
|
+
subject { ListTool::App::RenameListCommand }
|
5
|
+
|
6
|
+
describe '.match?' do
|
7
|
+
it 'returns true if "rl" or "rename-list" given' do
|
8
|
+
expect( subject.match? "rl" ).to be_truthy
|
9
|
+
expect( subject.match? "rename-list" ).to be_truthy
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns false otherwise' do
|
13
|
+
expect( subject.match? "some-arg" ).to be_falsey
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe '.parse' do
|
19
|
+
it 'shifts 2 arg from ARGV' do
|
20
|
+
argv = ['2', 'name']
|
21
|
+
expect( argv ).to receive(:shift).with(2).and_return(['2', 'name'])
|
22
|
+
subject.parse argv
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'success' do
|
26
|
+
it 'returns name and list num' do
|
27
|
+
expect( subject.parse(['2', 'new name']) ).to eq( {name: "new name", list: 1} )
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'failure' do
|
32
|
+
|
33
|
+
context 'when list number not given' do
|
34
|
+
it 'raises ArgumentError' do
|
35
|
+
expect{ subject.parse[] }.to raise_error(ArgumentError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when list number is not a integer' do
|
40
|
+
it 'raises ArgumentError' do
|
41
|
+
expect{ subject.parse(["not_an_integer", 'new name']) }.to raise_error(ArgumentError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when list number is less than 1' do
|
46
|
+
it 'raises ArgumentError' do
|
47
|
+
expect{ subject.parse(['0', 'new name']) }.to raise_error( ArgumentError )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when new name not given' do
|
52
|
+
it 'raises ArgumentError' do
|
53
|
+
expect{ subject.parse(["2"]) }.to raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when not an array given' do
|
58
|
+
it 'raises ArgumentError' do
|
59
|
+
expect{ subject.parse "not_an_array" }.to raise_error( ArgumentError )
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
describe '.execute' do
|
69
|
+
let (:lister) { ListTool::Lister.new }
|
70
|
+
|
71
|
+
context 'success' do
|
72
|
+
it 'calls lister.rename_list with given list number and name' do
|
73
|
+
expect(lister).to receive(:rename_list).with(2, "new name").and_return("not_nil")
|
74
|
+
subject.execute({name: 'new name', list: 2}, lister)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'failure' do
|
79
|
+
context 'when list not found' do
|
80
|
+
it 'raises ListNotFoundError' do
|
81
|
+
expect{ subject.execute({name: 'new name' ,list: -2}, lister) }.to raise_error(ListTool::ListNotFoundError )
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
describe '.help' do
|
90
|
+
it 'returns help message' do
|
91
|
+
expect( subject.help ).to be_a String
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require_relative '../../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe ListTool::App::ReplaceItemCommand do
|
4
|
+
subject { ListTool::App::ReplaceItemCommand }
|
5
|
+
|
6
|
+
describe '.match?' do
|
7
|
+
it 'returns true if "r" or "replace-item" given' do
|
8
|
+
expect( subject.match? "r" ).to be_truthy
|
9
|
+
expect( subject.match? "replace-item" ).to be_truthy
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns false otherwise' do
|
13
|
+
expect( subject.match? "some-arg" ).to be_falsey
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe '.parse' do
|
19
|
+
it 'shifts 2 arg from ARGV' do
|
20
|
+
argv = ['2', 'name']
|
21
|
+
expect( argv ).to receive(:shift).with(2).and_return(['2', 'name'])
|
22
|
+
subject.parse argv
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'success' do
|
26
|
+
it 'returns name and item num' do
|
27
|
+
expect( subject.parse(['2', 'new name']) ).to eq( {name: "new name", item: 1} )
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'failure' do
|
32
|
+
|
33
|
+
context 'when item number not given' do
|
34
|
+
it 'raises ArgumentError' do
|
35
|
+
expect{ subject.parse[] }.to raise_error(ArgumentError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when item number is not a integer' do
|
40
|
+
it 'raises ArgumentError' do
|
41
|
+
expect{ subject.parse(["not_an_integer", 'new name']) }.to raise_error(ArgumentError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when item number is less than 1' do
|
46
|
+
it 'raises ArgumentError' do
|
47
|
+
expect{ subject.parse(['0', 'new name']) }.to raise_error( ArgumentError )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when new name not given' do
|
52
|
+
it 'raises ArgumentError' do
|
53
|
+
expect{ subject.parse(["2"]) }.to raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when not an array given' do
|
58
|
+
it 'raises ArgumentError' do
|
59
|
+
expect{ subject.parse "not_an_array" }.to raise_error( ArgumentError )
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
describe '.execute' do
|
69
|
+
let (:lister) { ListTool::Lister.new }
|
70
|
+
|
71
|
+
context 'success' do
|
72
|
+
it 'calls lister.replace_item with given item number and name' do
|
73
|
+
expect(lister).to receive(:change_item).with(2, "new name").and_return("not_nil")
|
74
|
+
subject.execute({name: 'new name', item: 2}, lister)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'failure' do
|
79
|
+
|
80
|
+
context 'when item not found' do
|
81
|
+
it 'raises ItemNotFoundError' do
|
82
|
+
allow(lister).to receive(:change_item).and_return(nil)
|
83
|
+
expect{ subject.execute({name: 'new name', item: -2}, lister) }.to raise_error( ListTool::ItemNotFoundError )
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
describe '.help' do
|
92
|
+
it 'returns help message' do
|
93
|
+
expect( subject.help ).to be_a String
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require_relative '../../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe ListTool::App::ShowItemsCommand do
|
4
|
+
subject { ListTool::App::ShowItemsCommand }
|
5
|
+
|
6
|
+
describe '.match?' do
|
7
|
+
it 'returns true if "s" or "show-items" given' do
|
8
|
+
expect( subject.match? "s" ).to be_truthy
|
9
|
+
expect( subject.match? "show-items" ).to be_truthy
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns false otherwise' do
|
13
|
+
expect( subject.match? "some-arg" ).to be_falsey
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe '.parse' do
|
19
|
+
it 'shifts 1 arg from ARGV' do
|
20
|
+
argv = ['text']
|
21
|
+
expect( argv ).to receive(:shift).with(no_args)
|
22
|
+
subject.parse argv
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'success' do
|
26
|
+
context 'when list number is not given' do
|
27
|
+
it 'returns empty hash' do
|
28
|
+
expect( subject.parse([]) ).to eq( {} )
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when list number is given' do
|
33
|
+
it 'returns {list: list_num}' do
|
34
|
+
expect( subject.parse(["1"]) ).to eq( {list: 0} )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'failure' do
|
40
|
+
context 'when list number is not an integer' do
|
41
|
+
it 'raises ArgumentError' do
|
42
|
+
expect{ subject.parse(['not_an_int']) }.to raise_error( ArgumentError )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when list number is less than 1' do
|
47
|
+
it 'raises ArgumentError' do
|
48
|
+
expect{ subject.parse(['0']) }.to raise_error( ArgumentError )
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when not an array given' do
|
53
|
+
it 'raises ArgumentError' do
|
54
|
+
expect{ subject.parse "not_an_array" }.to raise_error( ArgumentError )
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
describe '.execute' do
|
63
|
+
let (:lister) { ListTool::Lister.new }
|
64
|
+
let (:printer) { ListTool::App::Printer }
|
65
|
+
|
66
|
+
context 'success' do
|
67
|
+
context 'list number not given' do
|
68
|
+
it 'gets default list contents' do
|
69
|
+
expect(lister).to receive(:list).with(no_args).and_return([])
|
70
|
+
allow(printer).to receive(:print_items)
|
71
|
+
subject.execute({}, lister)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'list number is given' do
|
76
|
+
it 'gets given list contents' do
|
77
|
+
expect(lister).to receive(:list).with(1).and_return([])
|
78
|
+
allow(printer).to receive(:print_items)
|
79
|
+
subject.execute({list: 1}, lister)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'calls printer.print_items' do
|
84
|
+
allow(lister).to receive(:list).with(no_args).and_return(['item1', 'item2'])
|
85
|
+
expect(printer).to receive(:print_items).with(['item1', 'item2'])
|
86
|
+
subject.execute({}, lister)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'failure' do
|
91
|
+
context 'when list not found' do
|
92
|
+
it 'raises ListNotFoundError' do
|
93
|
+
expect{ subject.execute({list: 2}, lister) }.to raise_error(ListTool::ListNotFoundError )
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when list not specified and no default list set' do
|
98
|
+
it 'raises NoDefaultListError' do
|
99
|
+
expect{ subject.execute({}, lister) }.to raise_error(ListTool::NoDefaultListError )
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
describe '.help' do
|
107
|
+
it 'returns help message' do
|
108
|
+
expect( subject.help ).to be_a String
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative '../../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe ListTool::App::ShowListsCommand do
|
4
|
+
subject { ListTool::App::ShowListsCommand }
|
5
|
+
|
6
|
+
describe '.match?' do
|
7
|
+
it 'returns true if "sl" or "show-lists" given' do
|
8
|
+
expect( subject.match? "sl" ).to be_truthy
|
9
|
+
expect( subject.match? "show-lists" ).to be_truthy
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns false otherwise' do
|
13
|
+
expect( subject.match? "some-arg" ).to be_falsey
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe '.parse' do
|
19
|
+
it 'returns {}' do
|
20
|
+
expect( subject.parse [] ).to eq( {} )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
describe '.execute' do
|
26
|
+
let (:lister) { ListTool::Lister.new }
|
27
|
+
let (:printer) { ListTool::App::Printer }
|
28
|
+
|
29
|
+
it 'gets array of lists' do
|
30
|
+
expect(lister).to receive(:lists)
|
31
|
+
allow(printer).to receive(:print_lists)
|
32
|
+
subject.execute( {}, lister )
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'sends array of lists to printer' do
|
36
|
+
allow(lister).to receive(:lists).and_return(['list1'])
|
37
|
+
expect(printer).to receive(:print_lists).with(['list1'])
|
38
|
+
subject.execute( {}, lister )
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
describe '.help' do
|
44
|
+
it 'returns help message' do
|
45
|
+
expect( subject.help ).to be_a String
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe ListTool::App::UnknownCommand do
|
4
|
+
subject { ListTool::App::UnknownCommand }
|
5
|
+
|
6
|
+
describe '.match?' do
|
7
|
+
it 'returns true always' do
|
8
|
+
expect( subject.match? (65+rand(26)).chr ).to be_truthy
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'stores command to a class variable' do
|
12
|
+
subject.match? "a"
|
13
|
+
expect(subject.instance_variable_get(:@unknown_command)).to eq 'a'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe '.parse' do
|
19
|
+
it 'does nothing and returns {}' do
|
20
|
+
expect( subject.parse [] ).to eq({})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
describe '.execute' do
|
26
|
+
it 'raises UnknownCommandError' do
|
27
|
+
expect{ subject.execute({}, nil) }.to raise_error(ListTool::UnknownCommandError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative '../../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe ListTool::App::UseCommand do
|
4
|
+
subject { ListTool::App::UseCommand }
|
5
|
+
|
6
|
+
describe '.match?' do
|
7
|
+
it 'returns true if "u" or "use" given' do
|
8
|
+
expect( subject.match? "u" ).to be_truthy
|
9
|
+
expect( subject.match? "use" ).to be_truthy
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns false otherwise' do
|
13
|
+
expect( subject.match? "some-arg" ).to be_falsey
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe '.parse' do
|
19
|
+
context 'success' do
|
20
|
+
it 'returns {List: list_num}' do
|
21
|
+
expect( subject.parse(["2"]) ).to eq( {list: 1} )
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'failure' do
|
26
|
+
context 'when list number not given' do
|
27
|
+
it 'raises ArgumentError' do
|
28
|
+
expect{ subject.parse([]) }.to raise_error( ArgumentError )
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when list number is not an integer' do
|
33
|
+
it 'raises ArgumentError' do
|
34
|
+
expect{ subject.parse(['not_an_int']) }.to raise_error( ArgumentError )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when list number is less than 1' do
|
39
|
+
it 'raises ArgumentError' do
|
40
|
+
expect{ subject.parse(['0']) }.to raise_error( ArgumentError )
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when not an array given' do
|
45
|
+
it 'raises ArgumentError' do
|
46
|
+
expect{ subject.parse "not_an_array" }.to raise_error( ArgumentError )
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
describe '.execute' do
|
54
|
+
context 'success' do
|
55
|
+
it 'sets default list' do
|
56
|
+
lister = double()
|
57
|
+
expect( lister ).to receive(:set_default_list).with(1).and_return("not_nil")
|
58
|
+
subject.execute({list: 1}, lister)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'failure' do
|
63
|
+
context 'when list not found' do
|
64
|
+
it 'raises ListNotFoundError' do
|
65
|
+
lister = ListTool::Lister.new
|
66
|
+
expect{ subject.execute({list: 1}, lister) }.to raise_error(ListTool::ListNotFoundError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
describe '.help' do
|
74
|
+
it 'returns help message' do
|
75
|
+
expect( subject.help ).to be_a String
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative '../../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe ListTool::App::VersionCommand do
|
4
|
+
subject { ListTool::App::VersionCommand }
|
5
|
+
|
6
|
+
describe '.match?' do
|
7
|
+
it 'returns true if "v", "-v", "version", or "--version" given' do
|
8
|
+
expect( subject.match? "v" ).to be_truthy
|
9
|
+
expect( subject.match? "-v" ).to be_truthy
|
10
|
+
expect( subject.match? "version" ).to be_truthy
|
11
|
+
expect( subject.match? "--version" ).to be_truthy
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns false otherwise' do
|
15
|
+
expect( subject.match? "some-arg" ).to be_falsey
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
describe '.parse' do
|
21
|
+
it 'always returns {}' do
|
22
|
+
expect( subject.parse nil ).to eq( {} )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
describe '.execute' do
|
28
|
+
it 'calls Printer.print_version' do
|
29
|
+
expect(ListTool::App::Printer).to receive(:print_version)
|
30
|
+
subject.execute( {}, nil )
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe '.help' do
|
36
|
+
it 'returns help message' do
|
37
|
+
expect( subject.help ).to be_a String
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|