tty-table 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/README.md +458 -142
  4. data/lib/tty-table.rb +6 -6
  5. data/lib/tty/table.rb +34 -34
  6. data/lib/tty/table/alignment_set.rb +73 -0
  7. data/lib/tty/table/border.rb +54 -36
  8. data/lib/tty/table/border/null.rb +4 -4
  9. data/lib/tty/table/{columns.rb → column_constraint.rb} +30 -32
  10. data/lib/tty/table/column_set.rb +18 -17
  11. data/lib/tty/table/field.rb +50 -25
  12. data/lib/tty/table/header.rb +6 -2
  13. data/lib/tty/table/indentation.rb +7 -12
  14. data/lib/tty/table/operation/alignment.rb +59 -0
  15. data/lib/tty/table/operation/escape.rb +1 -1
  16. data/lib/tty/table/operation/filter.rb +1 -1
  17. data/lib/tty/table/operation/padding.rb +12 -61
  18. data/lib/tty/table/operation/truncation.rb +2 -2
  19. data/lib/tty/table/operation/wrapped.rb +2 -5
  20. data/lib/tty/table/operations.rb +35 -17
  21. data/lib/tty/table/orientation/vertical.rb +4 -4
  22. data/lib/tty/table/renderer.rb +1 -7
  23. data/lib/tty/table/renderer/basic.rb +69 -63
  24. data/lib/tty/table/version.rb +1 -1
  25. data/spec/spec_helper.rb +3 -4
  26. data/spec/unit/access_spec.rb +8 -8
  27. data/spec/unit/{operation/alignment_set → alignment_set}/each_spec.rb +1 -1
  28. data/spec/unit/{operation/alignment_set → alignment_set}/new_spec.rb +4 -4
  29. data/spec/unit/{operation/alignment_set → alignment_set}/to_ary_spec.rb +1 -1
  30. data/spec/unit/alignment_spec.rb +71 -0
  31. data/spec/unit/border/ascii/rendering_spec.rb +12 -12
  32. data/spec/unit/border/new_spec.rb +2 -2
  33. data/spec/unit/border/null/rendering_spec.rb +2 -2
  34. data/spec/unit/border/unicode/rendering_spec.rb +10 -10
  35. data/spec/unit/{columns → column_constraint}/enforce_spec.rb +15 -12
  36. data/spec/unit/{columns → column_constraint}/widths_spec.rb +6 -6
  37. data/spec/unit/column_set/extract_widths_spec.rb +39 -6
  38. data/spec/unit/data_spec.rb +4 -6
  39. data/spec/unit/each_spec.rb +8 -23
  40. data/spec/unit/each_with_index_spec.rb +27 -33
  41. data/spec/unit/field/length_spec.rb +23 -9
  42. data/spec/unit/field/width_spec.rb +1 -1
  43. data/spec/unit/filter_spec.rb +7 -8
  44. data/spec/unit/header/new_spec.rb +6 -15
  45. data/spec/unit/indentation/indent_spec.rb +21 -0
  46. data/spec/unit/new_spec.rb +73 -0
  47. data/spec/unit/operation/{alignment_set → alignment}/call_spec.rb +1 -1
  48. data/spec/unit/operation/escape/call_spec.rb +2 -3
  49. data/spec/unit/operation/filter/call_spec.rb +2 -3
  50. data/spec/unit/operation/truncation/call_spec.rb +6 -8
  51. data/spec/unit/operation/wrapped/call_spec.rb +15 -8
  52. data/spec/unit/operations/new_spec.rb +1 -1
  53. data/spec/unit/orientation_spec.rb +6 -6
  54. data/spec/unit/padding_spec.rb +29 -32
  55. data/spec/unit/properties_spec.rb +4 -4
  56. data/spec/unit/render_repeat_spec.rb +42 -0
  57. data/spec/unit/render_spec.rb +1 -1
  58. data/spec/unit/render_with_spec.rb +3 -3
  59. data/spec/unit/renderer/ascii/coloring_spec.rb +70 -0
  60. data/spec/unit/renderer/ascii/multiline_spec.rb +101 -0
  61. data/spec/unit/renderer/ascii/padding_spec.rb +37 -10
  62. data/spec/unit/renderer/ascii/render_spec.rb +4 -4
  63. data/spec/unit/renderer/ascii/resizing_spec.rb +22 -22
  64. data/spec/unit/renderer/ascii/separator_spec.rb +1 -1
  65. data/spec/unit/renderer/basic/alignment_spec.rb +20 -20
  66. data/spec/unit/renderer/basic/coloring_spec.rb +43 -28
  67. data/spec/unit/renderer/basic/filter_spec.rb +3 -3
  68. data/spec/unit/renderer/basic/multiline_spec.rb +74 -0
  69. data/spec/unit/renderer/basic/options_spec.rb +9 -9
  70. data/spec/unit/renderer/basic/padding_spec.rb +26 -2
  71. data/spec/unit/renderer/basic/render_spec.rb +4 -4
  72. data/spec/unit/renderer/basic/resizing_spec.rb +18 -18
  73. data/spec/unit/renderer/basic/separator_spec.rb +1 -1
  74. data/spec/unit/renderer/basic/truncation_spec.rb +6 -6
  75. data/spec/unit/renderer/basic/wrapping_spec.rb +3 -3
  76. data/spec/unit/renderer/border_spec.rb +4 -4
  77. data/spec/unit/renderer/unicode/coloring_spec.rb +70 -0
  78. data/spec/unit/renderer/unicode/indentation_spec.rb +1 -1
  79. data/spec/unit/renderer/unicode/padding_spec.rb +26 -26
  80. data/spec/unit/renderer/unicode/render_spec.rb +4 -4
  81. data/spec/unit/renderer/unicode/separator_spec.rb +1 -1
  82. data/spec/unit/to_s_spec.rb +4 -11
  83. data/spec/unit/utf_spec.rb +33 -0
  84. data/tty-table.gemspec +2 -1
  85. metadata +52 -32
  86. data/lib/tty/table/operation/alignment_set.rb +0 -103
  87. data/lib/tty/table/padder.rb +0 -180
  88. data/lib/tty/table/renderer/color.rb +0 -12
  89. data/spec/unit/indentation/insert_indent_spec.rb +0 -27
  90. data/spec/unit/initialize_spec.rb +0 -88
  91. data/spec/unit/padder/parse_spec.rb +0 -45
  92. data/spec/unit/padder/to_s_spec.rb +0 -14
  93. data/spec/unit/renderer/basic/multiline_content_spec.rb +0 -135
  94. data/spec/unit/renderer/style_spec.rb +0 -72
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  class Table
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end # TTY
data/spec/spec_helper.rb CHANGED
@@ -44,8 +44,7 @@ RSpec.configure do |config|
44
44
  Kernel.srand config.seed
