tty 0.0.11 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -7
- data/CHANGELOG.md +6 -0
- data/Gemfile +18 -1
- data/README.md +55 -28
- data/Rakefile +5 -9
- data/images/tty.png +0 -0
- data/lib/tty.rb +7 -1
- data/lib/tty/coercer/boolean.rb +6 -9
- data/lib/tty/coercer/float.rb +14 -17
- data/lib/tty/coercer/integer.rb +14 -17
- data/lib/tty/coercer/range.rb +6 -7
- data/lib/tty/logger.rb +23 -9
- data/lib/tty/plugins.rb +3 -6
- data/lib/tty/plugins/plugin.rb +4 -7
- data/lib/tty/shell.rb +20 -12
- data/lib/tty/shell/question.rb +41 -48
- data/lib/tty/shell/question/modifier.rb +5 -8
- data/lib/tty/shell/question/validation.rb +8 -7
- data/lib/tty/shell/reader.rb +28 -19
- data/lib/tty/shell/response.rb +26 -22
- data/lib/tty/shell/statement.rb +13 -9
- data/lib/tty/shell/suggestion.rb +17 -13
- data/lib/tty/support/coercion.rb +5 -6
- data/lib/tty/support/conversion.rb +7 -6
- data/lib/tty/support/delegatable.rb +5 -5
- data/lib/tty/support/unicode.rb +3 -4
- data/lib/tty/support/utils.rb +1 -2
- data/lib/tty/system.rb +13 -6
- data/lib/tty/system/editor.rb +21 -18
- data/lib/tty/system/which.rb +3 -5
- data/lib/tty/table.rb +18 -22
- data/lib/tty/table/border.rb +2 -4
- data/lib/tty/table/border/ascii.rb +3 -2
- data/lib/tty/table/border/null.rb +1 -3
- data/lib/tty/table/border/row_line.rb +1 -4
- data/lib/tty/table/border/unicode.rb +3 -2
- data/lib/tty/table/border_dsl.rb +21 -17
- data/lib/tty/table/border_options.rb +6 -5
- data/lib/tty/table/column_set.rb +11 -7
- data/lib/tty/table/columns.rb +19 -16
- data/lib/tty/table/error.rb +1 -3
- data/lib/tty/table/field.rb +30 -12
- data/lib/tty/table/header.rb +18 -9
- data/lib/tty/table/indentation.rb +1 -3
- data/lib/tty/table/operation/alignment.rb +8 -9
- data/lib/tty/table/operation/alignment_set.rb +6 -5
- data/lib/tty/table/operation/escape.rb +3 -3
- data/lib/tty/table/operation/filter.rb +3 -4
- data/lib/tty/table/operation/truncation.rb +3 -3
- data/lib/tty/table/operation/wrapped.rb +3 -4
- data/lib/tty/table/operations.rb +19 -22
- data/lib/tty/table/orientation.rb +5 -5
- data/lib/tty/table/orientation/horizontal.rb +9 -6
- data/lib/tty/table/orientation/vertical.rb +10 -7
- data/lib/tty/table/padder.rb +46 -8
- data/lib/tty/table/renderer.rb +21 -14
- data/lib/tty/table/renderer/ascii.rb +6 -5
- data/lib/tty/table/renderer/basic.rb +18 -19
- data/lib/tty/table/renderer/unicode.rb +11 -5
- data/lib/tty/table/row.rb +36 -20
- data/lib/tty/table/transformation.rb +6 -5
- data/lib/tty/table/validatable.rb +32 -17
- data/lib/tty/terminal.rb +26 -42
- data/lib/tty/terminal/color.rb +10 -12
- data/lib/tty/terminal/echo.rb +4 -7
- data/lib/tty/terminal/home.rb +3 -10
- data/lib/tty/terminal/pager.rb +11 -10
- data/lib/tty/terminal/pager/basic.rb +3 -6
- data/lib/tty/terminal/pager/system.rb +2 -5
- data/lib/tty/text.rb +7 -10
- data/lib/tty/text/distance.rb +2 -4
- data/lib/tty/text/truncation.rb +1 -3
- data/lib/tty/text/wrapping.rb +1 -3
- data/lib/tty/vector.rb +3 -5
- data/lib/tty/version.rb +2 -2
- data/spec/spec_helper.rb +4 -11
- data/spec/tty/coercer/boolean/coerce_spec.rb +19 -16
- data/spec/tty/coercer/float/coerce_spec.rb +6 -4
- data/spec/tty/coercer/integer/coerce_spec.rb +5 -4
- data/spec/tty/coercer/range/coerce_spec.rb +12 -11
- data/spec/tty/logger/log_spec.rb +23 -0
- data/spec/tty/logger/new_spec.rb +14 -14
- data/spec/tty/logger/valid_level_spec.rb +6 -6
- data/spec/tty/plugins/find_spec.rb +4 -4
- data/spec/tty/plugins/load_spec.rb +4 -5
- data/spec/tty/plugins/plugin/load_spec.rb +10 -8
- data/spec/tty/plugins/plugin/new_spec.rb +7 -7
- data/spec/tty/shell/ask_spec.rb +6 -7
- data/spec/tty/shell/error_spec.rb +1 -2
- data/spec/tty/shell/print_table_spec.rb +1 -2
- data/spec/tty/shell/question/argument_spec.rb +1 -1
- data/spec/tty/shell/question/character_spec.rb +11 -3
- data/spec/tty/shell/question/default_spec.rb +3 -3
- data/spec/tty/shell/question/in_spec.rb +1 -1
- data/spec/tty/shell/question/initialize_spec.rb +8 -11
- data/spec/tty/shell/question/modifier/apply_to_spec.rb +8 -4
- data/spec/tty/shell/question/modifier/letter_case_spec.rb +4 -4
- data/spec/tty/shell/question/modifier/whitespace_spec.rb +5 -5
- data/spec/tty/shell/question/modify_spec.rb +1 -1
- data/spec/tty/shell/question/valid_spec.rb +4 -4
- data/spec/tty/shell/question/validate_spec.rb +4 -4
- data/spec/tty/shell/question/validation/coerce_spec.rb +2 -3
- data/spec/tty/shell/question/validation/valid_value_spec.rb +3 -3
- data/spec/tty/shell/reader/getc_spec.rb +16 -14
- data/spec/tty/shell/response/read_bool_spec.rb +1 -1
- data/spec/tty/shell/response/read_char_spec.rb +1 -2
- data/spec/tty/shell/response/read_date_spec.rb +1 -1
- data/spec/tty/shell/response/read_email_spec.rb +1 -1
- data/spec/tty/shell/response/read_multiple_spec.rb +3 -4
- data/spec/tty/shell/response/read_number_spec.rb +1 -2
- data/spec/tty/shell/response/read_range_spec.rb +2 -2
- data/spec/tty/shell/response/read_spec.rb +7 -7
- data/spec/tty/shell/response/read_string_spec.rb +2 -2
- data/spec/tty/shell/say_spec.rb +1 -1
- data/spec/tty/shell/statement/initialize_spec.rb +3 -3
- data/spec/tty/shell/suggest_spec.rb +1 -1
- data/spec/tty/shell/warn_spec.rb +1 -2
- data/spec/tty/support/coercion_spec.rb +10 -10
- data/spec/tty/support/conversion_spec.rb +9 -9
- data/spec/tty/support/delegatable_spec.rb +7 -5
- data/spec/tty/support/equatable_spec.rb +32 -34
- data/spec/tty/support/fixtures/classes.rb +4 -2
- data/spec/tty/system/editor/available_spec.rb +12 -12
- data/spec/tty/system/editor/build_spec.rb +8 -16
- data/spec/tty/system/editor/command_spec.rb +3 -2
- data/spec/tty/system/editor/executables_spec.rb +3 -3
- data/spec/tty/system/editor/invoke_spec.rb +10 -14
- data/spec/tty/system/editor/open_spec.rb +9 -7
- data/spec/tty/system/platform_spec.rb +32 -13
- data/spec/tty/system/which/which_spec.rb +9 -9
- data/spec/tty/system/which_spec.rb +4 -4
- data/spec/tty/table/access_spec.rb +24 -21
- data/spec/tty/table/add_row_spec.rb +2 -2
- data/spec/tty/table/border/ascii/rendering_spec.rb +13 -13
- data/spec/tty/table/border/new_spec.rb +5 -4
- data/spec/tty/table/border/null/rendering_spec.rb +12 -12
- data/spec/tty/table/border/options/from_spec.rb +2 -3
- data/spec/tty/table/border/options/new_spec.rb +4 -5
- data/spec/tty/table/border/unicode/rendering_spec.rb +10 -10
- data/spec/tty/table/border_options/new_spec.rb +20 -0
- data/spec/tty/table/border_options/update_spec.rb +18 -0
- data/spec/tty/table/column_set/extract_widths_spec.rb +1 -1
- data/spec/tty/table/column_set/total_width_spec.rb +2 -2
- data/spec/tty/table/column_set/widths_from_spec.rb +1 -2
- data/spec/tty/table/columns/enforce_spec.rb +2 -2
- data/spec/tty/table/columns/widths_spec.rb +2 -0
- data/spec/tty/table/data_spec.rb +3 -3
- data/spec/tty/table/each_spec.rb +9 -11
- data/spec/tty/table/each_with_index_spec.rb +8 -9
- data/spec/tty/table/empty_spec.rb +3 -3
- data/spec/tty/table/eql_spec.rb +6 -6
- data/spec/tty/table/field/equality_spec.rb +11 -11
- data/spec/tty/table/field/length_spec.rb +4 -4
- data/spec/tty/table/field/lines_spec.rb +3 -3
- data/spec/tty/table/field/new_spec.rb +7 -7
- data/spec/tty/table/field/width_spec.rb +6 -4
- data/spec/tty/table/filter_spec.rb +3 -3
- data/spec/tty/table/header/call_spec.rb +3 -3
- data/spec/tty/table/header/height_spec.rb +1 -1
- data/spec/tty/table/header/new_spec.rb +5 -5
- data/spec/tty/table/header/set_spec.rb +9 -4
- data/spec/tty/table/header/to_ary_spec.rb +4 -4
- data/spec/tty/table/header_spec.rb +3 -4
- data/spec/tty/table/indentation/insert_indent_spec.rb +1 -1
- data/spec/tty/table/initialize_spec.rb +13 -13
- data/spec/tty/table/operation/alignment/format_spec.rb +5 -5
- data/spec/tty/table/operation/alignment/new_spec.rb +4 -4
- data/spec/tty/table/operation/alignment_set/call_spec.rb +11 -11
- data/spec/tty/table/operation/alignment_set/each_spec.rb +3 -3
- data/spec/tty/table/operation/alignment_set/new_spec.rb +6 -6
- data/spec/tty/table/operation/alignment_set/to_ary_spec.rb +4 -4
- data/spec/tty/table/operation/escape/call_spec.rb +1 -1
- data/spec/tty/table/operation/filter/call_spec.rb +1 -1
- data/spec/tty/table/operation/truncation/call_spec.rb +1 -1
- data/spec/tty/table/operation/truncation/truncate_spec.rb +4 -4
- data/spec/tty/table/operation/wrapped/call_spec.rb +1 -1
- data/spec/tty/table/operation/wrapped/wrap_spec.rb +3 -3
- data/spec/tty/table/operations/new_spec.rb +1 -1
- data/spec/tty/table/options_spec.rb +8 -8
- data/spec/tty/table/orientation_spec.rb +15 -13
- data/spec/tty/table/padder/parse_spec.rb +1 -1
- data/spec/tty/table/padder/to_s_spec.rb +14 -0
- data/spec/tty/table/padding_spec.rb +1 -1
- data/spec/tty/table/properties_spec.rb +9 -8
- data/spec/tty/table/render_spec.rb +8 -5
- data/spec/tty/table/render_with_spec.rb +5 -4
- data/spec/tty/table/renderer/ascii/indentation_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/render_spec.rb +7 -7
- data/spec/tty/table/renderer/ascii/resizing_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/separator_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/alignment_spec.rb +5 -5
- data/spec/tty/table/renderer/basic/coloring_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +6 -6
- data/spec/tty/table/renderer/basic/filter_spec.rb +4 -4
- data/spec/tty/table/renderer/basic/indentation_spec.rb +5 -3
- data/spec/tty/table/renderer/basic/multiline_content_spec.rb +10 -10
- data/spec/tty/table/renderer/basic/new_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/options_spec.rb +9 -9
- data/spec/tty/table/renderer/basic/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/render_spec.rb +8 -8
- data/spec/tty/table/renderer/basic/resizing_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/separator_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/truncation_spec.rb +4 -4
- data/spec/tty/table/renderer/basic/wrapping_spec.rb +4 -4
- data/spec/tty/table/renderer/border_spec.rb +21 -21
- data/spec/tty/table/renderer/render_spec.rb +7 -7
- data/spec/tty/table/renderer/select_spec.rb +4 -4
- data/spec/tty/table/renderer/style_spec.rb +19 -19
- data/spec/tty/table/renderer/unicode/indentation_spec.rb +1 -1
- data/spec/tty/table/renderer/unicode/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/unicode/render_spec.rb +6 -6
- data/spec/tty/table/renderer/unicode/separator_spec.rb +2 -2
- data/spec/tty/table/renderer_spec.rb +1 -1
- data/spec/tty/table/rotate_spec.rb +27 -27
- data/spec/tty/table/row/access_spec.rb +3 -3
- data/spec/tty/table/row/call_spec.rb +4 -4
- data/spec/tty/table/row/data_spec.rb +5 -5
- data/spec/tty/table/row/each_spec.rb +1 -1
- data/spec/tty/table/row/equality_spec.rb +16 -16
- data/spec/tty/table/row/height_spec.rb +1 -1
- data/spec/tty/table/row/new_spec.rb +11 -11
- data/spec/tty/table/row/to_ary_spec.rb +3 -3
- data/spec/tty/table/to_s_spec.rb +8 -8
- data/spec/tty/table/validatable/validate_options_spec.rb +5 -5
- data/spec/tty/table/validatable_spec.rb +14 -1
- data/spec/tty/terminal/color/code_spec.rb +3 -3
- data/spec/tty/terminal/color/remove_spec.rb +8 -9
- data/spec/tty/terminal/color/set_spec.rb +5 -6
- data/spec/tty/terminal/color_spec.rb +3 -5
- data/spec/tty/terminal/echo_spec.rb +3 -4
- data/spec/tty/terminal/home_spec.rb +12 -14
- data/spec/tty/terminal/page_spec.rb +5 -4
- data/spec/tty/terminal/pager/available_spec.rb +11 -11
- data/spec/tty/terminal/pager/basic/page_spec.rb +8 -8
- data/spec/tty/terminal/pager/command_spec.rb +2 -2
- data/spec/tty/terminal/pager/executables_spec.rb +3 -3
- data/spec/tty/terminal/pager/page_spec.rb +8 -10
- data/spec/tty/terminal/pager/system/page_spec.rb +8 -8
- data/spec/tty/terminal/size_spec.rb +39 -36
- data/spec/tty/text/distance/distance_spec.rb +13 -13
- data/spec/tty/text/distance/initialize_spec.rb +4 -4
- data/spec/tty/text/distance_spec.rb +2 -2
- data/spec/tty/text/truncate_spec.rb +2 -3
- data/spec/tty/text/truncation/initialize_spec.rb +9 -9
- data/spec/tty/text/truncation/truncate_spec.rb +14 -14
- data/spec/tty/text/wrap_spec.rb +2 -3
- data/spec/tty/text/wrapping/initialize_spec.rb +7 -7
- data/spec/tty/text/wrapping/wrap_spec.rb +11 -11
- data/spec/tty/tty_spec.rb +22 -0
- data/spec/tty/vector/new_spec.rb +7 -7
- data/tasks/console.rake +10 -0
- data/tasks/coverage.rake +11 -0
- data/tasks/metrics/cane.rake +2 -0
- data/tasks/metrics/flog.rake +2 -0
- data/tasks/metrics/heckle.rake +15 -0
- data/tasks/metrics/reek.rake +2 -0
- data/tasks/spec.rake +29 -0
- data/tty.gemspec +5 -12
- metadata +34 -91
- data/.rvmrc +0 -34
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -13,7 +13,7 @@ describe TTY::Table::Renderer::Unicode, 'with separator' do
|
|
13
13
|
|
14
14
|
it "renders each row" do
|
15
15
|
renderer.border.separator= :each_row
|
16
|
-
renderer.render.
|
16
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
17
17
|
┌──┬──┬──┐
|
18
18
|
│h1│h2│h3│
|
19
19
|
├──┼──┼──┤
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -6,23 +6,23 @@ describe TTY::Table, '#rotate' do
|
|
6
6
|
let(:header) { ['h1', 'h2', 'h3'] }
|
7
7
|
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
8
|
|
9
|
-
subject { described_class.new(header, rows) }
|
9
|
+
subject(:table) { described_class.new(header, rows) }
|
10
10
|
|
11
|
-
before {
|
11
|
+
before { table.orientation = :horizontal }
|
12
12
|
|
13
13
|
context 'with default' do
|
14
14
|
context 'without header' do
|
15
15
|
let(:header) { nil }
|
16
16
|
|
17
17
|
it 'preserves orientation' do
|
18
|
-
expect(
|
19
|
-
expect(
|
18
|
+
expect(table.header).to be_nil
|
19
|
+
expect(table.rotate.to_a).to eql rows
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'with header' do
|
24
24
|
it 'preserves orientation' do
|
25
|
-
expect(
|
25
|
+
expect(table.rotate.to_a).to eql [header] + rows
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -31,8 +31,8 @@ describe TTY::Table, '#rotate' do
|
|
31
31
|
let(:header) { nil }
|
32
32
|
|
33
33
|
it 'rotates the rows' do
|
34
|
-
|
35
|
-
expect(
|
34
|
+
table.orientation = :vertical
|
35
|
+
expect(table.rotate.to_a).to eql [
|
36
36
|
['1', 'a1'],
|
37
37
|
['2', 'a2'],
|
38
38
|
['3', 'a3'],
|
@@ -40,29 +40,29 @@ describe TTY::Table, '#rotate' do
|
|
40
40
|
['2', 'b2'],
|
41
41
|
['3', 'b3'],
|
42
42
|
]
|
43
|
-
expect(
|
43
|
+
expect(table.header).to be_nil
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'rotates the rows back' do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
expect(
|
51
|
-
expect(
|
47
|
+
table.orientation = :vertical
|
48
|
+
table.rotate
|
49
|
+
table.orientation = :horizontal
|
50
|
+
expect(table.rotate.to_a).to eql rows
|
51
|
+
expect(table.header).to eql header
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'roates the output' do
|
55
|
-
expect(
|
56
|
-
|
57
|
-
|
58
|
-
expect(
|
55
|
+
expect(table.to_s).to eq("a1 a2 a3\nb1 b2 b3")
|
56
|
+
table.orientation = :vertical
|
57
|
+
table.rotate
|
58
|
+
expect(table.to_s).to eq("1 a1\n2 a2\n3 a3\n1 b1\n2 b2\n3 b3")
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
context 'with header' do
|
63
63
|
it 'rotates the rows and merges header' do
|
64
|
-
|
65
|
-
expect(
|
64
|
+
table.orientation = :vertical
|
65
|
+
expect(table.rotate.to_a).to eql [
|
66
66
|
['h1', 'a1'],
|
67
67
|
['h2', 'a2'],
|
68
68
|
['h3', 'a3'],
|
@@ -70,17 +70,17 @@ describe TTY::Table, '#rotate' do
|
|
70
70
|
['h2', 'b2'],
|
71
71
|
['h3', 'b3'],
|
72
72
|
]
|
73
|
-
expect(
|
73
|
+
expect(table.header).to be_empty
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'rotates the rows and header back' do
|
77
|
-
|
78
|
-
|
79
|
-
expect(
|
77
|
+
table.orientation = :vertical
|
78
|
+
table.rotate
|
79
|
+
expect(table.orientation).to be_a TTY::Table::Orientation::Vertical
|
80
80
|
|
81
|
-
|
82
|
-
expect(
|
83
|
-
expect(
|
81
|
+
table.orientation = :horizontal
|
82
|
+
expect(table.rotate.to_a).to eql [header] + rows
|
83
|
+
expect(table.header).to eql header
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -13,13 +13,13 @@ describe TTY::Table::Row, '#access' do
|
|
13
13
|
let(:attribute) { 0 }
|
14
14
|
let(:value) { 1 }
|
15
15
|
|
16
|
-
it {
|
16
|
+
it { is_expected.to eq(1) }
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'when symbol' do
|
20
20
|
let(:attribute) { :id }
|
21
21
|
let(:value) { 1 }
|
22
22
|
|
23
|
-
it {
|
23
|
+
it { is_expected.to eq(1) }
|
24
24
|
end
|
25
25
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -12,7 +12,7 @@ describe TTY::Table::Row, '#call' do
|
|
12
12
|
|
13
13
|
let(:attribute) { 1 }
|
14
14
|
|
15
|
-
it {
|
15
|
+
it { is_expected.to eql('b') }
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'when symbol' do
|
@@ -21,13 +21,13 @@ describe TTY::Table::Row, '#call' do
|
|
21
21
|
context 'when hash access' do
|
22
22
|
let(:attribute) { :id }
|
23
23
|
|
24
|
-
it {
|
24
|
+
it { is_expected.to eql(1) }
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'when array access' do
|
28
28
|
let(:attribute) { 0 }
|
29
29
|
|
30
|
-
it {
|
30
|
+
it { is_expected.to eql(1) }
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -11,16 +11,16 @@ describe TTY::Table::Row, '#data' do
|
|
11
11
|
context 'without attributes' do
|
12
12
|
let(:header) { nil }
|
13
13
|
|
14
|
-
it {
|
14
|
+
it { is_expected.to be_instance_of(Hash) }
|
15
15
|
|
16
|
-
it {
|
16
|
+
it { is_expected.to eql(0 => 'a') }
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'with attributes' do
|
20
20
|
let(:header) { [:id] }
|
21
21
|
|
22
|
-
it {
|
22
|
+
it { is_expected.to be_instance_of(Hash) }
|
23
23
|
|
24
|
-
it {
|
24
|
+
it { is_expected.to eql(id: 'a') }
|
25
25
|
end
|
26
26
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -12,62 +12,62 @@ describe TTY::Table::Row, '#==' do
|
|
12
12
|
context 'with the same object' do
|
13
13
|
let(:other) { object }
|
14
14
|
|
15
|
-
it {
|
15
|
+
it { is_expected.to eql(true) }
|
16
16
|
|
17
17
|
it 'is symmetric' do
|
18
|
-
|
18
|
+
is_expected.to eql(other == object)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'with an equivalent object' do
|
23
23
|
let(:other) { object.dup }
|
24
24
|
|
25
|
-
it {
|
25
|
+
it { is_expected.to eql(true) }
|
26
26
|
|
27
27
|
it 'is symmetric' do
|
28
|
-
|
28
|
+
is_expected.to eql(other == object)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'with an equivalent object of subclass' do
|
33
|
-
let(:other) { Class.new(described_class).new(data, :
|
33
|
+
let(:other) { Class.new(described_class).new(data, attributes: attributes) }
|
34
34
|
|
35
|
-
it {
|
35
|
+
it { is_expected.to eql(true) }
|
36
36
|
|
37
37
|
it 'is symmetric' do
|
38
|
-
|
38
|
+
is_expected.to eql(other == object)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context 'with an object having a different attributes' do
|
43
43
|
let(:other_attributes) { [:text] }
|
44
|
-
let(:other) { described_class.new(data, :
|
44
|
+
let(:other) { described_class.new(data, attributes: other_attributes) }
|
45
45
|
|
46
|
-
it {
|
46
|
+
it { is_expected.to eql(true) }
|
47
47
|
|
48
48
|
it 'is symmetric' do
|
49
|
-
|
49
|
+
is_expected.to eql(other == object)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
context 'with an object having a different attributes' do
|
54
54
|
let(:other_data) { [2] }
|
55
|
-
let(:other) { described_class.new(other_data, :
|
55
|
+
let(:other) { described_class.new(other_data, attributes: attributes) }
|
56
56
|
|
57
|
-
it {
|
57
|
+
it { is_expected.to eql(false) }
|
58
58
|
|
59
59
|
it 'is symmetric' do
|
60
|
-
|
60
|
+
is_expected.to eql(other == object)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
context 'with an equivalent object responding to_ary' do
|
65
65
|
let(:other) { data }
|
66
66
|
|
67
|
-
it {
|
67
|
+
it { is_expected.to eql(true) }
|
68
68
|
|
69
69
|
it 'is symmetric' do
|
70
|
-
|
70
|
+
is_expected.to eql(other == object)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -10,32 +10,32 @@ describe TTY::Table::Row, '#new' do
|
|
10
10
|
context 'with no arguments' do
|
11
11
|
let(:data) { [] }
|
12
12
|
|
13
|
-
it {
|
13
|
+
it { is_expected.to be_instance_of(object) }
|
14
14
|
|
15
|
-
it {
|
15
|
+
it { is_expected.to be_empty }
|
16
16
|
|
17
|
-
|
17
|
+
it { expect(subject.attributes).to eq([]) }
|
18
18
|
|
19
|
-
|
19
|
+
it { expect(subject.data).to eq({}) }
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'with Array argument' do
|
23
23
|
let(:data) { ['a'] }
|
24
24
|
|
25
|
-
it {
|
25
|
+
it { is_expected.to be_instance_of(object) }
|
26
26
|
|
27
|
-
|
27
|
+
it { expect(subject.attributes).to eq([0]) }
|
28
28
|
|
29
|
-
|
29
|
+
it { expect(subject.to_hash).to eq({0 => "a"}) }
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'with Hash argument' do
|
33
|
-
let(:data) { {:
|
33
|
+
let(:data) { {id: 'a'} }
|
34
34
|
|
35
35
|
it { should be_instance_of(object) }
|
36
36
|
|
37
|
-
|
37
|
+
it { expect(subject.attributes).to eq([:id]) }
|
38
38
|
|
39
|
-
|
39
|
+
it { expect(subject.to_hash).to eq({:id => 'a'}) }
|
40
40
|
end
|
41
41
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -8,7 +8,7 @@ describe TTY::Table::Row, '#to_ary' do
|
|
8
8
|
|
9
9
|
subject { object.to_ary }
|
10
10
|
|
11
|
-
it {
|
11
|
+
it { is_expected.to be_instance_of(Array) }
|
12
12
|
|
13
|
-
it {
|
13
|
+
it { is_expected.to eq(data) }
|
14
14
|
end
|
data/spec/tty/table/to_s_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Table, '#to_s' do
|
6
|
-
let(:header)
|
7
|
-
let(:rows)
|
6
|
+
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
+
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
8
|
let(:renderer) { :basic }
|
9
9
|
|
10
|
-
subject { described_class.new(header, rows) }
|
10
|
+
subject(:table) { described_class.new(header, rows) }
|
11
11
|
|
12
12
|
context 'without renderer' do
|
13
13
|
let(:renderer) { nil }
|
14
14
|
|
15
15
|
it 'displayes basic table' do
|
16
|
-
|
16
|
+
expect(table.to_s).to eq <<-EOS.normalize
|
17
17
|
h1 h2 h3
|
18
18
|
a1 a2 a3
|
19
19
|
b1 b2 b3
|
@@ -23,7 +23,7 @@ describe TTY::Table, '#to_s' do
|
|
23
23
|
|
24
24
|
context 'without border' do
|
25
25
|
it 'displays table' do
|
26
|
-
|
26
|
+
expect(table.to_s).to eq <<-EOS.normalize
|
27
27
|
h1 h2 h3
|
28
28
|
a1 a2 a3
|
29
29
|
b1 b2 b3
|
@@ -35,7 +35,7 @@ describe TTY::Table, '#to_s' do
|
|
35
35
|
let(:renderer) { :ascii }
|
36
36
|
|
37
37
|
it 'displays table' do
|
38
|
-
|
38
|
+
expect(table.render(renderer)).to eq <<-EOS.normalize
|
39
39
|
+--+--+--+
|
40
40
|
|h1|h2|h3|
|
41
41
|
+--+--+--+
|
@@ -50,7 +50,7 @@ describe TTY::Table, '#to_s' do
|
|
50
50
|
let(:renderer) { :unicode}
|
51
51
|
|
52
52
|
it 'displays table' do
|
53
|
-
|
53
|
+
expect(table.render(renderer)).to eq <<-EOS.normalize
|
54
54
|
┌──┬──┬──┐
|
55
55
|
│h1│h2│h3│
|
56
56
|
├──┼──┼──┤
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -8,25 +8,25 @@ describe TTY::Table::Validatable, '#validate_options!' do
|
|
8
8
|
subject { described_class.new.validate_options! options }
|
9
9
|
|
10
10
|
context 'with empty rows' do
|
11
|
-
let(:options) { {:
|
11
|
+
let(:options) { {rows: []} }
|
12
12
|
|
13
13
|
it { expect { subject }.not_to raise_error() }
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'with invalid rows type' do
|
17
|
-
let(:options) { {:
|
17
|
+
let(:options) { {rows: 1 } }
|
18
18
|
|
19
19
|
it { expect { subject }.to raise_error(TTY::InvalidArgument) }
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'with empty header' do
|
23
|
-
let(:options) { {:
|
23
|
+
let(:options) { {header: []} }
|
24
24
|
|
25
25
|
it { expect { subject }.to raise_error(TTY::InvalidArgument) }
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'with invalid header type' do
|
29
|
-
let(:options) { {:
|
29
|
+
let(:options) { {header: 1} }
|
30
30
|
|
31
31
|
it { expect { subject }.to raise_error(TTY::InvalidArgument) }
|
32
32
|
end
|