command_line_reporter 3.3.4 → 4.0.2

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.
@@ -4,71 +4,105 @@ module CommandLineReporter
4
4
  class Column
5
5
  include OptionsValidator
6
6
 
7
- VALID_OPTIONS = [:width, :padding, :align, :color, :bold, :underline, :reversed]
7
+ VALID_OPTIONS = %i[width padding align color bold underline reversed span wrap].freeze
8
8
  attr_accessor :text, :size, *VALID_OPTIONS
9
9
 
10
10
  def initialize(text = nil, options = {})
11
- self.validate_options(options, *VALID_OPTIONS)
11
+ validate_options(options, *VALID_OPTIONS)
12
+ assign_alignment_defaults(options)
13
+ assign_color_defaults(options)
12
14
 
13
15
  self.text = text.to_s
14
16
 
15
- self.width = options[:width] || 10
16
- self.align = options[:align] || 'left'
17
- self.padding = options[:padding] || 0
18
- self.color = options[:color] || nil
19
- self.bold = options[:bold] || false
20
- self.underline = options[:underline] || false
21
- self.reversed = options[:reversed] || false
22
-
23
- raise ArgumentError unless self.width > 0
24
- raise ArgumentError unless self.padding.to_s.match(/^\d+$/)
17
+ self.wrap = (options.fetch(:wrap, :character).to_s)
18
+ raise(ArgumentError, ":wrap must be word or character (got #{options[:wrap].inspect})") unless %w(word character).include?(self.wrap)
25
19
  end
26
20
 
27
21
  def size
28
- self.width - 2 * self.padding
22
+ width - (2 * padding) + (3 * (span - 1))
29
23
  end
30
24
 
31
25
  def required_width
32
- self.text.to_s.size + 2 * self.padding
26
+ text.to_s.size + 2 * padding
33
27
  end
34
28
 
35
29
  def screen_rows
36
- if self.text.nil? || self.text.empty?
37
- [' ' * self.width]
30
+ if text.nil? || text.empty?
31
+ [' ' * width]
38
32
  else