45
45
  end
46
46
 
47
- class String
48
- def normalize
49
- gsub(/^[ \t]*/, '').chomp
50
- end
47
+ def unindent(string)
48
+ prefix = string.scan(/^[ \t]+(?=\S)/).min
49
+ string.gsub(/^#{prefix}/, '').chomp
51
50
  end
@@ -17,11 +17,11 @@ RSpec.describe TTY::Table, 'access' do
17
17
  context 'when array like access' do
18
18
  it { expect(table[0,0]).to eq('a1') }
19
19
 
20
- it { expect(table[0]).to eq(rows[0]) }
20
+ it { expect(table[0]).to eq(['a1','a2']) }
21
21
 
22
22
  it { expect(table[5]).to eq(nil) }
23
23
 
24
- it { expect(table[-1]).to eq(rows[-1]) }
24
+ it { expect(table[-1]).to eq(['b1','b2']) }
25
25
 
26
26
  it { expect(table[5,5]).to eq(nil) }
27
27
 
@@ -46,9 +46,9 @@ RSpec.describe TTY::Table, 'access' do
46
46
 
47
47
  it 'yields row at index' do
48
48
  yields = []
49
- expect { table.row(1).each { |el| yields << el } }.to change { yields }.
50
- from( [] ).
51
- to( rows[1] )
49
+ expect {
50
+ table.row(1).each { |el| yields << el }
51
+ }.to change { yields }.from( [] ).to( rows[1] )
52
52
  end
53
53
  end
54
54
 
@@ -78,9 +78,9 @@ RSpec.describe TTY::Table, 'access' do
78
78
 
79
79
  it 'yields column at index' do
80
80
  yields = []
81
- expect { table.column(1).each { |el| yields << el } }.to change { yields }.
82
- from( [] ).
83
- to( ['a2', 'b2'])
81
+ expect {
82
+ table.column(1).each { |el| yields << el }
83
+ }.to change { yields }.from( [] ).to( ['a2', 'b2'])
84
84
  end
85
85
  end
86
86
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe TTY::Table::Operation::AlignmentSet, '#each' do
5
+ RSpec.describe TTY::Table::AlignmentSet, '#each' do
6
6
  let(:alignments) { [:left, :center, :right] }
7
7
  let(:yields) { [] }
8
8
  let(:object) { described_class.new alignments }
@@ -2,10 +2,10 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe TTY::Table::Operation::AlignmentSet, '#new' do
5
+ RSpec.describe TTY::Table::AlignmentSet, '#new' do
6
6
  let(:object) { described_class }
7
7
 
8
- subject { object.new(argument) }
8
+ subject(:alignment_set) { object.new(argument) }
9
9
 
10
10
  context 'with no argument' do
11
11
  let(:argument) { [] }
@@ -14,7 +14,7 @@ RSpec.describe TTY::Table::Operation::AlignmentSet, '#new' do
14
14
 
15
15
  it { is_expected.to be_instance_of(object) }
16
16
 
17
- it { expect(subject.alignments).to eq([]) }
17
+ it { expect(alignment_set.to_a).to eq([]) }
18
18
  end
19
19
 
20
20
  context 'with argument' do
@@ -22,6 +22,6 @@ RSpec.describe TTY::Table::Operation::AlignmentSet, '#new' do
22
22
 
23
23
  it { is_expected.to be_instance_of(object) }
24
24
 
25
- it { expect(subject.alignments).to eq(argument) }
25
+ it { expect(alignment_set.to_a).to eq(argument) }
26
26
  end
27
27
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe TTY::Table::Operation::AlignmentSet, '#to_ary' do
5
+ RSpec.describe TTY::Table::AlignmentSet, '#to_ary' do
6
6
  let(:argument) { [:center, :left] }
7
7
  let(:object) { described_class.new argument }
8
8
 
@@ -0,0 +1,71 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe TTY::Table, 'alignment' do
6
+ it "aligns table columns when rendering" do
7
+ table = TTY::Table.new ['header1', 'header2'], [['a1','a2'],['b1','b2']]
8
+ expect(table.render(alignments: [:right, :center])).to eql([
9
+ "header1 header2",
10
+ " a1 a2 ",
11
+ " b1 b2 "
12
+ ].join("\n"))
13
+ end
14
+
15
+ it "uses default alignment when too few alignments provided" do
16
+ table = TTY::Table.new ['header1', 'header2'], [['a1','a2'],['b1','b2']]
17
+ expect(table.render(alignments: [:right])).to eql([
18
+ "header1 header2",
19
+ " a1 a2 ",
20
+ " b1 b2 "
21
+ ].join("\n"))
22
+ end
23
+
24
+ it "aligns table columns without header when rendering" do
25
+ table = TTY::Table.new [['aaaaa1','a2'],['b1','bbbbb2']]
26
+ expect(table.render(alignments: [:right, :center])).to eql([
27
+ "aaaaa1 a2 ",
28
+ " b1 bbbbb2"
29
+ ].join("\n"))
30
+ end
31
+
32
+ it "aligns individual fields when rendering" do
33
+ table = TTY::Table.new header: ['header1', 'header2']
34
+ table << ['a1', {value: 'a2', alignment: :center}]
35
+ table << [{value: 'b1', alignment: :right}, 'b2']
36
+ expect(table.render).to eql([
37
+ "header1 header2",
38
+ "a1 a2 ",
39
+ " b1 b2 "
40
+ ].join("\n"))
41
+ end
42
+
43
+ it "prioritizes individual field options over table rendering options" do
44
+ table = TTY::Table.new header: ['header1', 'header2']
45
+ table << [{value: 'a1', alignment: :center},'a2']
46
+ table << ['b1','b2']
47
+ expect(table.render(alignments: [:right, :center])).to eql([
48
+ "header1 header2",
49
+ " a1 a2 ",
50
+ " b1 b2 "
51
+ ].join("\n"))
52
+ end
53
+
54
+ it "allows to align all columns at once" do
55
+ table = TTY::Table.new ['header1', 'header2'], [['a1','a2'],['b1','b2']]
56
+ expect(table.render(alignment: [:center])).to eql([
57
+ "header1 header2",
58
+ " a1 a2 ",
59
+ " b1 b2 "
60
+ ].join("\n"))
61
+ end
62
+
63
+ xit "aligns specific column" do
64
+ table = TTY::Table.new ['header1', 'header2'], [['a1','a2'],['b1','b2']]
65
+ expect(table.render(column_alignment: [1, :center])).to eql([
66
+ "header1 header2",
67
+ "a1 a2 ",
68
+ "b1 b2 "
69
+ ].join("\n"))
70
+ end
71
+ end
@@ -4,26 +4,26 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe TTY::Table::Border::ASCII, '#rendering' do
6
6
 
7
- subject { described_class.new(column_widths) }
7
+ subject(:border) { described_class.new(column_widths, [0,0,0,0]) }
8
8
 
9
9
  context 'with empty row' do
10
10
  let(:row) { TTY::Table::Row.new([]) }
11
11
  let(:column_widths) { [] }
12
12
 
13
13
  it 'draws top line' do
14
- expect(subject.top_line).to eq("++")
14
+ expect(border.top_line).to eq("++")
15
15
  end
16
16
 
17
17
  it 'draws middle line' do
18
- expect(subject.separator).to eq("++")
18
+ expect(border.separator).to eq("++")
19
19
  end
20
20
 
21
21
  it 'draw bottom line' do
22
- expect(subject.bottom_line).to eq("++")
22
+ expect(border.bottom_line).to eq("++")
23
23
  end
24
24
 
25
25
  it 'draws row line' do
26
- expect(subject.row_line(row)).to eq("||")
26
+ expect(border.row_line(row)).to eq("||")
27
27
  end
28
28
  end
29
29
 
@@ -32,19 +32,19 @@ RSpec.describe TTY::Table::Border::ASCII, '#rendering' do
32
32
  let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
33
33
 
34
34
  it 'draws top line' do
35
- expect(subject.top_line).to eq("+--+--+--+")
35
+ expect(border.top_line).to eq("+--+--+--+")
36
36
  end
37
37
 
38
38
  it 'draw middle line' do
39
- expect(subject.separator).to eq("+--+--+--+")
39
+ expect(border.separator).to eq("+--+--+--+")
40
40
  end
41
41
 
42
42
  it 'draw bottom line' do
43
- expect(subject.bottom_line).to eq("+--+--+--+")
43
+ expect(border.bottom_line).to eq("+--+--+--+")
44
44
  end
45
45
 
46
46
  it 'draws row line' do
47
- expect(subject.row_line(row)).to eq("|a1|a2|a3|")
47
+ expect(border.row_line(row)).to eq("|a1|a2|a3|")
48
48
  end
49
49
  end
50
50
 
@@ -55,7 +55,7 @@ RSpec.describe TTY::Table::Border::ASCII, '#rendering' do
55
55
  let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }
