clin 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.lint-ci.yml +2 -0
  3. data/.simplecov +5 -0
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG.md +11 -0
  6. data/README.md +5 -4
  7. data/benchmarks/bench.rb +21 -0
  8. data/benchmarks/text_bench.rb +78 -0
  9. data/clin.gemspec +2 -1
  10. data/examples/reusable_options.rb +19 -0
  11. data/examples/simple.rb +8 -3
  12. data/examples/test.rb +5 -5
  13. data/examples/text_builder.rb +40 -0
  14. data/lib/clin/argument.rb +19 -2
  15. data/lib/clin/command_mixin/core.rb +13 -18
  16. data/lib/clin/command_mixin/options.rb +37 -26
  17. data/lib/clin/command_parser.rb +46 -57
  18. data/lib/clin/common/help_options.rb +1 -0
  19. data/lib/clin/errors.rb +50 -4
  20. data/lib/clin/line_reader/basic.rb +38 -0
  21. data/lib/clin/line_reader/readline.rb +53 -0
  22. data/lib/clin/line_reader.rb +16 -0
  23. data/lib/clin/option.rb +24 -11
  24. data/lib/clin/option_parser.rb +159 -0
  25. data/lib/clin/shell.rb +36 -15
  26. data/lib/clin/shell_interaction/choose.rb +19 -11
  27. data/lib/clin/shell_interaction/file_conflict.rb +4 -1
  28. data/lib/clin/shell_interaction/select.rb +44 -0
  29. data/lib/clin/shell_interaction.rb +1 -0
  30. data/lib/clin/text/table.rb +270 -0
  31. data/lib/clin/text.rb +152 -0
  32. data/lib/clin/version.rb +1 -1
  33. data/lib/clin.rb +10 -1
  34. data/spec/clin/command_dispacher_spec.rb +1 -1
  35. data/spec/clin/command_mixin/options_spec.rb +38 -15
  36. data/spec/clin/command_parser_spec.rb +27 -51
  37. data/spec/clin/line_reader/basic_spec.rb +54 -0
  38. data/spec/clin/line_reader/readline_spec.rb +64 -0
  39. data/spec/clin/line_reader_spec.rb +17 -0
  40. data/spec/clin/option_parser_spec.rb +217 -0
  41. data/spec/clin/option_spec.rb +5 -7
  42. data/spec/clin/shell_interaction/choose_spec.rb +30 -0
  43. data/spec/clin/shell_interaction/file_interaction_spec.rb +18 -0
  44. data/spec/clin/shell_interaction/select_spec.rb +96 -0
  45. data/spec/clin/shell_spec.rb +42 -0
  46. data/spec/clin/text/table_cell_spec.rb +72 -0
  47. data/spec/clin/text/table_row_spec.rb +74 -0
  48. data/spec/clin/text/table_separator_row_spec.rb +82 -0
  49. data/spec/clin/text/table_spec.rb +259 -0
  50. data/spec/clin/text_spec.rb +158 -0
  51. data/spec/examples/list_option_spec.rb +6 -2
  52. data/spec/examples/reusable_options_spec.rb +21 -0
  53. data/spec/examples/simple_spec.rb +9 -9
  54. data/spec/spec_helper.rb +3 -2
  55. metadata +54 -3
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Clin::Text::TableRow do
4
+ def table_double(options)
5
+ double(:table, options.reverse_merge(column_length: {}, update_column_length: true,
6
+ separate_blank?: true))
7
+ end
8
+
9
+ describe '#each' do
10
+ let(:table) { table_double(column_length: double(:col_length, size: size)) }
11
+ subject { Clin::Text::TableRow.new(table, %w(a b c)) }
12
+
13
+ before do
14
+ allow(Clin::Text::TableCell).to receive(:new) do |_table, _index, val|
15
+ val
16
+ end
17
+ end
18
+ context 'when same number of column as cells' do
19
+ let(:size) { 3 }
20
+ it { expect { |b| subject.each(&b) }.to yield_control.exactly(size).times }
21
+ it { expect { |b| subject.each(&b) }.to yield_successive_args('a', 'b', 'c') }
22
+ end
23
+
24
+ context 'when there are more column that cells in the rows' do
25
+ let(:size) { 5 }
26
+ it { expect { |b| subject.each(&b) }.to yield_control.exactly(size).times }
27
+ it { expect { |b| subject.each(&b) }.to yield_successive_args('a', 'b', 'c', '', '') }
28
+ end
29
+ end
30
+
31
+ describe '#border' do
32
+ let(:table) { table_double(vertical_border: '|', border?: border) }
33
+ subject { Clin::Text::TableRow.new(table, []) }
34
+ context 'when border is enabled' do
35
+ let(:border) { true }
36
+
37
+ it { expect(subject.border('value')).to eq('|value|') }
38
+ it { expect(subject.border('value', ' ')).to eq('| value |') }
39
+ end
40
+
41
+ context 'when border is not enabled' do
42
+ let(:border) { false }
43
+
44
+ it { expect(subject.border('value')).to eq('value') }
45
+ it { expect(subject.border('value', ' ')).to eq('value') }
46
+ end
47
+ end
48
+
49
+ describe '#to_s' do
50
+ let(:table) { Clin::Text::Table.new(col_delim: delimiter, border: border) }
51
+ subject { Clin::Text::TableRow.new(table, %w(val1 val2 val3)) }
52
+
53
+ context 'when no border' do
54
+ let(:border) { false }
55
+ let(:delimiter) { ' [] ' }
56
+
57
+ it { expect(subject.to_s).to eq('val1 [] val2 [] val3') }
58
+ end
59
+
60
+ context 'when border' do
61
+ let(:border) { true }
62
+ let(:delimiter) { ' [] ' }
63
+
64
+ it { expect(subject.to_s).to eq('| val1 [] val2 [] val3 |') }
65
+ end
66
+
67
+ context 'when no border and specific delimiter' do
68
+ let(:border) { false }
69
+ let(:delimiter) { [' # ', ' $ '] }
70
+
71
+ it { expect(subject.to_s).to eq('val1 # val2 $ val3') }
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Clin::Text::TableSeparatorRow do
4
+ def table_double(options)
5
+ double(:table, options.reverse_merge(column_length: {}, update_column_length: true,
6
+ separate_blank?: true))
7
+ end
8
+
9
+ describe '#delimiter_at' do
10
+ let(:table) do
11
+ Clin::Text::Table.new do |t|
12
+ t.row %w(a b c d) # 4 columns(i.e. 3 Delimiters)
13
+ t.column_delimiter delimiter
14
+ end
15
+ end
16
+
17
+ subject { Clin::Text::TableSeparatorRow.new(table, '-', col_delimiter: include_column) }
18
+ context 'when not include column delimiter' do
19
+ let(:include_column) { false }
20
+ let(:delimiter) { ' | ' }
21
+
22
+ it { expect(subject.delimiter_at(0)).to eq('---') }
23
+ it { expect(subject.delimiter_at(1)).to eq('---') }
24
+ it { expect(subject.delimiter_at(2)).to eq('---') }
25
+ it { expect(subject.delimiter_at(3)).to eq('') }
26
+ it { expect(subject.delimiter_at(10)).to eq('') }
27
+
28
+ end
29
+ context 'when include column delimiter' do
30
+ let(:include_column) { true }
31
+
32
+ context 'when column delimiter is a global value' do
33
+ let(:delimiter) { ' # ' }
34
+ it { expect(subject.delimiter_at(0)).to eq(delimiter) }
35
+ it { expect(subject.delimiter_at(1)).to eq(delimiter) }
36
+ it { expect(subject.delimiter_at(2)).to eq(delimiter) }
37
+ it { expect(subject.delimiter_at(3)).to eq('') }
38
+ it { expect(subject.delimiter_at(10)).to eq('') }
39
+ end
40
+
41
+ context 'when column delimiter is a specific' do
42
+ let(:delimiter) { [' # ', ' | ', ' [] '] }
43
+ it { expect(subject.delimiter_at(0)).to eq(delimiter[0]) }
44
+ it { expect(subject.delimiter_at(1)).to eq(delimiter[1]) }
45
+ it { expect(subject.delimiter_at(2)).to eq(delimiter[2]) }
46
+ it { expect(subject.delimiter_at(3)).to eq('') }
47
+ it { expect(subject.delimiter_at(10)).to eq('') }
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#to_s' do
53
+ let(:delimiter) { ' | ' }
54
+ let(:table) do
55
+ Clin::Text::Table.new(col_delim: delimiter, border: border) do |t|
56
+ t.column_length = [4, 4, 4]
57
+ end
58
+ end
59
+ subject { Clin::Text::TableSeparatorRow.new(table, col_delimiter: include_column) }
60
+
61
+ context 'when not including column delimiter' do
62
+ let(:include_column) { false }
63
+ let(:border) { false }
64
+
65
+ it { expect(subject.to_s).to eq('------------------') }
66
+ end
67
+
68
+ context 'when including column delimiter' do
69
+ let(:include_column) { true }
70
+ let(:border) { false }
71
+
72
+ it { expect(subject.to_s).to eq('---- | ---- | ----') }
73
+ end
74
+
75
+ context 'when border' do
76
+ let(:include_column) { true }
77
+ let(:border) { true }
78
+
79
+ it { expect(subject.to_s).to eq('|----- | ---- | -----|') }
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,259 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Clin::Text::Table do
4
+ describe '#row' do
5
+ before do
6
+ subject.row(%w(a b c))
7
+ subject.row(%w(a2 b2 c2))
8
+ end
9
+
10
+ it { expect(subject.rows.size).to be 2 }
11
+ it { expect(subject.rows.first).to be_a Clin::Text::TableRow }
12
+ it { expect(subject.rows.first.cells.size).to be 3 }
13
+ end
14
+
15
+ describe '#header' do
16
+ before do
17
+ subject.header(%w(a b c))
18
+ end
19
+
20
+ it { expect(subject.rows).to be_empty }
21
+ it { expect(subject.header).to be_a Clin::Text::TableRow }
22
+ it { expect(subject.header.cells.size).to be 3 }
23
+ end
24
+
25
+ describe '#separator' do
26
+ before do
27
+ subject.row(%w(a b c))
28
+ subject.separator
29
+ subject.separator('=')
30
+ end
31
+
32
+ it { expect(subject.rows.size).to be 3 }
33
+ it { expect(subject.rows[1]).to be_a Clin::Text::TableSeparatorRow }
34
+ it { expect(subject.rows[2]).to be_a Clin::Text::TableSeparatorRow }
35
+ it { expect(subject.rows[2].char).to eq '=' }
36
+ end
37
+
38
+ describe '#align' do
39
+ it 'set global alignment' do
40
+ subject.align(:center)
41
+ expect(subject.alignment).to eq :center
42
+ end
43
+
44
+ it 'set column alignment' do
45
+ subject.align(*[:center, :left, :right])
46
+ expect(subject.alignment).to eq [:center, :left, :right]
47
+ end
48
+ end
49
+
50
+ describe '#column_delimiter' do
51
+ it 'set global delimiter' do
52
+ subject.column_delimiter(' # ')
53
+ expect(subject.column_delimiters).to eq(' # ')
54
+ end
55
+
56
+ it 'set column delimiter' do
57
+ subject.column_delimiter(*[' # ', ' O ', ' [] '])
58
+ expect(subject.column_delimiters).to eq [' # ', ' O ', ' [] ']
59
+ end
60
+ end
61
+
62
+ describe '#update_column_length' do
63
+ it 'set the value' do
64
+ subject.update_column_length(1, 12)
65
+ expect(subject.column_length).to eq({1 => 12})
66
+ end
67
+
68
+ it 'set overwrite smaller value' do
69
+ subject.update_column_length(1, 12)
70
+ subject.update_column_length(1, 24)
71
+ expect(subject.column_length).to eq({1 => 24})
72
+ end
73
+
74
+ it 'set keep larger value' do
75
+ subject.update_column_length(1, 12)
76
+ subject.update_column_length(1, 6)
77
+ expect(subject.column_length).to eq({1 => 12})
78
+ end
79
+ end
80
+
81
+ describe '#sym_or_array' do
82
+ it 'return symbol when symbol given' do
83
+ expect(subject.send(:sym_or_array, :sym)).to eq(:sym)
84
+ end
85
+
86
+ it 'return array when multiple arguments given' do
87
+ expect(subject.send(:sym_or_array, :sym1, :sym2, :sym3)).to eq([:sym1, :sym2, :sym3])
88
+ end
89
+
90
+ it 'return array when array given' do
91
+ expect(subject.send(:sym_or_array, [:sym1, :sym2, :sym3])).to eq([:sym1, :sym2, :sym3])
92
+ end
93
+
94
+ it 'return array when array and arguments given' do
95
+ expect(subject.send(:sym_or_array, [:sym1, :sym2], :sym3)).to eq([:sym1, :sym2, :sym3])
96
+ end
97
+ end
98
+
99
+ describe '#add_border' do
100
+ let(:text) { double(:text, line: true, prefix: true) }
101
+ let (:line) { '====----====' }
102
+ before do
103
+ allow(Clin::Text::TableSeparatorRow).to receive(:new).and_return(line)
104
+ subject.send(:add_border, text)
105
+ end
106
+ it { expect(text).to have_received(:line).with(line) }
107
+ it { expect(text).to have_received(:prefix).with(line) }
108
+ end
109
+
110
+ describe '#to_text' do
111
+ let(:header) { %w(Header1 Header2 Header3) }
112
+ let(:row1) { %w(First1 First2 First3) }
113
+ let(:row2) { %w(Second1 Second2 SecondThird) }
114
+
115
+ before do
116
+ subject.border = false
117
+ subject.row row1
118
+ subject.row row2
119
+ end
120
+
121
+ it 'make a text with only the given row' do
122
+ expect(subject.to_text._lines.size).to be 2
123
+ end
124
+
125
+ it 'add 2 rows for header' do
126
+ subject.header header
127
+ expect(subject.to_text._lines.size).to be 4
128
+ end
129
+
130
+ it 'add 2 rows for border' do
131
+ subject.border = true
132
+ expect(subject.to_text._lines.size).to be 4
133
+ end
134
+ end
135
+
136
+
137
+ describe '#delimiter_at' do
138
+ before do
139
+ subject.row %w(a b c d) # 4 columns(i.e. 3 Delimiters)
140
+ subject.column_delimiter delimiter
141
+ end
142
+ context 'when delimiter is a global value' do
143
+ let(:delimiter) { ' # ' }
144
+ it { expect(subject.delimiter_at(0)).to eq(delimiter) }
145
+ it { expect(subject.delimiter_at(3)).to eq('') }
146
+ it { expect(subject.delimiter_at(10)).to eq('') }
147
+ end
148
+
149
+ context 'when delimiter is a global value' do
150
+ let(:delimiter) { ' # ' }
151
+ it { expect(subject.delimiter_at(0)).to eq(delimiter) }
152
+ it { expect(subject.delimiter_at(1)).to eq(delimiter) }
153
+ it { expect(subject.delimiter_at(2)).to eq(delimiter) }
154
+ it { expect(subject.delimiter_at(3)).to eq('') }
155
+ it { expect(subject.delimiter_at(10)).to eq('') }
156
+ end
157
+
158
+ context 'when delimiter is a specific' do
159
+ let(:delimiter) { [' # ', ' | ', ' [] '] }
160
+ it { expect(subject.delimiter_at(0)).to eq(delimiter[0]) }
161
+ it { expect(subject.delimiter_at(1)).to eq(delimiter[1]) }
162
+ it { expect(subject.delimiter_at(2)).to eq(delimiter[2]) }
163
+ it { expect(subject.delimiter_at(3)).to eq('') }
164
+ it { expect(subject.delimiter_at(10)).to eq('') }
165
+ end
166
+ end
167
+
168
+ describe '#to_s' do
169
+ subject do
170
+ Clin::Text::Table.new(border: false) do |t|
171
+ t.align :right, :center, :left
172
+ # t.column_delimiter ' - ', ' # '
173
+ t.header %w(First Last Email)
174
+
175
+ t.row %w(Timothee Guerin timothee.guerin@outlook.com)
176
+ t.row %w(Some Guy Some.Guy@outlook.com)
177
+
178
+ t.separator
179
+
180
+ t.row %w(VeryLongFirstName Guy Some.Other@outlook.com)
181
+ end
182
+ end
183
+
184
+ context 'when include border' do
185
+ it 'build the table' do
186
+ subject.border = true
187
+ expect(subject.to_s).to eq <<table
188
+ |----------------------------------------------------------|
189
+ | First | Last | Email |
190
+ |------------------ | ------ | ----------------------------|
191
+ | Timothee | Guerin | timothee.guerin@outlook.com |
192
+ | Some | Guy | Some.Guy@outlook.com |
193
+ |------------------ | ------ | ----------------------------|
194
+ | VeryLongFirstName | Guy | Some.Other@outlook.com |
195
+ |----------------------------------------------------------|
196
+ table
197
+ end
198
+ end
199
+
200
+ context 'when no border' do
201
+ before do
202
+ subject.border = false
203
+ end
204
+
205
+ it 'build the table' do
206
+ out = <<table
207
+ First | Last | Email
208
+ ----------------- | ------ | ---------------------------
209
+ Timothee | Guerin | timothee.guerin@outlook.com
210
+ Some | Guy | Some.Guy@outlook.com
211
+ ----------------- | ------ | ---------------------------
212
+ VeryLongFirstName | Guy | Some.Other@outlook.com
213
+ table
214
+ # Need to rstrip because trailing whitespace are being removed automatically by editor
215
+ expect(subject.to_s.split("\n").map(&:rstrip)).to eq out.split("\n").map(&:rstrip)
216
+ end
217
+ end
218
+
219
+ context 'when custom column delimiter' do
220
+ before do
221
+ subject.border = true
222
+ subject.column_delimiter ' - ', ' # '
223
+ end
224
+
225
+ it 'build the table' do
226
+ expect(subject.to_s).to eq <<table
227
+ |----------------------------------------------------------|
228
+ | First - Last # Email |
229
+ |------------------ - ------ # ----------------------------|
230
+ | Timothee - Guerin # timothee.guerin@outlook.com |
231
+ | Some - Guy # Some.Guy@outlook.com |
232
+ |------------------ - ------ # ----------------------------|
233
+ | VeryLongFirstName - Guy # Some.Other@outlook.com |
234
+ |----------------------------------------------------------|
235
+ table
236
+ end
237
+ end
238
+
239
+ context 'when align all to the right' do
240
+ before do
241
+ subject.border = true
242
+ subject.align :right
243
+ end
244
+
245
+ it 'build the table' do
246
+ expect(subject.to_s).to eq <<table
247
+ |----------------------------------------------------------|
248
+ | First | Last | Email |
249
+ |------------------ | ------ | ----------------------------|
250
+ | Timothee | Guerin | timothee.guerin@outlook.com |
251
+ | Some | Guy | Some.Guy@outlook.com |
252
+ |------------------ | ------ | ----------------------------|
253
+ | VeryLongFirstName | Guy | Some.Other@outlook.com |
254
+ |----------------------------------------------------------|
255
+ table
256
+ end
257
+ end
258
+ end
259
+ end
@@ -0,0 +1,158 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Clin::Text do
4
+ describe '#process_line' do
5
+ let (:line) { Faker::Lorem::sentence }
6
+ context 'when global indent is not set' do
7
+ subject { Clin::Text.new }
8
+
9
+ it 'return the same line with no indent' do
10
+ expect(subject.process_line(line)).to eq(line)
11
+ end
12
+
13
+ it 'add a new line and indent' do
14
+ expect(subject.process_line(line, indent: 2)).to eq(" #{line}")
15
+ end
16
+ end
17
+
18
+ context 'when global indent is set' do
19
+ subject { Clin::Text.new(indent: '**') }
20
+
21
+ it 'add line with global indent' do
22
+ expect(subject.process_line(line)).to eq("**#{line}")
23
+ end
24
+
25
+ it 'add line with global indent and method indent' do
26
+ expect(subject.process_line(line, indent: 2)).to eq("** #{line}")
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#line' do
32
+ let (:line1) { Faker::Lorem::sentence }
33
+ let (:line2) { Faker::Lorem::sentence }
34
+
35
+ before do
36
+ subject.line(line1)
37
+ subject.line(line2)
38
+ end
39
+
40
+ it { expect(subject.lines.size).to be 2 }
41
+ it { expect(subject.lines[0]).to eq line1 }
42
+ it { expect(subject.lines[1]).to eq line2 }
43
+ end
44
+
45
+ describe '#prefix' do
46
+ let (:line1) { Faker::Lorem::sentence }
47
+ let (:line2) { Faker::Lorem::sentence }
48
+
49
+ before do
50
+ subject.line(line1)
51
+ subject.prefix(line2)
52
+ end
53
+
54
+ it { expect(subject.lines.size).to be 2 }
55
+ it { expect(subject.lines[0]).to eq line2 }
56
+ it { expect(subject.lines[1]).to eq line1 }
57
+ end
58
+
59
+ describe '#blank' do
60
+ it 'add 1 blank line' do
61
+ subject.blank
62
+ expect(subject.lines).to eq([''])
63
+ end
64
+
65
+ it 'add multiple blank line' do
66
+ subject.blank(3)
67
+ expect(subject.lines).to eq(['', '', ''])
68
+ end
69
+ end
70
+
71
+ describe '#lines' do
72
+ let (:lines) { [Faker::Lorem::sentence, Faker::Lorem::sentence] }
73
+ it 'add lines' do
74
+ subject.lines(lines)
75
+ expect(subject.lines).to eq(lines)
76
+ end
77
+
78
+ it 'add lines and indent' do
79
+ subject.lines(lines, indent: '**')
80
+ expect(subject.lines).to eq(lines.map { |x| "**#{x}" })
81
+ end
82
+ end
83
+
84
+ describe '#text' do
85
+ let (:lines) { [Faker::Lorem::sentence, Faker::Lorem::sentence] }
86
+
87
+ let (:text) do
88
+ text_lines = lines
89
+ Clin::Text.new do |t|
90
+ t.lines(text_lines)
91
+ end
92
+ end
93
+
94
+ it 'add text' do
95
+ subject.text(text)
96
+ expect(subject.lines).to eq(lines)
97
+ end
98
+
99
+ it 'add text and indent' do
100
+ subject.text(text, indent: '**')
101
+ expect(subject.lines).to eq(lines.map { |x| "**#{x}" })
102
+ end
103
+ end
104
+
105
+ describe '#indent' do
106
+ let (:line) { Faker::Lorem::sentence }
107
+
108
+ it 'add an indented line inside block' do
109
+ subject.indent 2 do
110
+ subject.line(line)
111
+ end
112
+ expect(subject.lines).to eq([" #{line}"])
113
+ end
114
+
115
+ it 'add line with nested indent' do
116
+ subject.indent 2 do
117
+ subject.line(line)
118
+ subject.indent '***' do
119
+ subject.line(line)
120
+ end
121
+ subject.line(line)
122
+ end
123
+ expect(subject.lines).to eq([" #{line}", " ***#{line}", " #{line}"])
124
+ end
125
+ end
126
+
127
+
128
+ describe '#to_s' do
129
+ let (:line1) { Faker::Lorem::sentence }
130
+ let (:line2) { Faker::Lorem::sentence }
131
+ let (:line3) { Faker::Lorem::sentence }
132
+
133
+ it 'join line with \n' do
134
+ subject.line line1
135
+ subject.line line2
136
+ subject.prefix line3
137
+ expect(subject.to_s).to eq("#{line3}\n#{line1}\n#{line2}\n")
138
+ end
139
+ end
140
+
141
+ describe '#on' do
142
+ it 'register a new callback' do
143
+ b = proc { |line|}
144
+ subject.on(&b)
145
+ expect(subject.listeners).to eq([b])
146
+ end
147
+ end
148
+
149
+ describe '#broadcast' do
150
+ it 'register a new callback' do
151
+ b = proc { |line|}
152
+ subject.on(&b)
153
+ subject.on(&b)
154
+ expect(b).to receive(:call).with('some line').twice
155
+ subject.broadcast('some line')
156
+ end
157
+ end
158
+ end
@@ -6,8 +6,12 @@ RSpec.describe 'list_option.rb' do
6
6
  it { expect(ListCommand.parse('').params).to eq(echo: [], line: 0) }
