command_line_reporter 2.1 → 3.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.
@@ -4,6 +4,14 @@ require 'nested_formatter'
4
4
  describe CommandLineReporter::NestedFormatter do
5
5
  subject { CommandLineReporter::NestedFormatter.instance }
6
6
 
7
+ before :all do
8
+ @controls = {
9
+ :clear => "\e[0m",
10
+ :bold => "\e[1m",
11
+ :red => "\e[31m",
12
+ }
13
+ end
14
+
7
15
  describe '#method default values' do
8
16
  its(:message_string) { should == 'working' }
9
17
  its(:complete_string) { should == 'complete' }
@@ -63,6 +71,20 @@ describe CommandLineReporter::NestedFormatter do
63
71
  subject.format({ }, lambda { })
64
72
  end
65
73
 
74
+ it 'performs a wrapped report with color' do
75
+ subject.should_receive(:puts).with("#{@controls[:red]}working#{@controls[:clear]}")
76
+ subject.should_receive(:puts).with("#{@controls[:red]}complete#{@controls[:clear]}")
77
+
78
+ subject.format({:color => 'red'}, lambda { })
79
+ end
80
+
81
+ it 'performs a wrapped report with color' do
82
+ subject.should_receive(:puts).with("#{@controls[:bold]}working#{@controls[:clear]}")
83
+ subject.should_receive(:puts).with("#{@controls[:bold]}complete#{@controls[:clear]}")
84
+
85
+ subject.format({:bold => true}, lambda { })
86
+ end
87
+
66
88
  it 'performs a wrapped report overriding the message' do
67
89
  subject.should_receive(:puts).with('test')
68
90
  subject.should_receive(:puts).with('complete')
@@ -138,14 +160,33 @@ describe CommandLineReporter::NestedFormatter do
138
160
  subject.should_receive(:puts).with(' complete')
139
161
  subject.should_receive(:puts).with('complete')
140
162
 
141
- nested = lambda {
142
- }
143
-
144
163
  subject.format({:message => 'test'}, lambda {
145
164
  subject.format({:message => 'test2'}, lambda {})
146
165
  })
147
166
  end
148
167
 
168
+ it 'indents the nested wrapped messages and outputs color' do
169
+ subject.should_receive(:puts).with("#{@controls[:red]}test#{@controls[:clear]}")
170
+ subject.should_receive(:puts).with("#{@controls[:red]} test2#{@controls[:clear]}")
171
+ subject.should_receive(:puts).with("#{@controls[:red]} complete#{@controls[:clear]}")
172
+ subject.should_receive(:puts).with("#{@controls[:red]}complete#{@controls[:clear]}")
173
+
174
+ subject.format({:message => 'test', :color => 'red'}, lambda {
175
+ subject.format({:message => 'test2', :color => 'red'}, lambda {})
176
+ })
177
+ end
178
+
179
+ it 'indents the nested wrapped messages and outputs bold' do
180
+ subject.should_receive(:puts).with("#{@controls[:bold]}test#{@controls[:clear]}")
181
+ subject.should_receive(:puts).with("#{@controls[:bold]} test2#{@controls[:clear]}")
182
+ subject.should_receive(:puts).with("#{@controls[:bold]} complete#{@controls[:clear]}")
183
+ subject.should_receive(:puts).with("#{@controls[:bold]}complete#{@controls[:clear]}")
184
+
185
+ subject.format({:message => 'test', :bold => true}, lambda {
186
+ subject.format({:message => 'test2', :bold => true}, lambda {})
187
+ })
188
+ end
189
+
149
190
  it 'indents the multiple nested wrapped messages' do
150
191
  subject.should_receive(:puts).with('test')
151
192
  subject.should_receive(:puts).with(' test2')
@@ -8,6 +8,14 @@ describe CommandLineReporter::ProgressFormatter do
8
8
  its(:indicator) { should == '.' }
9
9
  end
10
10
 
11
+ before :all do
12
+ @controls = {
13
+ :clear => "\e[0m",
14
+ :bold => "\e[1m",
15
+ :red => "\e[31m",
16
+ }
17
+ end
18
+
11
19
  describe '#format' do
12
20
  it 'displays dots for the indicator' do
13
21
  subject.should_receive(:print).exactly(10).times.with('.')
@@ -18,6 +26,24 @@ describe CommandLineReporter::ProgressFormatter do
18
26
  })
19
27
  end
20
28
 