56
56
 
57
57
  it 'draws row line' do
58
- expect(subject.row_line(row)).to eq <<-EOS.normalize
58
+ expect(border.row_line(row)).to eq unindent(<<-EOS)
59
59
  |a1|a2|a3|
60
60
  |b1| | |
61
61
  |c1| | |
@@ -67,7 +67,7 @@ RSpec.describe TTY::Table::Border::ASCII, '#rendering' do
67
67
  let(:row) { TTY::Table::Row.new(["a1\n\n", "\na2\n", "\n\na3"]) }
68
68
 
69
69
  it 'draws row line' do
70
- expect(subject.row_line(row)).to eq <<-EOS.normalize
70
+ expect(border.row_line(row)).to eq unindent(<<-EOS)
71
71
  |a1| | |
72
72
  | |a2| |
73
73
  | | |a3|
@@ -79,7 +79,7 @@ RSpec.describe TTY::Table::Border::ASCII, '#rendering' do
79
79
  let(:row) { TTY::Table::Row.new(["\na1\n", "\na2\n", "\na3\n"]) }
80
80
 
81
81
  it 'draws row line' do
82
- expect(subject.row_line(row)).to eq <<-EOS.normalize
82
+ expect(border.row_line(row)).to eq unindent(<<-EOS)
83
83
  | | | |
