tty-table 0.11.0 → 0.12.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 (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +104 -98
  5. data/lib/tty-table.rb +1 -1
  6. data/lib/tty/table.rb +70 -34
  7. data/lib/tty/table/alignment_set.rb +1 -3
  8. data/lib/tty/table/border.rb +50 -57
  9. data/lib/tty/table/border/ascii.rb +16 -16
  10. data/lib/tty/table/border/null.rb +19 -22
  11. data/lib/tty/table/border/row_line.rb +3 -2
  12. data/lib/tty/table/border/unicode.rb +16 -16
  13. data/lib/tty/table/border_dsl.rb +24 -22
  14. data/lib/tty/table/border_options.rb +32 -27
  15. data/lib/tty/table/column_constraint.rb +12 -9
  16. data/lib/tty/table/columns.rb +6 -6
  17. data/lib/tty/table/field.rb +46 -28
  18. data/lib/tty/table/header.rb +5 -5
  19. data/lib/tty/table/indentation.rb +7 -4
  20. data/lib/tty/table/operation/alignment.rb +1 -1
  21. data/lib/tty/table/operation/escape.rb +1 -2
  22. data/lib/tty/table/operation/padding.rb +1 -1
  23. data/lib/tty/table/operation/truncation.rb +1 -1
  24. data/lib/tty/table/operation/wrapped.rb +1 -1
  25. data/lib/tty/table/options.rb +1 -1
  26. data/lib/tty/table/orientation.rb +4 -4
  27. data/lib/tty/table/renderer.rb +8 -8
  28. data/lib/tty/table/renderer/ascii.rb +2 -2
  29. data/lib/tty/table/renderer/basic.rb +37 -40
  30. data/lib/tty/table/renderer/unicode.rb +1 -1
  31. data/lib/tty/table/row.rb +7 -7
  32. data/lib/tty/table/validatable.rb +23 -7
  33. data/lib/tty/table/version.rb +1 -1
  34. metadata +23 -272
  35. data/Rakefile +0 -10
  36. data/examples/alignment.rb +0 -10
  37. data/examples/basic.rb +0 -6
  38. data/examples/orientation.rb +0 -13
  39. data/examples/padding.rb +0 -15
  40. data/examples/resize.rb +0 -15
  41. data/spec/spec_helper.rb +0 -50
  42. data/spec/unit/access_spec.rb +0 -84
  43. data/spec/unit/add_row_spec.rb +0 -26
  44. data/spec/unit/alignment_set/each_spec.rb +0 -15
  45. data/spec/unit/alignment_set/new_spec.rb +0 -25
  46. data/spec/unit/alignment_set/to_ary_spec.rb +0 -12
  47. data/spec/unit/alignment_spec.rb +0 -69
  48. data/spec/unit/border/ascii/rendering_spec.rb +0 -88
  49. data/spec/unit/border/new_spec.rb +0 -25
  50. data/spec/unit/border/null/rendering_spec.rb +0 -128
  51. data/spec/unit/border/options/from_spec.rb +0 -36
  52. data/spec/unit/border/options/new_spec.rb +0 -12
  53. data/spec/unit/border/unicode/rendering_spec.rb +0 -61
  54. data/spec/unit/border_options/new_spec.rb +0 -18
  55. data/spec/unit/border_options/update_spec.rb +0 -16
  56. data/spec/unit/column_constraint/enforce_spec.rb +0 -68
  57. data/spec/unit/column_constraint/widths_spec.rb +0 -33
  58. data/spec/unit/columns/extract_widths_spec.rb +0 -41
  59. data/spec/unit/columns/total_width_spec.rb +0 -11
  60. data/spec/unit/columns/widths_from_spec.rb +0 -49
  61. data/spec/unit/data_spec.rb +0 -10
  62. data/spec/unit/each_spec.rb +0 -24
  63. data/spec/unit/each_with_index_spec.rb +0 -49
  64. data/spec/unit/empty_spec.rb +0 -21
  65. data/spec/unit/eql_spec.rb +0 -32
  66. data/spec/unit/field/equality_spec.rb +0 -49
  67. data/spec/unit/field/length_spec.rb +0 -33
  68. data/spec/unit/field/lines_spec.rb +0 -19
  69. data/spec/unit/field/new_spec.rb +0 -27
  70. data/spec/unit/field/width_spec.rb +0 -21
  71. data/spec/unit/filter_spec.rb +0 -20
  72. data/spec/unit/header/call_spec.rb +0 -28
  73. data/spec/unit/header/color_spec.rb +0 -17
  74. data/spec/unit/header/equality_spec.rb +0 -49
  75. data/spec/unit/header/height_spec.rb +0 -25
  76. data/spec/unit/header/new_spec.rb +0 -13
  77. data/spec/unit/header/set_spec.rb +0 -18
  78. data/spec/unit/header/to_ary_spec.rb +0 -12
  79. data/spec/unit/header_spec.rb +0 -11
  80. data/spec/unit/indentation/indent_spec.rb +0 -15
  81. data/spec/unit/new_spec.rb +0 -71
  82. data/spec/unit/operation/alignment/call_spec.rb +0 -37
  83. data/spec/unit/operation/escape/call_spec.rb +0 -13
  84. data/spec/unit/operation/filter/call_spec.rb +0 -14
  85. data/spec/unit/operation/truncation/call_spec.rb +0 -28
  86. data/spec/unit/operation/wrapped/call_spec.rb +0 -38
  87. data/spec/unit/operations/new_spec.rb +0 -28
  88. data/spec/unit/options/access_spec.rb +0 -12
  89. data/spec/unit/options_spec.rb +0 -23
  90. data/spec/unit/orientation_spec.rb +0 -143
  91. data/spec/unit/padding_spec.rb +0 -115
  92. data/spec/unit/properties_spec.rb +0 -23
  93. data/spec/unit/render_repeat_spec.rb +0 -39
  94. data/spec/unit/render_spec.rb +0 -61
  95. data/spec/unit/render_with_spec.rb +0 -104
  96. data/spec/unit/renderer/ascii/coloring_spec.rb +0 -83
  97. data/spec/unit/renderer/ascii/indentation_spec.rb +0 -39
  98. data/spec/unit/renderer/ascii/multiline_spec.rb +0 -99
  99. data/spec/unit/renderer/ascii/padding_spec.rb +0 -115
  100. data/spec/unit/renderer/ascii/render_spec.rb +0 -66
  101. data/spec/unit/renderer/ascii/resizing_spec.rb +0 -112
  102. data/spec/unit/renderer/ascii/separator_spec.rb +0 -38
  103. data/spec/unit/renderer/basic/alignment_spec.rb +0 -86
  104. data/spec/unit/renderer/basic/coloring_spec.rb +0 -59
  105. data/spec/unit/renderer/basic/extract_column_widths_spec.rb +0 -26
  106. data/spec/unit/renderer/basic/filter_spec.rb +0 -51
  107. data/spec/unit/renderer/basic/indentation_spec.rb +0 -46
  108. data/spec/unit/renderer/basic/multiline_spec.rb +0 -72
  109. data/spec/unit/renderer/basic/new_spec.rb +0 -24
  110. data/spec/unit/renderer/basic/options_spec.rb +0 -50
  111. data/spec/unit/renderer/basic/padding_spec.rb +0 -74
  112. data/spec/unit/renderer/basic/render_spec.rb +0 -55
  113. data/spec/unit/renderer/basic/resizing_spec.rb +0 -94
  114. data/spec/unit/renderer/basic/separator_spec.rb +0 -41
  115. data/spec/unit/renderer/basic/single_row_separator_spec.rb +0 -80
  116. data/spec/unit/renderer/basic/truncation_spec.rb +0 -33
  117. data/spec/unit/renderer/basic/wrapping_spec.rb +0 -38
  118. data/spec/unit/renderer/border_spec.rb +0 -102
  119. data/spec/unit/renderer/render_spec.rb +0 -34
  120. data/spec/unit/renderer/select_spec.rb +0 -20
  121. data/spec/unit/renderer/unicode/coloring_spec.rb +0 -68
  122. data/spec/unit/renderer/unicode/indentation_spec.rb +0 -39
  123. data/spec/unit/renderer/unicode/padding_spec.rb +0 -59
  124. data/spec/unit/renderer/unicode/render_spec.rb +0 -66
  125. data/spec/unit/renderer/unicode/separator_spec.rb +0 -36
  126. data/spec/unit/renderer_spec.rb +0 -17
  127. data/spec/unit/rotate_spec.rb +0 -84
  128. data/spec/unit/row/access_spec.rb +0 -23
  129. data/spec/unit/row/call_spec.rb +0 -43
  130. data/spec/unit/row/data_spec.rb +0 -24
  131. data/spec/unit/row/each_spec.rb +0 -29
  132. data/spec/unit/row/equality_spec.rb +0 -71
  133. data/spec/unit/row/height_spec.rb +0 -25
  134. data/spec/unit/row/new_spec.rb +0 -39
  135. data/spec/unit/row/to_ary_spec.rb +0 -12
  136. data/spec/unit/to_s_spec.rb +0 -56
  137. data/spec/unit/transformation/extract_tuples_spec.rb +0 -33
  138. data/spec/unit/utf_spec.rb +0 -31
  139. data/spec/unit/validatable/validate_options_spec.rb +0 -31
  140. data/spec/unit/validatable_spec.rb +0 -30
  141. data/tasks/console.rake +0 -11
  142. data/tasks/coverage.rake +0 -11
  143. data/tasks/spec.rake +0 -29
  144. data/tty-table.gemspec +0 -41
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Renderer::Unicode, 'coloring' do
4
-
5
- let(:color) { Pastel.new(enabled: true) }
6
-
7
- before { allow(Pastel).to receive(:new).and_return(color) }
8
-
9
- context 'when border' do
10
- it "colors border" do
11
- table = TTY::Table.new header: ['header1', 'header2']
12
- table << ['a1', 'a2']
13
- table << ['b1', 'b2']
14
- renderer = described_class.new(table)
15
- renderer.border = {style: :green }
16
-
17
- expect(renderer.render).to eq unindent(<<-EOS)
18
- #{color.green('┌───────┬───────┐')}
19
- #{color.green('│')}header1#{color.green('│')}header2#{color.green('│')}
20
- #{color.green('├───────┼───────┤')}
21
- #{color.green('│')}a1 #{color.green('│')}a2 #{color.green('│')}
22
- #{color.green('│')}b1 #{color.green('│')}b2 #{color.green('│')}
23
- #{color.green('└───────┴───────┘')}
24
- EOS
25
- end
26
- end
27
-
28
- context 'when content' do
29
- it "colors individual field" do
30
- header = [color.yellow('header1'), 'header2']
31
- table = TTY::Table.new header: header
32
- table << [color.green.on_blue('a1'), 'a2']
33
- table << ['b1', color.red.on_yellow('b2')]
34
- renderer = described_class.new(table)
35
-
36
- expect(renderer.render).to eq unindent(<<-EOS)
37
- ┌───────┬───────┐
38
- │#{color.yellow('header1')}│header2│
39
- ├───────┼───────┤
40
- │#{color.green.on_blue('a1')} │a2 │
41
- │b1 │#{color.red.on_yellow('b2')} │
42
- └───────┴───────┘
43
- EOS
44
- end
45
-
46
- it "colors multiline content" do
47
- header = [color.yellow("Multi\nHeader"), 'header2']
48
- table = TTY::Table.new header: header
49
- table << [color.green.on_blue("Multi\nLine\nContent"), 'a2']
50
- table << ['b1', color.red.on_yellow("Multi\nLine\nContent")]
51
- renderer = described_class.new(table, multiline: true)
52
-
53
- expect(renderer.render).to eq unindent(<<-EOS)
54
- ┌───────┬───────┐
55
- │#{color.yellow('Multi ')}│header2│
56
- │#{color.yellow('Header')} │ │
57
- ├───────┼───────┤
58
- │#{color.green.on_blue('Multi ')}│a2 │
59
- │#{color.green.on_blue('Line ')}│ │
60
- │#{color.green.on_blue('Content')}│ │
61
- │b1 │#{color.red.on_yellow("Multi ")}│
62
- │ │#{color.red.on_yellow("Line ")}│
63
- │ │#{color.red.on_yellow("Content")}│
64
- └───────┴───────┘
65
- EOS
66
- end
67
- end
68
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Renderer::Unicode, 'indentation' do
4
- let(:header) { ['h1', 'h2', 'h3'] }
5
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
6
- let(:table) { TTY::Table.new(header, rows) }
7
- let(:indent) { 2 }
8
- let(:options) { {indent: indent } }
9
-
10
- subject(:renderer) { described_class.new(table, options)}
11
-
12
- context 'when default' do
13
- it 'indents by value' do
14
- expect(renderer.render).to eq <<-EOS.chomp
15
- ┌──┬──┬──┐
16
- │h1│h2│h3│
17
- ├──┼──┼──┤
18
- │a1│a2│a3│
19
- │b1│b2│b3│
20
- └──┴──┴──┘
21
- EOS
22
- end
23
- end
24
-
25
- context 'when each row' do
26
- it 'indents by value' do
27
- renderer.border.separator = :each_row
28
- expect(renderer.render).to eql <<-EOS.chomp
29
- ┌──┬──┬──┐
30
- │h1│h2│h3│
31
- ├──┼──┼──┤
32
- │a1│a2│a3│
33
- ├──┼──┼──┤
34
- │b1│b2│b3│
35
- └──┴──┴──┘
36
- EOS
37
- end
38
- end
39
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Renderer::Unicode, 'padding' do
4
- let(:header) { ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'] }
5
- let(:rows) { [['id', 'int(11)', 'YES', 'nil', 'NULL', '']] }
6
- let(:table) { TTY::Table.new(header, rows) }
7
-
8
- subject(:renderer) { described_class.new(table, options) }
9
-
10
- context 'with left & right padding' do
11
- let(:options) { {padding: [0,1,0,1]} }
12
-
13
- it 'pads each field' do
14
- expect(renderer.render).to eql unindent(<<-EOS)
15
- ┌───────┬─────────┬──────┬─────┬─────────┬───────┐
16
- │ Field │ Type │ Null │ Key │ Default │ Extra │
17
- ├───────┼─────────┼──────┼─────┼─────────┼───────┤
18
- │ id │ int(11) │ YES │ nil │ NULL │ │
19
- └───────┴─────────┴──────┴─────┴─────────┴───────┘
20
- EOS
21
- end
22
- end
23
-
24
- context 'with top & bottom padding' do
25
- let(:options) { {padding: [1,0,1,0], multiline: true} }
26
-
27
- it 'pads each field' do
28
- expect(renderer.render).to eql unindent(<<-EOS)
29
- ┌─────┬───────┬────┬───┬───────┬─────┐
30
- │ │ │ │ │ │ │
31
- │Field│Type │Null│Key│Default│Extra│
32
- │ │ │ │ │ │ │
33
- ├─────┼───────┼────┼───┼───────┼─────┤
34
- │ │ │ │ │ │ │
35
- │id │int(11)│YES │nil│NULL │ │
36
- │ │ │ │ │ │ │
37
- └─────┴───────┴────┴───┴───────┴─────┘
38
- EOS
39
- end
40
- end
41
-
42
- context 'with full padding' do
43
- let(:options) { {padding: [1,1,1,1], multiline: true} }
44
-
45
- it 'pads each field' do
46
- expect(renderer.render).to eql unindent(<<-EOS)
47
- ┌───────┬─────────┬──────┬─────┬─────────┬───────┐
48
- │ │ │ │ │ │ │
49
- │ Field │ Type │ Null │ Key │ Default │ Extra │
50
- │ │ │ │ │ │ │
51
- ├───────┼─────────┼──────┼─────┼─────────┼───────┤
52
- │ │ │ │ │ │ │
53
- │ id │ int(11) │ YES │ nil │ NULL │ │
54
- │ │ │ │ │ │ │
55
- └───────┴─────────┴──────┴─────┴─────────┴───────┘
56
- EOS
57
- end
58
- end
59
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Renderer::Unicode, '#render' do
4
- let(:header) { ['h1', 'h2', 'h3'] }
5
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
6
- let(:table) { TTY::Table.new header, rows }
7
-
8
- subject(:renderer) { described_class.new(table) }
9
-
10
- context 'with rows only' do
11
- let(:table) { TTY::Table.new rows }
12
-
13
- it 'display table rows' do
14
- expect(renderer.render).to eq unindent(<<-EOS)
15
- ┌──┬──┬──┐
16
- │a1│a2│a3│
17
- │b1│b2│b3│
18
- └──┴──┴──┘
19
- EOS
20
- end
21
- end
22
-
23
- context 'with header' do
24
- it 'displays table with header' do
25
- expect(renderer.render).to eq unindent(<<-EOS)
26
- ┌──┬──┬──┐
27
- │h1│h2│h3│
28
- ├──┼──┼──┤
29
- │a1│a2│a3│
30
- │b1│b2│b3│
31
- └──┴──┴──┘
32
- EOS
33
- end
34
- end
35
-
36
- context 'with short header' do
37
- let(:header) { ['h1', 'h2'] }
38
- let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
39
-
40
- it 'displays table according to widths' do
41
- expect(renderer.render).to eq unindent(<<-EOS)
42
- ┌────┬───┐
43
- │h1 │h2 │
44
- ├────┼───┤
45
- │aaa1│a2 │
46
- │b1 │bb1│
47
- └────┴───┘
48
- EOS
49
- end
50
- end
51
-
52
- context 'with long header' do
53
- let(:header) { ['header1', 'header2', 'header3'] }
54
-
55
- it 'header greater than row sizes' do
56
- expect(renderer.render).to eq unindent(<<-EOS)
57
- ┌───────┬───────┬───────┐
58
- │header1│header2│header3│
59
- ├───────┼───────┼───────┤
60
- │a1 │a2 │a3 │
61
- │b1 │b2 │b3 │
62
- └───────┴───────┴───────┘
63
- EOS
64
- end
65
- end
66
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Renderer::Unicode, 'with separator' do
4
- let(:header) { ['h1', 'h2', 'h3'] }
5
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
6
- let(:table) { TTY::Table.new(header, rows) }
7
-
8
- let(:object) { described_class.new table }
9
-
10
- subject(:renderer) { object }
11
-
12
- it "renders each row" do
13
- renderer.border.separator= :each_row
14
- expect(renderer.render).to eq unindent(<<-EOS)
15
- ┌──┬──┬──┐
16
- │h1│h2│h3│
17
- ├──┼──┼──┤
18
- │a1│a2│a3│
19
- ├──┼──┼──┤
20
- │b1│b2│b3│
21
- └──┴──┴──┘
22
- EOS
23
- end
24
-
25
- it "will not the default separator if individual separators are specified" do
26
- renderer.border.separator = [1]
27
- expect(renderer.render).to eq unindent(<<-EOS)
28
- ┌──┬──┬──┐
29
- │h1│h2│h3│
30
- │a1│a2│a3│
31
- ├──┼──┼──┤
32
- │b1│b2│b3│
33
- └──┴──┴──┘
34
- EOS
35
- end
36
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table, '#renderer' do
4
- let(:object) { described_class }
5
- let(:header) { ['h1', 'h2'] }
6
- let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
7
-
8
- subject(:table) { object.new(header, rows).renderer }
9
-
10
- it 'creates new renderer' do
11
- expect(subject).to be_kind_of(TTY::Table::Renderer::Basic)
12
- end
13
-
14
- it 'chains calls on renderer' do
15
- expect(subject.render).to eql("h1 h2\na1 a2\nb1 b2")
16
- end
17
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table, '#rotate' do
4
- let(:header) { ['h1', 'h2', 'h3'] }
5
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
6
-
7
- subject(:table) { described_class.new(header, rows) }
8
-
9
- before { table.orientation = :horizontal }
10
-
11
- context 'with default' do
12
- context 'without header' do
13
- let(:header) { nil }
14
-
15
- it 'preserves orientation' do
16
- expect(table.header).to be_nil
17
- expect(table.rotate.to_a).to eql rows
18
- end
19
- end
20
-
21
- context 'with header' do
22
- it 'preserves orientation' do
23
- expect(table.rotate.to_a).to eql [header] + rows
24
- end
25
- end
26
- end
27
-
28
- context 'with no header' do
29
- let(:header) { nil }
30
-
31
- it 'rotates the rows' do
32
- table.orientation = :vertical
33
- expect(table.rotate.to_a).to eql [
34
- ['1', 'a1'],
35
- ['2', 'a2'],
36
- ['3', 'a3'],
37
- ['1', 'b1'],
38
- ['2', 'b2'],
39
- ['3', 'b3'],
40
- ]
41
- expect(table.header).to be_nil
42
- end
43
-
44
- it 'rotates the rows back' do
45
- table.orientation = :vertical
46
- table.rotate
47
- table.orientation = :horizontal
48
- expect(table.rotate.to_a).to eql rows
49
- expect(table.header).to eql header
50
- end
51
-
52
- it 'roates the output' do
53
- expect(table.to_s).to eq("a1 a2 a3\nb1 b2 b3")
54
- table.orientation = :vertical
55
- table.rotate
56
- expect(table.to_s).to eq("1 a1\n2 a2\n3 a3\n1 b1\n2 b2\n3 b3")
57
- end
58
- end
59
-
60
- context 'with header' do
61
- it 'rotates the rows and merges header' do
62
- table.orientation = :vertical
63
- expect(table.rotate.to_a).to eql [
64
- ['h1', 'a1'],
65
- ['h2', 'a2'],
66
- ['h3', 'a3'],
67
- ['h1', 'b1'],
68
- ['h2', 'b2'],
69
- ['h3', 'b3'],
70
- ]
71
- expect(table.header).to be_empty
72
- end
73
-
74
- it 'rotates the rows and header back' do
75
- table.orientation = :vertical
76
- table.rotate
77
- expect(table.orientation).to be_a TTY::Table::Orientation::Vertical
78
-
79
- table.orientation = :horizontal
80
- expect(table.rotate.to_a).to eql [header] + rows
81
- expect(table.header).to eql header
82
- end
83
- end
84
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Row, '#access' do
4
- let(:object) { described_class.new [] }
5
-
6
- before { object[attribute] = value}
7
-
8
- subject { object[attribute] }
9
-
10
- context 'when integer' do
11
- let(:attribute) { 0 }
12
- let(:value) { 1 }
13
-
14
- it { is_expected.to eq(1) }
15
- end
16
-
17
- context 'when symbol' do
18
- let(:attribute) { :id }
19
- let(:value) { 1 }
20
-
21
- it { is_expected.to eq(1) }
22
- end
23
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Row, '#call' do
4
- let(:object) { described_class.new(data) }
5
-
6
- subject { object[attribute] }
7
-
8
- context 'when integer' do
9
- let(:data) { ['a', 'b'] }
10
-
11
- let(:attribute) { 1 }
12
-
13
- it { is_expected.to eql('b') }
14
- end
15
-
16
- context 'when symbol' do
17
- let(:data) { {:id => 1} }
18
-
19
- context 'when hash access' do
20
- let(:attribute) { :id }
21
-
22
- it { is_expected.to eql(1) }
23
- end
24
-
25
- context 'when array access' do
26
- let(:attribute) { 0 }
27
-
28
- it { is_expected.to eql(1) }
29
- end
30
- end
31
-
32
- context 'when unkown attribute' do
33
- let(:data) { {:id => 1} }
34
-
35
- let(:attribute) { :other }
36
-
37
- specify {
38
- expect {
39
- subject
40
- }.to raise_error(TTY::Table::UnknownAttributeError)
41
- }
42
- end
43
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Row, '#data' do
4
- let(:object) { described_class.new data, header }
5
- let(:data) { ['a'] }
6
-
7
- subject { object.to_hash }
8
-
9
- context 'without attributes' do
10
- let(:header) { nil }
11
-
12
- it { is_expected.to be_instance_of(Hash) }
13
-
14
- it { is_expected.to eql(0 => 'a') }
15
- end
16
-
17
- context 'with attributes' do
18
- let(:header) { [:id] }
19
-
20
- it { is_expected.to be_instance_of(Hash) }
21
-
22
- it { is_expected.to eql(id: 'a') }
23
- end
24
- end