39
- self.text.scan(/.{1,#{self.size}}/m).map {|s| to_cell(s)}
33
+ reformat_wrapped(text).map { |line| to_cell(line) }
40
34
  end
41
35
  end
42
36
 
43
37
  private
44
38
 
39
+ def reformat_wrapped(text)
40
+ lines = []
41
+ text.lines.each do |line|
42
+ line_words = (wrap == 'word') ? line.split(/\s+/) : [line]
43
+ line_words.each do |word|
44
+ current_line = lines.last
45
+ if current_line.nil? || current_line.size + word.size >= size
46
+ # word does not fit on current line. Add new line(s) handling the case where current
47
+ # word is longer than line width.
48
+ lines.concat(word.scan(/.{1,#{size}}/))
49
+ else
50
+ # Word fits on current line.
51
+ (current_line << ' ' << word).strip!
52
+ end
53
+ end
54
+ lines << ''
55
+ end
56
+ lines[0..-2]
57
+ end
58
+
59
+ def assign_alignment_defaults(options)
60
+ self.span = options[:span] || 1
61
+
62
+ self.width = options[:width] || 10
63
+ self.width = Integer(width)
64
+ self.width *= span
65
+
66
+ self.align = options[:align] || 'left'
67
+
68
+ self.padding = options[:padding] || 0
69
+ self.padding = Integer(padding)
70
+ end
71
+
72
+ def assign_color_defaults(options)
73
+ self.color = options[:color] || nil
74
+ self.bold = options[:bold] || false
75
+ self.underline = options[:underline] || false
76
+ self.reversed = options[:reversed] || false
77
+ end
78
+
45
79
  def to_cell(str)
46
80
  # NOTE: For making underline and reversed work Change so that based on the
47
81
  # unformatted text it determines how much spacing to add left and right
48
82
  # then colorize the cell text
49
83
  cell = str.empty? ? blank_cell : aligned_cell(str)
50
- padding_str = ' ' * self.padding
84
+ padding_str = ' ' * padding
51
85
  padding_str + colorize(cell) + padding_str
52
86
  end
53
87
 
54
88
  def blank_cell
55
- ' ' * self.size
89
+ ' ' * size
56
90
  end
57
91
 
58
92
  def aligned_cell(str)
59
- case self.align
93
+ case align
60
94
  when 'left'
61
- str.ljust(self.size)
95
+ str.ljust(size)
62
96
  when 'right'
63
- str.rjust(self.size)
97
+ str.rjust(size)
64
98
  when 'center'
65
- str.ljust((self.size - str.size)/2.0 + str.size).rjust(self.size)
99
+ str.ljust((size - str.size) / 2.0 + str.size).rjust(size)
66
100
  end
67
101
  end
68
102
 
69
103
  def colorize(str)
70
- str = str.send(color) if self.color
71
- str = str.send('bold') if self.bold
104
+ str = str.send(color) if color
105
+ str = str.send('bold') if bold
72
106
  str
73
107
  end
74
108
  end
@@ -6,18 +6,18 @@ module CommandLineReporter
6
6
  include Singleton
7
7
  include OptionsValidator
8
8
 
9
- VALID_OPTIONS = [:message, :type, :complete, :indent_size, :color, :bold]
9
+ VALID_OPTIONS = %i[message type complete indent_size color bold].freeze
10
10
  attr_accessor :indent_size, :complete_string, :message_string, :color, :bold
11
11
 
12
12
  def format(options, block)
13
- self.validate_options(options, *VALID_OPTIONS)
13
+ validate_options(options, *VALID_OPTIONS)
14
14
 
15
15
  indent_level :incr
16
16
 
17
- padding = ' ' * @indent_level * (options[:indent_size] || self.indent_size)
17
+ padding = ' ' * @indent_level * (options[:indent_size] || indent_size)
18
18
 
19
- message_str = padding + (options[:message] || self.message_string)
20
- complete_str = options[:complete] || self.complete_string
19
+ message_str = padding + (options[:message] || message_string)
20
+ complete_str = options[:complete] || complete_string
21
21
 
22
22
  if options[:type] == 'inline'
23
23
  colorize("#{message_str}...", true, options)
@@ -51,17 +51,13 @@ module CommandLineReporter
51
51
  str = str.send(options[:color]) if options[:color]
52
52
  str = str.bold if options[:bold]
53
53
 
54
- if inline
55
- print str
56
- else
57
- puts str
58
- end
54
+ inline ? print(str) : puts(str)
59
55
  end
60
56
 
61
57
  def indent_level(value)
62
58
  case value
63
59
  when :incr
64
- @indent_level = (@indent_level) ? @indent_level + 1 : 0
60
+ @indent_level = @indent_level ? @indent_level + 1 : 0
65
61
  when :decr
66
62
  @indent_level -= 1
67
63
  end
@@ -6,11 +6,11 @@ module CommandLineReporter
6
6
  include Singleton
7
7
  include OptionsValidator
8
8
 
9
- VALID_OPTIONS = [:indicator, :color, :bold]
9
+ VALID_OPTIONS = %i[indicator color bold].freeze
10
10
  attr_accessor *VALID_OPTIONS
11
11
 
12
12
  def format(options, block)
13
- self.validate_options(options, *VALID_OPTIONS)
13
+ validate_options(options, *VALID_OPTIONS)
14
14
 
15
15
  self.indicator = options[:indicator] if options[:indicator]
16
16
  self.color = options[:color]
@@ -22,10 +22,10 @@ module CommandLineReporter
22
22
  end
23
23
 
24
24
  def progress(override = nil)
25
- str = override || self.indicator
25
+ str = override || indicator
26
26
 
27
- str = str.send(self.color) if self.color
28
- str = str.send('bold') if self.bold
27
+ str = str.send(color) if color
28
+ str = str.send('bold') if bold
29
29
 
30
30
  print str
31
31
  end
@@ -2,11 +2,11 @@ module CommandLineReporter
2
2
  class Row
3
3
  include OptionsValidator
4
4
 
5
- VALID_OPTIONS = [:header, :color, :bold, :encoding]
5
+ VALID_OPTIONS = %i[header color bold encoding].freeze
6
6
  attr_accessor :columns, :border, *VALID_OPTIONS
7
7
 
8
8
  def initialize(options = {})
9
- self.validate_options(options, *VALID_OPTIONS)
9
+ validate_options(options, *VALID_OPTIONS)
10
10
 
11
11
  self.columns = []
12
12
  self.border = false
@@ -17,29 +17,23 @@ module CommandLineReporter
17
17
  end
18
18
 
19
19
  def add(column)
20
- if column.color.nil? && self.color
21
- column.color = self.color
22
- end
23
-
24
- if self.bold || self.header
25
- column.bold = true
26
- end
27
-
28
- self.columns << column
20
+ column.color = color if column.color.nil? && color
21
+ column.bold = true if bold || header
22
+ columns << column
29
23
  end
30
24
 
31
25
  def output
32
26
  screen_count.times do |sr|
33
27
  border_char = use_utf8? ? "\u2503" : '|'
34
28
 
35
- line = (self.border) ? "#{border_char} " : ''
29
+ line = border ? "#{border_char} " : ''
36
30
 
37
- self.columns.size.times do |mc|
38
- col = self.columns[mc]
31
+ columns.size.times do |mc|
32
+ col = columns[mc]
39
33
  # Account for the fact that some columns will have more screen rows than their
40
34
  # counterparts in the row. An example being:
41
- # c1 = Column.new('x' * 50, :width => 10)
42
- # c2 = Column.new('x' * 20, :width => 10)
35
+ # c1 = Column.new('x' * 50, width: 10)
36
+ # c2 = Column.new('x' * 20, width: 10)
43
37
  #
44
38
  # c1.screen_rows.size == 5
45
39
  # c2.screen_rows.size == 2
@@ -58,12 +52,12 @@ module CommandLineReporter
58
52
  if col.screen_rows[sr].nil?
59
53
  line << ' ' * col.width << ' '
60
54
  else
61
- line << self.columns[mc].screen_rows[sr] << ' '
55
+ line << columns[mc].screen_rows[sr] << ' '
62
56
  end
63
57
 
64
- if self.border
58
+ if border
65
59
  line << border_char
66
- line << ' ' if mc < self.columns.size - 1
60
+ line << ' ' if mc < columns.size - 1
67
61
  end
68
62
  end
69
63
 
@@ -74,11 +68,11 @@ module CommandLineReporter
74
68
  private
75
69
 
76
70
  def screen_count
77
- @sc ||= self.columns.inject(0) {|max,column| column.screen_rows.size > max ? column.screen_rows.size : max}
71
+ @sc ||= columns.inject(0) { |a, e| e.screen_rows.size > a ? e.screen_rows.size : a }
78
72
  end
79
73
 
80
74
  def use_utf8?
81
- self.encoding == :unicode && "\u2501" != "u2501"
75
+ encoding == :unicode && "\u2501" != 'u2501'
82
76
  end
83
77
  end
84
78
  end
@@ -2,11 +2,11 @@ module CommandLineReporter
2
2
  class Table
3
3
  include OptionsValidator
4
4
 
5
- VALID_OPTIONS = [:border, :width, :encoding]
5
+ VALID_OPTIONS = %i[border width encoding].freeze
6
6
  attr_accessor :rows, *VALID_OPTIONS
7
7
 
8
8
  def initialize(options = {})
9
- self.validate_options(options, *VALID_OPTIONS)
9
+ validate_options(options, *VALID_OPTIONS)
10
10
 
11
11
  self.border = options[:border] || false
12
12
  self.width = options[:width] || false
@@ -14,41 +14,47 @@ module CommandLineReporter
14
14
 
15
15
  @rows = []
16
16
 
17
- raise ArgumentError, "Invalid encoding" unless [ :ascii, :unicode ].include? self.encoding
17
+ raise ArgumentError, 'Invalid encoding' unless %i[ascii unicode].include? encoding
18
18
  end
19
19
 
20
20
  def add(row)
21
21
  # Inheritance from the table
22
- row.border = self.border
22
+ row.border = border
23
23
 
24
24
  # Inherit properties from the appropriate row
25
- inherit_column_attrs(row) if self.rows[0]
25
+ inherit_column_attrs(row) if rows[0]
26
26
 
27
- self.rows << row
27
+ rows << row
28
28
  end
29
29
 
30
+ # rubocop:disable Metrics/AbcSize
31
+ # rubocop:disable Metrics/CyclomaticComplexity
32
+ # rubocop:disable Metrics/MethodLength
30
33
  def output
31
- return if self.rows.size == 0 # we got here with nothing to print to the screen
32
- auto_adjust_widths if self.width == :auto
34
+ return if rows.empty? # we got here with nothing to print to the screen
35
+ auto_adjust_widths if width == :auto
33
36
 
34
- puts separator('first') if self.border
35
- self.rows.each_with_index do |row, index|
37
+ puts separator('first') if border
38
+
39
+ rows.each_with_index do |row, index|
36
40
  row.output
37
- puts separator('middle') if self.border && (index != self.rows.size - 1)
41
+ puts separator('middle') if border && (index != rows.size - 1)
38
42
  end
39
- puts separator('last') if self.border
43
+
44
+ puts separator('last') if border
40
45
  end
41
46
 
47
+ # TODO: This doesn't appear to be used and if it is, it will not handle span appropriately
42
48
  def auto_adjust_widths
43
49
  column_widths = []
44
50
 
45
- self.rows.each do |row|
51
+ rows.each do |row|
46
52
  row.columns.each_with_index do |col, i|
47
- column_widths[i] = [ col.required_width, ( column_widths[i] || 0 ) ].max
53
+ column_widths[i] = [col.required_width, (column_widths[i] || 0)].max
48
54
  end
49
55
  end
50
56
 
51
- self.rows.each do |row|
57
+ rows.each do |row|
52
58
  row.columns.each_with_index do |col, i|
53
59
  col.width = column_widths[i]
54
60
  end
@@ -60,11 +66,11 @@ module CommandLineReporter
60
66
  def separator(type = 'middle')
61
67
  left, center, right, bar = use_utf8? ? utf8_separator(type) : ascii_separator
62
68
 
63
- left + self.rows[0].columns.map {|c| bar * (c.width + 2)}.join(center) + right
69
+ left + rows[0].columns.map { |c| bar * (c.width + 2) }.join(center) + right
64
70
  end
65
71
 
66
72
  def use_utf8?
67
- self.encoding == :unicode && "\u2501" != "u2501"
73
+ encoding == :unicode && "\u2501" != 'u2501'
68
74
  end
69
75
 
70
76
  def ascii_separator
@@ -89,7 +95,7 @@ module CommandLineReporter
89
95
  end
90
96
 
91
97
  def inherit_column_attrs(row)
92
- row.columns.each_with_index do |c,i|
98
+ row.columns.each_with_index do |c, i|
93
99
  use_positional_attrs(c, i)
94
100
  use_color(row, c, i)
95
101
  use_bold(row, c, i)
@@ -97,16 +103,22 @@ module CommandLineReporter
97
103
  end
98
104
 
99
105
  def use_positional_attrs(c, i)
100
- # The positional attributes are always required to inheret to make sure the table
106
+ return if c.span > 1
107
+
108
+ # The positional attributes are always required to inherit to make sure the table
101
109
  # displays properly
102
- %w{align padding width}.each do |attr|
103
- val = self.rows[0].columns[i].send(attr)
104
- c.send(attr + "=", val)
110
+ %w[align padding width].each do |attr|
111
+ val = rows[0].columns[i].send(attr)
112
+ c.send(attr + '=', val)
105
113
  end
114
+
115
+ # spanning columns overrides inheritance for width
116
+ # val = rows[0].columns[i].width
117
+ # c.width = val unless c.span > 1
106
118
  end
107
119
 
108
120
  def inherit_from
109
- self.rows[0].header ? 1 : 0
121
+ rows[0].header ? 1 : 0
110
122
  end
111
123
 
112
124
  def use_color(row, c, i)
@@ -115,7 +127,7 @@ module CommandLineReporter
115
127
  elsif row.color
116
128
  c.color = row.color
117
129
  elsif inherit_from != 1
118
- c.color = self.rows[inherit_from].columns[i].color
130
+ c.color = rows[inherit_from].columns[i].color
119
131
  end
120
132
  end
121
133
 
@@ -123,7 +135,7 @@ module CommandLineReporter
123
135
  if row.bold
124
136
  c.bold = row.bold
125
137
  elsif inherit_from != 1
126
- c.bold = self.rows[inherit_from].columns[i].bold
138
+ c.bold = rows[inherit_from].columns[i].bold
127
139
  end
128
140
  end
129
141
  end
@@ -1,3 +1,3 @@
1
1
  module CommandLineReporter
2
- VERSION = '3.3.4'
2
+ VERSION = '4.0.2'.freeze
3
3
  end
@@ -1,94 +1,163 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CommandLineReporter::Column do
4
- describe '#initialize' do
4
+ subject { CommandLineReporter::Column }
5
+
6
+ def screen_rows(args = {})
7
+ described_class.new(text, {width: 5}.merge(args)).screen_rows
8
+ end
9
+
10
+ context '#initialize' do
5
11
  it 'rejects invalid options' do
6
- expect {
7
- CommandLineReporter::Column.new('test', :asdf => '1234')
8
- }.to raise_error ArgumentError
12
+ expect do
13
+ subject.new('test', asdf: '1234')
14
+ end.to raise_error ArgumentError
9
15
  end
10
16
 
11
17
  it 'defaults options hash' do
12
- expect {
13
- CommandLineReporter::Column.new('test')
14
- }.to_not raise_error
18
+ expect do
19
+ subject.new('test')
20
+ end.to_not raise_error Exception
15
21
  end
16
22
 
17
23
  it 'defaults the width' do
18
- expect(CommandLineReporter::Column.new('test').width).to eq(10)
24
+ c = subject.new('test')
25
+ expect(c.width).to eq(10)
19
26
  end
20
27
 
21
28
  it 'accepts the width' do
22
- expect(CommandLineReporter::Column.new('test', :width => 50).width).to eq(50)
29
+ c = subject.new('test', width: 50)
30
+ expect(c.width).to eq(50)
23
31
  end
24
32
 
25
33
  it 'requires valid width' do
26
- expect {
27
- CommandLineReporter::Column.new('test', :width => 'asdf')
28
- }.to raise_error ArgumentError
34
+ expect do
35
+ subject.new('test', width: 'asdf')
36
+ end.to raise_error ArgumentError
29
37
  end
30
38
 
31
39
  it 'accepts text' do
32
- expect(CommandLineReporter::Column.new('asdf').text).to eq('asdf')
40
+ c = subject.new('asdf')
41
+ expect(c.text).to eq('asdf')
33
42
  end
34
43
 
35
44
  it 'accepts color' do
36
- expect(CommandLineReporter::Column.new('asdf', :color => 'red').color).to eq('red')
45
+ c = subject.new('asdf', color: 'red')
46
+ expect(c.color).to eq('red')
37
47
  end
38
48
 
39
49
  it 'accepts bold' do
40
- expect(CommandLineReporter::Column.new('asdf', :bold => true).bold).to be true
50
+ c = subject.new('asdf', bold: true)
51
+ expect(c.bold).to be true
41
52
  end
42
53
 
43
54
  it 'defaults the padding' do
44
- expect(CommandLineReporter::Column.new('test').padding).to eq(0)
55
+ c = subject.new('test')
56
+ expect(c.padding).to eq(0)
45
57
  end
46
58
 
47
59
  it 'accepts the padding' do
48
- expect(CommandLineReporter::Column.new('test', :padding => 5).padding).to eq(5)
60
+ c = subject.new('test', padding: 5)
61
+ expect(c.padding).to eq(5)
49
62
  end
50
63
 
51
64
  it 'requires valid width' do
52
- expect {
53
- CommandLineReporter::Column.new('test', :padding => 'asdf')
54
- }.to raise_error ArgumentError
65
+ expect do
66
+ subject.new('test', padding: 'asdf')
67
+ end.to raise_error ArgumentError
55
68
  end
56
69
  end
57
70
 
58
- describe '#size' do
59
- it 'is the width less twice the padding' do
60
- expect(CommandLineReporter::Column.new('test').size).to eq(10)
61
- expect(CommandLineReporter::Column.new('test', :width => 5).size).to eq(5)
62
- expect(CommandLineReporter::Column.new('test', :width => 5, :padding => 1).size).to eq(3)
71
+ context '#size' do
72
+ it 'should have default width' do
73
+ c = subject.new('test')
74
+ expect(c.size).to eq(10)
75
+ end
76
+
77
+ it 'should have custom width' do
78
+ c = subject.new('test', width: 5)
79
+ expect(c.size).to eq(5)
80
+ end
81
+
82
+ it 'should be reduced by the padding' do
83
+ c = subject.new('test', width: 5, padding: 1)
84
+ expect(c.size).to eq(3)
63
85
  end
64
86
  end
65
87
 
66
- describe '#required_width' do
88
+ context '#required_width' do
67
89
  it 'is the length of the text plus twice the padding' do
68
- expect(CommandLineReporter::Column.new('test').required_width).to eq(4)
69
- expect(CommandLineReporter::Column.new('test', :padding => 1).required_width).to eq(6)
70
- expect(CommandLineReporter::Column.new('test', :padding => 5).required_width).to eq(14)
90
+ c = subject.new('test')
91
+ expect(c.required_width).to eq(4)
92
+ end
93
+
94
+ it 'should be length of string plus twice default padding' do
95
+ c = subject.new('test', padding: 1)
96
+ expect(c.required_width).to eq(6)
97
+ end
98
+
99
+ it 'should be length of string plus twice custom padding' do
100
+ c = subject.new('test', padding: 5)
101
+ expect(c.required_width).to eq(14)
71
102
  end
72
103
  end
73
104
 
74
- describe '#screen_rows' do
105
+ context 'spanning columns' do
106
+ it 'should adjust width for 2 default columns' do
107
+ col = subject.new('test', span: 2)
108
+ expect(col.width).to eq(20)
109
+ expect(col.size).to eq(23)
110
+ end
111
+
112
+ it 'should adjust width for 2 custom sized columns' do
113
+ col = subject.new('test', width: 20, span: 2)
114
+ expect(col.width).to eq(40)
115
+ expect(col.size).to eq(43)
116
+ end
117
+
118
+ it 'should adjust width for 3 default columns' do
119
+ col = subject.new('test', span: 3)
120
+ expect(col.width).to eq(30)
121
+ expect(col.size).to eq(36)
122
+ end
123
+
124
+ it 'should adjust width for 3 custom sized columns' do
125
+ col = subject.new('test', width: 20, span: 3)
126
+ expect(col.width).to eq(60)
127
+ expect(col.size).to eq(66)
128
+ end
129
+
130
+ it 'should adjust width for 4 default columns' do
131
+ col = subject.new('test', span: 4)
132
+ expect(col.width).to eq(40)
133
+ expect(col.size).to eq(49)
134
+ end
135
+
136
+ it 'should adjust width for 2 custom sized columns' do
137
+ col = subject.new('test', width: 20, span: 4)
138
+ expect(col.width).to eq(80)
139
+ expect(col.size).to eq(89)
140
+ end
141
+ end
142
+
143
+ context '#screen_rows' do
75
144
  let :controls do
76
145
  {
77
- :clear => "\e[0m",
78
- :bold => "\e[1m",
79
- :red => "\e[31m",
146
+ clear: "\e[0m",
147
+ bold: "\e[1m",
148
+ red: "\e[31m"
80
149
  }
81
150
  end
82
151
 
83
152
  context 'no wrapping' do
84
153
  context 'no padding' do
85
154
  it 'gives a single row' do
86
- c = CommandLineReporter::Column.new('x' * 5)
155
+ c = subject.new('x' * 5)
87
156
  c.screen_rows.size == 1
88
157
  end
89
158
 
90
159
  it 'handles empty text' do
91
- c = CommandLineReporter::Column.new
160
+ c = subject.new
92
161
  expect(c.screen_rows[0]).to eq(' ' * 10)
93
162
  end
94
163
 
@@ -97,17 +166,17 @@ describe CommandLineReporter::Column do
97
166
  let(:filler) { ' ' * 10 }
98
167
 
99
168
  it 'plain text' do
100
- c = CommandLineReporter::Column.new(text, :width => 20)
169
+ c = subject.new(text, width: 20)
101
170
  expect(c.screen_rows[0]).to eq(text + filler)
102
171
  end
103
172
 
104
173
  it 'outputs red' do
105
- c = CommandLineReporter::Column.new(text, :align => 'left', :width => 20, :color => 'red')
174
+ c = subject.new(text, align: 'left', width: 20, color: 'red')
106
175
  expect(c.screen_rows[0]).to eq(controls[:red] + text + filler + controls[:clear])
107
176
  end
108
177
 
109
178
  it 'outputs bold' do
110
- c = CommandLineReporter::Column.new(text, :align => 'left', :width => 20, :bold => true)
179
+ c = subject.new(text, align: 'left', width: 20, bold: true)
111
180
  expect(c.screen_rows[0]).to eq(controls[:bold] + text + filler + controls[:clear])
112
181
  end
113
182
  end
@@ -117,17 +186,17 @@ describe CommandLineReporter::Column do
117
186
  let(:filler) { ' ' * 10 }
118
187
 
119
188
  it 'plain text' do
120
- c = CommandLineReporter::Column.new(text, :align => 'right', :width => 20)
189
+ c = subject.new(text, align: 'right', width: 20)
121
190
  expect(c.screen_rows[0]).to eq(filler + text)
122
191
  end
123
192
 
124
193
  it 'outputs red' do
125
- c = CommandLineReporter::Column.new(text, :align => 'right', :width => 20, :color => 'red')
126
- expect(c.screen_rows[0]).to eq(controls[:red] + filler + text + controls[:clear])
194
+ c = subject.new(text, align: 'right', width: 20, color: 'red')
195
+ expect(c.screen_rows[0]).to eq(controls[:red] + filler + text + controls[:clear])
127
196
  end
128
197
 
129
198
  it 'outputs bold' do
130
- c = CommandLineReporter::Column.new(text, :align => 'right', :width => 20, :bold => true)
199
+ c = subject.new(text, align: 'right', width: 20, bold: true)
131
200
  expect(c.screen_rows[0]).to eq(controls[:bold] + filler + text + controls[:clear])
132
201
  end
133
202
  end
@@ -137,17 +206,17 @@ describe CommandLineReporter::Column do
137
206
  let(:filler) { ' ' * 5 }
138
207
 
139
208
  it 'plain text' do
140
- c = CommandLineReporter::Column.new(text, :align => 'center', :width => 20)
209
+ c = subject.new(text, align: 'center', width: 20)
141
210
  expect(c.screen_rows[0]).to eq(filler + text + filler)
142
211
  end
143
212
 
144
213
  it 'outputs red' do
145
- c = CommandLineReporter::Column.new(text, :align => 'center', :width => 20, :color => 'red')
214
+ c = subject.new(text, align: 'center', width: 20, color: 'red')
146
215
  expect(c.screen_rows[0]).to eq(controls[:red] + filler + text + filler + controls[:clear])
147
216
  end
148
217
 
149
218
  it 'outputs bold' do
150
- c = CommandLineReporter::Column.new(text, :align => 'center', :width => 20, :bold => true)
219
+ c = subject.new(text, align: 'center', width: 20, bold: true)
151
220
  expect(c.screen_rows[0]).to eq(controls[:bold] + filler + text + filler + controls[:clear])
152
221
  end
153
222
  end
@@ -160,17 +229,17 @@ describe CommandLineReporter::Column do
160
229
  let(:filler) { ' ' * 10 }
161
230
 
162
231
  it 'plain text' do
163
- c = CommandLineReporter::Column.new(text, :padding => 5, :width => 30)
232
+ c = subject.new(text, padding: 5, width: 30)
164
233
  expect(c.screen_rows[0]).to eq(padding + text + filler + padding)
165
234
  end
166
235
 
167
236
  it 'outputs red' do
168
- c = CommandLineReporter::Column.new(text, :padding => 5, :width => 30, :color => 'red')
237
+ c = subject.new(text, padding: 5, width: 30, color: 'red')
169
238
  expect(c.screen_rows[0]).to eq(padding + controls[:red] + text + filler + controls[:clear] + padding)
170
239
  end
171
240
 
172
241
  it 'outputs bold' do
173
- c = CommandLineReporter::Column.new(text, :padding => 5, :width => 30, :bold => true)
242
+ c = subject.new(text, padding: 5, width: 30, bold: true)
174
243
  expect(c.screen_rows[0]).to eq(padding + controls[:bold] + text + filler + controls[:clear] + padding)
175
244
  end
176
245
  end
@@ -181,17 +250,17 @@ describe CommandLineReporter::Column do
181
250
  let(:filler) { ' ' * 10 }
182
251
 
183
252
  it 'plain text' do
184
- c = CommandLineReporter::Column.new(text, :align => 'right', :padding => 5, :width => 30)
253
+ c = subject.new(text, align: 'right', padding: 5, width: 30)
185
254
  expect(c.screen_rows[0]).to eq(padding + filler + text + padding)
186
255
  end
187
256
 
188
257
  it 'outputs red' do
189
- c = CommandLineReporter::Column.new(text, :align => 'right', :padding => 5, :width => 30, :color => 'red')
258
+ c = subject.new(text, align: 'right', padding: 5, width: 30, color: 'red')
190
259
  expect(c.screen_rows[0]).to eq(padding + controls[:red] + filler + text + controls[:clear] + padding)
191
260
  end
192
261
 
193
262
  it 'outputs bold' do
194
- c = CommandLineReporter::Column.new(text, :align => 'right', :padding => 5, :width => 30, :bold => true)
263
+ c = subject.new(text, align: 'right', padding: 5, width: 30, bold: true)
195
264
  expect(c.screen_rows[0]).to eq(padding + controls[:bold] + filler + text + controls[:clear] + padding)
196
265
  end
197
266
  end
@@ -202,17 +271,17 @@ describe CommandLineReporter::Column do
202
271
  let(:filler) { ' ' * 5 }
203
272
 
204
273
  it 'plain text' do
205
- c = CommandLineReporter::Column.new(text, :align => 'center', :padding => 5, :width => 30)
274
+ c = subject.new(text, align: 'center', padding: 5, width: 30)
206
275
  expect(c.screen_rows[0]).to eq(padding + filler + text + filler + padding)
207
276
  end
208
277
 
209
278
  it 'outputs red' do
210
- c = CommandLineReporter::Column.new(text, :align => 'center', :padding => 5, :width => 30, :color => 'red')
279
+ c = subject.new(text, align: 'center', padding: 5, width: 30, color: 'red')
211
280
  expect(c.screen_rows[0]).to eq(padding + controls[:red] + filler + text + filler + controls[:clear] + padding)
212
281
  end
213
282
 
214
283
  it 'outputs bold' do
215
- c = CommandLineReporter::Column.new(text, :align => 'center', :padding => 5, :width => 30, :bold => true)
284
+ c = subject.new(text, align: 'center', padding: 5, width: 30, bold: true)
216
285
  expect(c.screen_rows[0]).to eq(padding + controls[:bold] + filler + text + filler + controls[:clear] + padding)
217
286
  end
218
287
  end
@@ -222,32 +291,42 @@ describe CommandLineReporter::Column do
222
291
  context 'with wrapping' do
223
292
  context 'no padding' do
224
293
  context 'left justifies' do
225
- let(:text) { 'x' * 25 }
226
- let(:full_line) { 'x' * 10 }
227
- let(:remainder) { 'x' * 5 }
228
- let(:filler) { ' ' * 5 }
294
+ let(:text) { "one cooperative\n\nbag copy" }
229
295
 
230
- it 'plain text' do
231
- c = CommandLineReporter::Column.new(text, :width => 10)
232
- expect(c.screen_rows).to eq([full_line, full_line, remainder + filler])
296
+ describe 'line-breaks' do
297
+ it 'do not break output' do
298
+ expect(screen_rows(width: 20)).to eq(['one cooperative ', ' ' * 20, 'bag copy '])
299
+ end
233
300
  end
234
301
 
235
- it 'outputs red' do
236
- c = CommandLineReporter::Column.new(text, :width => 10, :color => 'red')
237
- expect(c.screen_rows).to eq([
238
- controls[:red] + full_line + controls[:clear],
239
- controls[:red] + full_line + controls[:clear],
240
- controls[:red] + remainder + filler + controls[:clear],
241
- ])
302
+ describe 'wrap: word' do
303
+ it 'tries to break lines between words' do
304
+ expect(screen_rows(wrap: :word)).to eq(['one ', 'coope', 'rativ', 'e ', ' ', 'bag ', 'copy '])
305
+ end
306
+ end
307
+
308
+ describe 'wrap: character' do
309
+ it 'uses "character"-based wrapping by default' do
310
+ expect(screen_rows).to eq(screen_rows(wrap: :character))
311
+ end
312
+
313
+ it 'ignores word-breaks' do
314
+ expect(screen_rows).to eq(['one c', 'ooper', 'ative', ' ', ' ', 'bag c', 'opy '])
315
+ end
316
+ end
317
+
318
+ it 'outputs color' do
319
+ screen_rows(color: 'red').each do |row|
320
+ expect(row).to start_with(controls[:red])
321
+ expect(row).to end_with(controls[:clear])
322
+ end
242
323
  end
243
324
 
244
325
  it 'outputs bold' do
245
- c = CommandLineReporter::Column.new(text, :width => 10, :bold => true)
246
- expect(c.screen_rows).to eq([
247
- controls[:bold] + full_line + controls[:clear],
248
- controls[:bold] + full_line + controls[:clear],
249
- controls[:bold] + remainder + filler + controls[:clear],
250
- ])
326
+ screen_rows(bold: true).each do |row|
327
+ expect(row).to start_with(controls[:bold])
328
+ expect(row).to end_with(controls[:clear])
329
+ end
251
330
  end
252
331
  end
253
332
 
@@ -258,26 +337,30 @@ describe CommandLineReporter::Column do
258
337
  let(:filler) { ' ' * 5 }
259
338
 
260
339
  it 'plain text' do
261
- c = CommandLineReporter::Column.new(text, :align => 'right', :width => 10)
340
+ c = subject.new(text, align: 'right', width: 10)
262
341
  expect(c.screen_rows).to eq([full_line, full_line, filler + remainder])
263
342
  end
264
343
 
265
344
  it 'outputs red' do
266
- c = CommandLineReporter::Column.new(text, :align => 'right', :width => 10, :color => 'red')
267
- expect(c.screen_rows).to eq([
268
- controls[:red] + full_line + controls[:clear],
269
- controls[:red] + full_line + controls[:clear],
270
- controls[:red] + filler + remainder + controls[:clear],
271
- ])
345
+ c = subject.new(text, align: 'right', width: 10, color: 'red')
346
+ expect(c.screen_rows).to eq(
347
+ [
348
+ controls[:red] + full_line + controls[:clear],
349
+ controls[:red] + full_line + controls[:clear],
350
+ controls[:red] + filler + remainder + controls[:clear]
351
+ ]
352
+ )
272
353
  end
273
354
 
274
355
  it 'outputs bold' do
275
- c = CommandLineReporter::Column.new(text, :align => 'right', :width => 10, :bold => true)
276
- expect(c.screen_rows).to eq([
277
- controls[:bold] + full_line + controls[:clear],
278
- controls[:bold] + full_line + controls[:clear],
279
- controls[:bold] + filler + remainder + controls[:clear],
280
- ])
356
+ c = subject.new(text, align: 'right', width: 10, bold: true)
357
+ expect(c.screen_rows).to eq(
358
+ [
359
+ controls[:bold] + full_line + controls[:clear],
360
+ controls[:bold] + full_line + controls[:clear],
361
+ controls[:bold] + filler + remainder + controls[:clear]
362
+ ]
363
+ )
281
364
  end
282
365
  end
283
366
 
@@ -289,26 +372,30 @@ describe CommandLineReporter::Column do
289
372
  let(:right_filler) { ' ' * 2 }
290
373
 
291
374
  it 'plain text' do
292
- c = CommandLineReporter::Column.new(text, :align => 'center', :width => 10)
375
+ c = subject.new(text, align: 'center', width: 10)
293
376
  expect(c.screen_rows).to eq([full_line, full_line, ' ' * 3 + remainder + right_filler])
294
377
  end
295
378
 
296
379
  it 'outputs red' do
297
- c = CommandLineReporter::Column.new(text, :align => 'center', :width => 10, :color => 'red')
298
- expect(c.screen_rows).to eq([
299
- controls[:red] + full_line + controls[:clear],
300
- controls[:red] + full_line + controls[:clear],
301
- controls[:red] + left_filler + remainder + right_filler + controls[:clear],
302
- ])
380
+ c = subject.new(text, align: 'center', width: 10, color: 'red')
381
+ expect(c.screen_rows).to eq(
382
+ [
383
+ controls[:red] + full_line + controls[:clear],
384
+ controls[:red] + full_line + controls[:clear],
385
+ controls[:red] + left_filler + remainder + right_filler + controls[:clear]
386
+ ]
387
+ )
303
388
  end
304
389
 
305
390
  it 'outputs bold' do
306
- c = CommandLineReporter::Column.new(text, :align => 'center', :width => 10, :bold => true)
307
- expect(c.screen_rows).to eq([
308
- controls[:bold] + full_line + controls[:clear],
309
- controls[:bold] + full_line + controls[:clear],
310
- controls[:bold] + left_filler + remainder + right_filler + controls[:clear],
311
- ])
391
+ c = subject.new(text, align: 'center', width: 10, bold: true)
392
+ expect(c.screen_rows).to eq(
393
+ [
394
+ controls[:bold] + full_line + controls[:clear],
395
+ controls[:bold] + full_line + controls[:clear],
396
+ controls[:bold] + left_filler + remainder + right_filler + controls[:clear]
397
+ ]
398
+ )
312
399
  end
313
400
  end
314
401
  end
@@ -322,27 +409,33 @@ describe CommandLineReporter::Column do
322
409
  let(:filler) { ' ' * 7 }
323
410
 
324
411
  it 'plain text' do
325
- c = CommandLineReporter::Column.new(text, :padding => 2, :width => 20)
326
- expect(c.screen_rows).to eq([
327
- padding + full_line + padding,
328
- padding + remainder + filler + padding,
329
- ])
412
+ c = subject.new(text, padding: 2, width: 20)
413
+ expect(c.screen_rows).to eq(
414
+ [
415
+ padding + full_line + padding,
416
+ padding + remainder + filler + padding
417
+ ]
418
+ )
330
419
  end
331
420
 
332
421
  it 'outputs red' do
333
- c = CommandLineReporter::Column.new(text, :padding => 2, :width => 20, :color => 'red')
334
- expect(c.screen_rows).to eq([
335
- padding + controls[:red] + full_line + controls[:clear] + padding,
336
- padding + controls[:red] + remainder + filler + controls[:clear] + padding,
337
- ])
422
+ c = subject.new(text, padding: 2, width: 20, color: 'red')
423
+ expect(c.screen_rows).to eq(
424
+ [
425
+ padding + controls[:red] + full_line + controls[:clear] + padding,
426
+ padding + controls[:red] + remainder + filler + controls[:clear] + padding
427
+ ]
428
+ )
338
429
  end
339
430
 
340
431
  it 'outputs bold' do
341
- c = CommandLineReporter::Column.new(text, :padding => 2, :width => 20, :bold => true)
342
- expect(c.screen_rows).to eq([
343
- padding + controls[:bold] + full_line + controls[:clear] + padding,
344
- padding + controls[:bold] + remainder + filler + controls[:clear] + padding,
345
- ])
432
+ c = subject.new(text, padding: 2, width: 20, bold: true)
433
+ expect(c.screen_rows).to eq(
434
+ [
435
+ padding + controls[:bold] + full_line + controls[:clear] + padding,
436
+ padding + controls[:bold] + remainder + filler + controls[:clear] + padding
437
+ ]
438
+ )
346
439
  end
347
440
  end
348
441
 
@@ -354,27 +447,33 @@ describe CommandLineReporter::Column do
354
447
  let(:filler) { ' ' * 7 }
355
448
 
356
449
  it 'plain text' do
357
- c = CommandLineReporter::Column.new(text, :padding => 2, :align => 'right', :width => 20)
358
- expect(c.screen_rows).to eq([
359
- padding + full_line + padding,
360
- padding + filler + remainder + padding,
361
- ])
450
+ c = subject.new(text, padding: 2, align: 'right', width: 20)
451
+ expect(c.screen_rows).to eq(
452
+ [
453
+ padding + full_line + padding,
454
+ padding + filler + remainder + padding
455
+ ]
456
+ )
362
457
  end
363
458
 
364
459
  it 'outputs red' do
365
- c = CommandLineReporter::Column.new(text, :align => 'right', :padding => 2, :width => 20, :color => 'red')
366
- expect(c.screen_rows).to eq([
367
- padding + controls[:red] + full_line + controls[:clear] + padding,
368
- padding + controls[:red] + filler + remainder + controls[:clear] + padding,
369
- ])
460
+ c = subject.new(text, align: 'right', padding: 2, width: 20, color: 'red')
461
+ expect(c.screen_rows).to eq(
462
+ [
463
+ padding + controls[:red] + full_line + controls[:clear] + padding,
464
+ padding + controls[:red] + filler + remainder + controls[:clear] + padding
465
+ ]
466
+ )
370
467
  end
371
468
 
372
469
  it 'outputs bold' do
373
- c = CommandLineReporter::Column.new(text, :align => 'right', :padding => 2, :width => 20, :bold => true)
374
- expect(c.screen_rows).to eq([
375
- padding + controls[:bold] + full_line + controls[:clear] + padding,
376
- padding + controls[:bold] + filler + remainder + controls[:clear] + padding,
377
- ])
470
+ c = subject.new(text, align: 'right', padding: 2, width: 20, bold: true)
471
+ expect(c.screen_rows).to eq(
472
+ [
473
+ padding + controls[:bold] + full_line + controls[:clear] + padding,
474
+ padding + controls[:bold] + filler + remainder + controls[:clear] + padding
475
+ ]
476
+ )
378
477
  end
379
478
  end
380
479
 
@@ -387,27 +486,33 @@ describe CommandLineReporter::Column do
387
486
  let(:right_filler) { ' ' * 3 }
388
487
 
389
488
  it 'plain text' do
390
- c = CommandLineReporter::Column.new(text, :padding => 2, :align => 'center', :width => 20)
391
- expect(c.screen_rows).to eq([
392
- padding + full_line + padding,
393
- padding + left_filler + remainder + right_filler + padding,
394
- ])
489
+ c = subject.new(text, padding: 2, align: 'center', width: 20)
490
+ expect(c.screen_rows).to eq(
491
+ [
492
+ padding + full_line + padding,
493
+ padding + left_filler + remainder + right_filler + padding
494
+ ]
495
+ )
395
496
  end
396
497
 
397
498
  it 'outputs red' do
398
- c = CommandLineReporter::Column.new(text, :padding => 2, :align => 'center', :width => 20, :color => 'red')
399
- expect(c.screen_rows).to eq([
400
- padding + controls[:red] + full_line + controls[:clear] + padding,
401
- padding + controls[:red] + left_filler + remainder + right_filler + controls[:clear] + padding,
402
- ])
499
+ c = subject.new(text, padding: 2, align: 'center', width: 20, color: 'red')
500
+ expect(c.screen_rows).to eq(
501
+ [
502
+ padding + controls[:red] + full_line + controls[:clear] + padding,
503
+ padding + controls[:red] + left_filler + remainder + right_filler + controls[:clear] + padding
504
+ ]
505
+ )
403
506
  end
404
507
 
405
508
  it 'outputs bold' do
406
- c = CommandLineReporter::Column.new(text, :padding => 2, :align => 'center', :width => 20, :bold => true)
407
- expect(c.screen_rows).to eq([
408
- padding + controls[:bold] + full_line + controls[:clear] + padding,
409
- padding + controls[:bold] + left_filler + remainder + right_filler + controls[:clear] + padding,
410
- ])
509
+ c = subject.new(text, padding: 2, align: 'center', width: 20, bold: true)
510
+ expect(c.screen_rows).to eq(
511
+ [
512
+ padding + controls[:bold] + full_line + controls[:clear] + padding,
513
+ padding + controls[:bold] + left_filler + remainder + right_filler + controls[:clear] + padding
514
+ ]
515
+ )
411
516
  end
412
517
  end
413
518
  end