84
84
  |a1|a2|a3|
85
85
  | | | |
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  RSpec.describe TTY::Table::Border, '#new' do
6
6
  let(:row) { [] }
7
7
 
8
- subject(:instance) { klass.new row }
8
+ subject(:instance) { klass.new row, [0,0,0,0] }
9
9
 
10
10
  context 'when abstract' do
11
11
  let(:klass) { described_class }
@@ -16,7 +16,7 @@ RSpec.describe TTY::Table::Border, '#new' do
16
16
  context 'when concrete' do
17
17
  let(:klass) {
18
18
  Class.new do
19
- def initialize(row); end
19
+ def initialize(row, padding); end
20
20
  end
21
21
  }
22
22
 
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  RSpec.describe TTY::Table::Border::Null, '#rendering' do
6
6
  let(:border) { nil }
7
7
 
8
- subject { described_class.new column_widths, border }
8
+ subject { described_class.new column_widths, [0,0,0,0], border }
9
9
 
10
10
  context 'with empty row' do
11
11
  let(:row) { TTY::Table::Row.new([]) }
@@ -56,7 +56,7 @@ RSpec.describe TTY::Table::Border::Null, '#rendering' do
56
56
  let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }
57
57
 
58
58
  it 'draws row line' do
59
- expect(subject.row_line(row)).to eq <<-EOS.normalize
59
+ expect(subject.row_line(row)).to eq unindent(<<-EOS)
60
60
  a1 a2 a3