29
+ it 'displays colored red dots for the indicator' do
30
+ subject.should_receive(:print).exactly(10).times.with("#{@controls[:red]}.#{@controls[:clear]}")
31
+ subject.should_receive(:puts).exactly(1).times
32
+
33
+ subject.format({:color => 'red'}, lambda {
34
+ 10.times {subject.progress}
35
+ })
36
+ end
37
+
38
+ it 'displays BOLD dots for the indicator' do
39
+ subject.should_receive(:print).exactly(10).times.with("#{@controls[:bold]}.#{@controls[:clear]}")
40
+ subject.should_receive(:puts).exactly(1).times
41
+
42
+ subject.format({:bold => true}, lambda {
43
+ 10.times {subject.progress}
44
+ })
45
+ end
46
+
21
47
  it 'uses the defined indicator' do
22
48
  subject.indicator = '+'
23
49
  subject.should_receive(:print).exactly(10).times.with('+')
data/spec/row_spec.rb CHANGED
@@ -1,32 +1,69 @@
1
1
  require 'spec_helper'
2
2
  require 'row'
3
3
 
4
- describe Row do
4
+ describe CommandLineReporter::Row do
5
5
  before :each do
6
- @cols = 10.times.map {|v| Column.new("test#{v}")}
6
+ @cols = 10.times.map {|v| CommandLineReporter::Column.new("test#{v}")}
7
+ end
8
+
9
+ describe '#initialize' do
10
+ it 'accepts header' do
11
+ CommandLineReporter::Row.new(:header => true).header.should be_true
12
+ end
13
+
14
+ it 'accepts color' do
15
+ CommandLineReporter::Row.new(:color => 'red').color.should == 'red'
16
+ end
17
+
18
+ it 'accepts bold' do
19
+ CommandLineReporter::Row.new(:bold => true).bold.should be_true
20
+ end
7
21
  end
8
22
 
9
23
  describe '#add' do
10
- subject { Row.new }
24
+ subject { CommandLineReporter::Row.new }
11
25
 
12
- it 'adds columns' do
26
+ it 'columns' do
13
27
  subject.add(@cols[0])
14
28
  subject.columns.size.should == 1
15
29
  subject.columns[0].should == @cols[0]
16
30
  subject.add(@cols[1])
17
31
  subject.columns.should == @cols[0,2]
18
32
  end
33
+
34
+ it 'defaults colors on columns' do
35
+ row = CommandLineReporter::Row.new(:color => 'red')
36
+ row.add(@cols[0])
37
+ row.columns[0].color.should == 'red'
38
+ row.add(@cols[1])
39
+ row.columns[1].color.should == 'red'
40
+ end
41
+
42
+ it 'allows columns to override the row color' do
43
+ col = CommandLineReporter::Column.new('test', :color => 'blue')
44
+ row = CommandLineReporter::Row.new(:color => 'red')
45
+ row.add(col)
46
+ row.columns[0].color.should == 'blue'
47
+ end
48
+
49
+ it 'supercedes bold on columns' do
50
+ row = CommandLineReporter::Row.new(:bold => true)
51
+ row.add(@cols[0])
52
+ row.columns[0].bold.should be_true
53
+ row.add(@cols[1])
54
+ row.columns[1].bold.should be_true
55
+ end
19
56
  end
20
57
 
21
58
  describe '#output' do
22
59
  before :each do
23
60
  @cols = [
24
- Column.new('asdf'),
25
- Column.new('qwer', :align => 'center'),
26
- Column.new('zxcv', :align => 'right'),
27
- Column.new('x' * 25, :align => 'left', :width => 10),
28
- Column.new('x' * 25, :align => 'center', :width => 10),
29
- Column.new('x' * 35, :align => 'left', :width => 10),
61
+ CommandLineReporter::Column.new('asdf'),
62
+ CommandLineReporter::Column.new('qwer', :align => 'center'),
63
+ CommandLineReporter::Column.new('zxcv', :align => 'right'),
64
+ CommandLineReporter::Column.new('x' * 25, :align => 'left', :width => 10),
65
+ CommandLineReporter::Column.new('x' * 25, :align => 'center', :width => 10),
66
+ CommandLineReporter::Column.new('x' * 35, :align => 'left', :width => 10),
30
67
  ]
31
68
  end
32
69
 
data/spec/table_spec.rb CHANGED
@@ -1,45 +1,99 @@
1
1
  require 'spec_helper'
2
2
  require 'table'
3
3
 
4
- describe Table do
4
+ describe CommandLineReporter::Table do
5
5
  context 'creation' do
6
6
  it 'defaults options hash' do
7
7
  expect {
8
- Table.new
8
+ CommandLineReporter::Table.new
9
9
  }.to_not raise_error
10
10
  end
11
11
 
12
12
  it 'defaults the border' do
13
- Table.new.border.should == false
13
+ CommandLineReporter::Table.new.border.should be_false
14
14
  end
15
15
 
16
16
  it 'accepts the border' do