7
7
  it { expect(ListCommand.parse('--echo msg').params).to eq(echo: ['msg'], line: 0) }
8
8
  it { expect(ListCommand.parse('--line').params).to eq(echo: [], line: 1) }
9
- it { expect(ListCommand.parse('--line --line').params).to eq(echo: [], line: 2) }
10
- it { expect(ListCommand.parse('-lll').params).to eq(echo: [], line: 3) }
9
+ it {
10
+ expect(ListCommand.parse('--line --line').params).to eq(echo: [], line: 2)
11
+ }
12
+ it {
13
+ expect(ListCommand.parse('-lll').params).to eq(echo: [], line: 3)
14
+ }
11
15
  it do
12
16
  expect(ListCommand.parse('--echo msg1 --echo msg2').params)
13
17
  .to eq(echo: %w(msg1 msg2), line: 0)
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'examples/reusable_options'
3
+
4
+ RSpec.describe 'reusable_options.rb' do
5
+ def parse(str)
6
+ ReusableOptionCommand.parse(str).params
7
+ end
8
+
9
+ suppress_puts
10
+ it { expect(parse('--verbose')).to eq(verbose: true) }
11
+ it { expect(parse('--echo "Hello world!"')).to eq(echo: 'Hello world!') }
12
+ it { expect(parse('--source "~/source"')).to eq(source: '~/source') }
13
+ it { expect(parse('--echo "Hello world!" --source "~/source"'))
14
+ .to eq(echo: 'Hello world!', source: '~/source') }
15
+ it { expect(parse('--source "~/source" -v --echo "Hello world!"'))
16
+ .to eq(echo: 'Hello world!', verbose: true, source: '~/source') }
17
+ it { expect(parse('-s"~/source" -v --echo "Hello world!"'))
18
+ .to eq(echo: 'Hello world!', verbose: true, source: '~/source') }
19
+
20
+
21
+ end
@@ -4,28 +4,28 @@ require 'examples/simple'
4
4
  RSpec.describe 'simple_spec.rb' do