61
61
  b1
62
62
  c1
@@ -4,26 +4,26 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe TTY::Table::Border::Unicode, '#rendering' do
6
6
 
7
- subject { described_class.new(column_widths) }
7
+ subject(:border) { described_class.new(column_widths, [0,0,0,0]) }
8
8
 
9
9
  context 'with empty row' do
10
10
  let(:row) { TTY::Table::Row.new([]) }
11
11
  let(:column_widths) { [] }
12
12
 
13
13
  it 'draws top line' do
14
- expect(subject.top_line).to eq("┌┐")
14
+ expect(border.top_line).to eq("┌┐")
15
15
  end
16
16
 
17
17
  it 'draws middle line' do
18
- expect(subject.separator).to eq("├┤")
18
+ expect(border.separator).to eq("├┤")
19
19
  end
20
20
 
21
21
  it 'draw bottom line' do
22
- expect(subject.bottom_line).to eq("└┘")
22
+ expect(border.bottom_line).to eq("└┘")
23
23
  end
24
24
 
25
25
  it 'draws row line' do
26
- expect(subject.row_line(row)).to eq("││")
26
+ expect(border.row_line(row)).to eq("││")
27
27
  end
28
28
  end
29
29
 
@@ -32,19 +32,19 @@ RSpec.describe TTY::Table::Border::Unicode, '#rendering' do
32
32
  let(:column_widths) { [2,2,2] }
33
33
 
34
34
  it 'draws top line' do
35
- expect(subject.top_line).to eq("┌──┬──┬──┐")
35
+ expect(border.top_line).to eq("┌──┬──┬──┐")
36
36
  end
37
37
 
38
38
  it 'draw middle line' do
39
- expect(subject.separator).to eq("├──┼──┼──┤")
39
+ expect(border.separator).to eq("├──┼──┼──┤")
40
40
  end
41
41
 
42
42
  it 'draw bottom line' do
43
- expect(subject.bottom_line).to eq("└──┴──┴──┘")
43
+ expect(border.bottom_line).to eq("└──┴──┴──┘")
44
44
  end
45
45
 
46
46
  it 'draws row line' do
47
- expect(subject.row_line(row)).to eq("│a1│a2│a3│")
47
+ expect(border.row_line(row)).to eq("│a1│a2│a3│")
48
48
  end
49
49
  end
50
50
 
@@ -53,7 +53,7 @@ RSpec.describe TTY::Table::Border::Unicode, '#rendering' do
53
53
  let(:column_widths) { [2,2,2] }
54
54
 
55
55
  it 'draws row line' do
56
- expect(subject.row_line(row)).to eq <<-EOS.normalize
56
+ expect(border.row_line(row)).to eq unindent(<<-EOS)
57
57
  │a1│a2│a3│
58
58
  │b1│ │ │
59
59
  │c1│ │ │