17
- Table.new(:border => true).border.should == true
17
+ CommandLineReporter::Table.new(:border => true).border.should == true
18
18
  end
19
19
  end
20
20
 
21
21
  context 'rows' do
22
22
  it 'allows addition' do
23
- cols = [Column.new('test1'), Column.new('test2')]
24
- row = Row.new
23
+ cols = [CommandLineReporter::Column.new('test1'), CommandLineReporter::Column.new('test2')]
24
+ row = CommandLineReporter::Row.new
25
25
  cols.each {|c| row.add(c)}
26
26
  expect {
27
- Table.new.add(row)
27
+ CommandLineReporter::Table.new.add(row)
28
28
  }.to_not raise_error
29
29
  end
30
30
 
31
- it 'normalizes all column width and sizes' do
32
- cols = [Column.new('asdf', :width => 5), Column.new('qwer')]
33
- row = Row.new
34
- row.add(cols[0])
35
- t = Table.new
36
- t.add(row)
37
- row = Row.new
38
- row.add(cols[1])
39
- t.add(row)
40
- output = capture_stdout {
41
- t.output
42
- }
31
+ context 'inherits' do
32
+ before :each do
33
+ @table = CommandLineReporter::Table.new
34
+ row = CommandLineReporter::Row.new(:color => 'red')
35
+ (
36
+ @cols1 = [
37
+ CommandLineReporter::Column.new('asdf', :width => 5),
38
+ CommandLineReporter::Column.new('qwer', :align => 'right', :color => 'purple'),
39
+ CommandLineReporter::Column.new('tutu', :color => 'green'),
40
+ CommandLineReporter::Column.new('uiui', :bold => true),
41
+ ]
42
+ ).each {|c| row.add(c)}
43
+ @table.add(row)
44
+ row = CommandLineReporter::Row.new
45
+ (@cols2 = [
46
+ CommandLineReporter::Column.new('test'),
47
+ CommandLineReporter::Column.new('test'),
48
+ CommandLineReporter::Column.new('test', :color => 'blue'),
49
+ CommandLineReporter::Column.new('test'),
50
+ ]
51
+ ).each {|c| row.add(c)}
52
+ @table.add(row)
53
+ end
54
+
55
+ it 'positional attributes' do
56
+ [:align, :width, :size, :padding].each do |m|
57
+ 4.times do |i|
58
+ @table.rows[1].columns[i].send(m).should == @table.rows[0].columns[i].send(m)
59
+ end
60
+ end
61
+ end
62
+
63
+ context 'no header row' do
64
+ it 'color' do
65
+ @table.rows[1].columns[0].color.should == 'red'
66
+ @table.rows[1].columns[1].color.should == 'purple'
67
+ @table.rows[1].columns[2].color.should == 'blue'
68
+ @table.rows[1].columns[3].color.should == 'red'
69
+ end
70
+
71
+ it 'bold' do
72
+ @table.rows[1].columns[0].bold.should be_false
73
+ @table.rows[1].columns[1].bold.should be_false
74
+ @table.rows[1].columns[2].bold.should be_false
75
+ @table.rows[1].columns[3].bold.should be_true
76
+ end
77
+ end
78
+
79
+ context 'with header row' do
80
+ before :each do
81
+ @table = CommandLineReporter::Table.new
82
+ row = CommandLineReporter::Row.new(:header => true)
83
+ @cols1.each {|c| row.add(c)}
84
+ @table.add(row)
85
+ row = CommandLineReporter::Row.new
86
+ @cols2.each {|c| row.add(c)}
87
+ @table.add(row)
88
+ end
89
+
90
+ it 'bold' do
91
+ @table.rows[1].columns[0].bold.should be_false
92
+ @table.rows[1].columns[1].bold.should be_false
93
+ @table.rows[1].columns[2].bold.should be_false
94
+ @table.rows[1].columns[3].bold.should be_true
95
+ end
96
+ end
43
97
  end
44
98
  end
45
99
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: command_line_reporter
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: "2.1"
5
+ version: "3.0"
6
6
  platform: ruby
7
7
  authors:
8
8
  - Wes
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-01-29 00:00:00 Z
14
+ date: 2012-02-05 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -24,6 +24,17 @@ dependencies:
24
24
  type: :development
25
25
  prerelease: false
26
26
  version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: colored
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "1.2"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
27
38
  description: This gem makes it easy to provide a report while your ruby script is executing
28
39
  email: baywes@gmail.com
29
40
  executables: []
@@ -70,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
81
  requirements:
71
82
  - - ">="
72
83
  - !ruby/object:Gem::Version
73
- hash: -154884230452992637
84
+ hash: -3936770633859480563
74
85
  segments:
75
86
  - 0
76
87
  version: "0"