5
5
  suppress_puts
6
6
  it { expect(SimpleCommand.parse('display Some').params).
7
- to eq(display: 'display', message: 'Some') }
7
+ to eq(display: 'display', message: 'Some') }
8
8
  it { expect(SimpleCommand.parse('display "Message with spaces"').params).
9
- to eq(display: 'display', message: 'Message with spaces') }
9
+ to eq(display: 'display', message: 'Message with spaces') }
10
10
 
11
11
  it { expect(SimpleCommand.parse('display Some -e More').params).
12
- to eq(display: 'display', message: 'Some', echo: 'More') }
12
+ to eq(display: 'display', message: 'Some', echo: 'More') }
13
13
 
14
14
  it { expect(SimpleCommand.parse('display Some -eMore').params).
15
- to eq(display: 'display', message: 'Some', echo: 'More') }
15
+ to eq(display: 'display', message: 'Some', echo: 'More') }
16
16
 
17
17
  it { expect(SimpleCommand.parse('display Some -e "Even More"').params).
18
- to eq(display: 'display', message: 'Some', echo: 'Even More') }
18
+ to eq(display: 'display', message: 'Some', echo: 'Even More') }
19
19
 
20
20
  it { expect(SimpleCommand.parse('display Some --echo More').params).
21
- to eq(display: 'display', message: 'Some', echo: 'More') }
21
+ to eq(display: 'display', message: 'Some', echo: 'More') }
22
22
 
23
23
  it { expect(SimpleCommand.parse('display Some --echo=More').params).
24
- to eq(display: 'display', message: 'Some', echo: 'More') }
24
+ to eq(display: 'display', message: 'Some', echo: 'More') }
25
25
 
26
26
  it { expect(SimpleCommand.parse('display Some --echo "Even More"').params).
27
- to eq(display: 'display', message: 'Some', echo: 'Even More') }
27
+ to eq(display: 'display', message: 'Some', echo: 'Even More') }
28
28
 
29
29
  it { expect { SimpleCommand.parse('').params }.to raise_error(Clin::HelpError) }
30
30
  it { expect { SimpleCommand.parse('-h').params }.to raise_error(Clin::HelpError) }
31
- end
31
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
- require 'coveralls'
2
- Coveralls.wear!
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
+
3
4
  $LOAD_PATH.push File.expand_path('../..', __FILE__)
4
5
  $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
5
6
  require 'rspec'