@@ -2,20 +2,21 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe TTY::Table::Columns, '#enforce' do
5
+ RSpec.describe TTY::Table::ColumnConstraint, '#enforce' do
6
6
  let(:header) { ['h1', 'h2', 'h3', 'h4'] }
7
7
  let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
8
8
  let(:table) { TTY::Table.new(header, rows) }
9
- let(:object) { described_class.new(renderer) }
10
9
 
11
- subject { object.enforce }
10
+ subject(:columns) { described_class.new(table, renderer) }
12
11
 
13
12
  context 'with width contraint' do
14
13
  let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
15
14
  let(:options) { { width: 5 }}
16
15
 
17
16
  it 'raises error when table width is too small' do
18
- expect { subject }.to raise_error(TTY::Table::ResizeError)
17
+ expect {
18
+ columns.enforce
19
+ }.to raise_error(TTY::Table::ResizeError)
19
20
  end
20
21
  end
21
22
 
@@ -24,8 +25,9 @@ RSpec.describe TTY::Table::Columns, '#enforce' do
24
25
  let(:options) { { width: 11, resize: true }}
25
26
 
26
27
  it 'raises error when table width is too small' do
27
- expect(object).to receive(:expand)
28
- subject
28
+ allow(columns).to receive(:expand)
29
+ columns.enforce
30
+ expect(columns).to have_received(:expand)
29
31
  end
30
32
  end
31
33
 
@@ -36,8 +38,9 @@ RSpec.describe TTY::Table::Columns, '#enforce' do
36
38
  let(:options) { { width: 8, resize: true } }
37
39
 
38
40
  it 'calls shrink' do
39
- expect(object).to receive(:shrink)
40
- subject
41
+ allow(columns).to receive(:shrink)
42
+ columns.enforce
43
+ expect(columns).to have_received(:shrink)
41
44
  end
42
45
  end
43
46
 
@@ -47,10 +50,10 @@ RSpec.describe TTY::Table::Columns, '#enforce' do
47
50
  it 'changes table orientation to vertical' do
48
51
  allow(Kernel).to receive(:warn)
49
52
  expect(renderer.column_widths).to eql([2,2,2,2])
50
- expect(renderer.table.orientation.name).to eql(:horizontal)
51
- subject
52
- expect(renderer.column_widths).to eq([2,2])
53
- expect(renderer.table.orientation.name).to eql(:vertical)
53
+ expect(table.orientation.name).to eql(:horizontal)
54
+ column_widths = columns.enforce
55
+ expect(column_widths).to eq([2,2])
56
+ expect(table.orientation.name).to eql(:vertical)
54
57
  end
55
58
  end
56
59
  end
@@ -2,22 +2,22 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe TTY::Table::Columns, 'column widths' do
5
+ RSpec.describe TTY::Table::ColumnConstraint, 'column widths' do
6
6
  let(:header) { ['h1', 'h2', 'h3', 'h4'] }
7
7
  let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
8
8
  let(:table) { TTY::Table.new(header, rows) }
9
9
 
10
- subject { described_class.new(renderer) }
10
+ subject(:columns) { described_class.new(table, renderer) }
11
11
 
12
12
  context 'with basic renderer' do
13
13
  let(:renderer) { TTY::Table::Renderer::Basic.new(table) }
14
14
 
15
15
  it 'calculates columns natural width' do
16
- expect(subject.natural_width).to eq(11)
16
+ expect(columns.natural_width).to eq(11)
17
17
  end
18
18
 
19
19
  it 'calculates miminimum columns width' do
20
- expect(subject.minimum_width).to eq(7)
20
+ expect(columns.minimum_width).to eq(7)
21
21
  end
22
22
  end
23
23
 
@@ -25,11 +25,11 @@ RSpec.describe TTY::Table::Columns, 'column widths' do
25
25
  let(:renderer) { TTY::Table::Renderer::ASCII.new(table) }
26
26
 
27
27
  it 'calculates columns natural width' do
28
- expect(subject.natural_width).to eq(13)
28
+ expect(columns.natural_width).to eq(13)
29
29
  end
30
30
 
31
31
  it 'calculates miminimum columns width' do
32
- expect(subject.minimum_width).to eq(9)
32
+ expect(columns.minimum_width).to eq(9)
33
33
  end
34
34
  end
35
35
  end