iterm2_tab_formatter 0.7.3 → 0.8.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.
- data/README.md +12 -1
- data/lib/iterm2_tab_formatter.rb +25 -10
- data/lib/iterm2_tab_formatter/{auto.rb → autoload.rb} +1 -1
- data/lib/iterm2_tab_formatter/color_parse.rb +14 -0
- data/lib/iterm2_tab_formatter/rspec_configuration.rb +7 -0
- data/lib/iterm2_tab_formatter/text_formatter.rb +38 -23
- data/lib/iterm2_tab_formatter/version.rb +1 -1
- data/sandbox/slow_spec.rb +1 -1
- data/spec/color_parse_spec.rb +24 -0
- data/spec/iterm2_tab_formatter_spec.rb +25 -15
- data/spec/text_formatter_spec.rb +14 -6
- metadata +9 -5
data/README.md
CHANGED
@@ -38,10 +38,21 @@ Or install it yourself as:
|
|
38
38
|
|
39
39
|
Just add the following line to your spec_helper.rb file:
|
40
40
|
|
41
|
-
require 'iterm2_tab_formatter/
|
41
|
+
require 'iterm2_tab_formatter/autoload'
|
42
42
|
|
43
43
|
And then your iTerm2 tabs will participate in testing too!
|
44
44
|
|
45
|
+
If you want to customize your colors:
|
46
|
+
|
47
|
+
RSpec.configure do |c|
|
48
|
+
# ugly monochrome
|
49
|
+
c.it2tf_neutral = '#7F7F7F' # gray
|
50
|
+
c.it2tf_pass = '#FFFFFF' # white
|
51
|
+
c.it2tf_fail = '#000000' # black
|
52
|
+
end
|
53
|
+
|
54
|
+
require 'iterm2_tab_formatter/autoload' # must be after configuration
|
55
|
+
|
45
56
|
## Contributing
|
46
57
|
|
47
58
|
1. Fork it
|
data/lib/iterm2_tab_formatter.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'iterm2_tab_formatter/base'
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require 'iterm2_tab_formatter/version'
|
3
|
+
require 'iterm2_tab_formatter/controller'
|
4
|
+
require 'iterm2_tab_formatter/text_formatter'
|
5
|
+
require 'iterm2_tab_formatter/color_parse'
|
6
|
+
require 'iterm2_tab_formatter/rspec_configuration'
|
5
7
|
|
6
8
|
class Iterm2TabFormatter
|
7
9
|
attr_reader :controller
|
@@ -9,9 +11,9 @@ class Iterm2TabFormatter
|
|
9
11
|
def initialize(output)
|
10
12
|
super
|
11
13
|
colors = {
|
12
|
-
suite_start:
|
13
|
-
spec_fail:
|
14
|
-
suite_pass:
|
14
|
+
suite_start: color(:it2tf_neutral),
|
15
|
+
spec_fail: color(:it2tf_fail),
|
16
|
+
suite_pass: color(:it2tf_pass)
|
15
17
|
}
|
16
18
|
@controller = Iterm2TabFormatter::Controller.new(colors)
|
17
19
|
end
|
@@ -39,13 +41,26 @@ class Iterm2TabFormatter
|
|
39
41
|
pass_ratio = 1 - (1.0 * failure_count / example_count)
|
40
42
|
controller.tab_title = "#{pass_ratio * 100}% passed"
|
41
43
|
|
42
|
-
|
44
|
+
formatter = Iterm2TabFormatter::TextFormatter.new(
|
45
|
+
duration_seconds: duration,
|
46
|
+
example_count: example_count,
|
47
|
+
failure_count: failure_count,
|
48
|
+
pending_count: pending_count,
|
49
|
+
finish_time: Time.now
|
50
|
+
)
|
51
|
+
|
52
|
+
window_title = formatter.status
|
43
53
|
window_title << ' - '
|
44
|
-
window_title <<
|
54
|
+
window_title << formatter.window_title
|
45
55
|
window_title << ' - '
|
46
|
-
window_title <<
|
56
|
+
window_title << formatter.duration
|
47
57
|
window_title << ' - Finished at '
|
48
|
-
window_title <<
|
58
|
+
window_title << formatter.finished_at
|
49
59
|
controller.window_title = window_title
|
50
60
|
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def color(name)
|
64
|
+
Iterm2TabFormatter::color_parse(RSpec.configuration.__send__(name))
|
65
|
+
end
|
51
66
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'iterm2_tab_formatter/base'
|
2
|
+
|
3
|
+
class Iterm2TabFormatter
|
4
|
+
class << self
|
5
|
+
def color_parse(code)
|
6
|
+
regex = /\A#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})\z/i
|
7
|
+
raise ArgumentError, "Invalid format: #{code}. Use #RRGGBB" unless code.match(regex)
|
8
|
+
|
9
|
+
code.scan(regex) do |red, green, blue|
|
10
|
+
return [red.to_i(16), green.to_i(16), blue.to_i(16)]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -2,37 +2,52 @@ require 'iterm2_tab_formatter/base'
|
|
2
2
|
require 'time'
|
3
3
|
|
4
4
|
class Iterm2TabFormatter
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
window_title << 's' unless example_count == 1
|
5
|
+
class TextFormatter
|
6
|
+
def initialize(options)
|
7
|
+
@options = options.dup
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
def window_title
|
11
|
+
window_title = "#{example_count} example"
|
12
|
+
window_title << 's' unless example_count == 1
|
13
13
|
|
14
|
-
|
14
|
+
window_title << ", #{failure_count} failure" if failure_count > 0
|
15
|
+
window_title << 's' if failure_count > 1
|
15
16
|
|
16
|
-
|
17
|
-
end
|
17
|
+
window_title << ", #{pending_count} pending" if pending_count > 0
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
window_title
|
20
|
+
end
|
21
|
+
|
22
|
+
def finished_at
|
23
|
+
finish_time.iso8601
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
def duration
|
27
|
+
text_minutes = (duration_seconds / 60).to_i
|
28
|
+
text_seconds = (duration_seconds % 60)
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
text = ''
|
31
|
+
text << "#{text_minutes}m" if text_minutes > 0
|
32
|
+
text << ("%.1fs" % text_seconds)
|
30
33
|
|
31
|
-
|
32
|
-
|
34
|
+
text
|
35
|
+
end
|
36
|
+
|
37
|
+
def status
|
38
|
+
failure_count == 0 ? 'PASS' : 'FAIL'
|
39
|
+
end
|
33
40
|
|
34
|
-
|
35
|
-
|
41
|
+
private
|
42
|
+
%w(
|
43
|
+
example_count
|
44
|
+
failure_count
|
45
|
+
pending_count
|
46
|
+
finish_time
|
47
|
+
duration_seconds
|
48
|
+
).map(&:to_sym).each do |attr|
|
49
|
+
define_method(attr) do
|
50
|
+
@options.fetch(attr)
|
36
51
|
end
|
37
52
|
end
|
38
53
|
end
|
data/sandbox/slow_spec.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'iterm2_tab_formatter/color_parse'
|
3
|
+
|
4
|
+
describe Iterm2TabFormatter do
|
5
|
+
describe '.color_parse' do
|
6
|
+
({
|
7
|
+
'#000000' => [0, 0, 0],
|
8
|
+
'#FF0000' => [255, 0, 0],
|
9
|
+
'#00FF00' => [0, 255, 0],
|
10
|
+
'#0000FF' => [0, 0, 255],
|
11
|
+
'#123456' => [0x12, 0x34, 0x56],
|
12
|
+
}).each do |code, values|
|
13
|
+
it "correctly parses #{code}" do
|
14
|
+
expect(Iterm2TabFormatter.color_parse(code)).to eq(values)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'raises on invalid code' do
|
19
|
+
expect {
|
20
|
+
Iterm2TabFormatter.color_parse('whatever')
|
21
|
+
}.to raise_error(/RRGGBB/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -21,6 +21,16 @@ describe Iterm2TabFormatter do
|
|
21
21
|
formatter.example_failed(double)
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'sets the window title to the description of a spec' do
|
25
|
+
example = double("example", description: 'an example description')
|
26
|
+
|
27
|
+
controller.should_receive(:window_title=).with('an example description')
|
28
|
+
controller.should_receive(:tab_title=).with('0/100')
|
29
|
+
|
30
|
+
formatter.stub(example_count: 100)
|
31
|
+
formatter.example_started(example)
|
32
|
+
end
|
33
|
+
|
24
34
|
describe 'at the end of the suite' do
|
25
35
|
before do
|
26
36
|
controller.stub(:apply_pass_color)
|
@@ -56,25 +66,25 @@ describe Iterm2TabFormatter do
|
|
56
66
|
end
|
57
67
|
|
58
68
|
it 'sets the window title through TextFormatter' do
|
59
|
-
Time.
|
60
|
-
|
61
|
-
Iterm2TabFormatter::TextFormatter.should_receive(:
|
62
|
-
|
63
|
-
|
69
|
+
now = Time.now
|
70
|
+
Time.should_receive(:now).and_return(now)
|
71
|
+
Iterm2TabFormatter::TextFormatter.should_receive(:new).with(
|
72
|
+
duration_seconds: 5,
|
73
|
+
example_count: 10,
|
74
|
+
failure_count: 3,
|
75
|
+
pending_count: 4,
|
76
|
+
finish_time: now
|
77
|
+
).and_return(double(
|
78
|
+
status: 'PASS_OR_FAIL',
|
79
|
+
duration: 'the_duration',
|
80
|
+
window_title: 'window_title',
|
81
|
+
finished_at: 'finish_time'
|
82
|
+
))
|
83
|
+
|
64
84
|
controller.should_receive(:window_title=).with('PASS_OR_FAIL - window_title - the_duration - Finished at finish_time')
|
65
85
|
|
66
86
|
formatter.dump_summary(5, 10, 3, 4)
|
67
87
|
end
|
68
88
|
end
|
69
89
|
end
|
70
|
-
|
71
|
-
it 'sets the window title to the description of a spec' do
|
72
|
-
example = double("example", description: 'an example description')
|
73
|
-
|
74
|
-
controller.should_receive(:window_title=).with('an example description')
|
75
|
-
controller.should_receive(:tab_title=).with('0/100')
|
76
|
-
|
77
|
-
formatter.stub(example_count: 100)
|
78
|
-
formatter.example_started(example)
|
79
|
-
end
|
80
90
|
end
|
data/spec/text_formatter_spec.rb
CHANGED
@@ -14,7 +14,9 @@ describe Iterm2TabFormatter::TextFormatter do
|
|
14
14
|
example_count, failure_count, pending_count = counts
|
15
15
|
|
16
16
|
it "is correct for #{example_count}/#{failure_count}/#{pending_count}" do
|
17
|
-
|
17
|
+
opts = {example_count: example_count, failure_count: failure_count, pending_count: pending_count}
|
18
|
+
formatter = described_class.new(opts)#example_count, failure_count, pending_count)
|
19
|
+
expect(formatter.window_title).to eq(expected_message)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -22,26 +24,32 @@ describe Iterm2TabFormatter::TextFormatter do
|
|
22
24
|
describe '.finished_at' do
|
23
25
|
it 'formats as ISO-8601 datetime' do
|
24
26
|
date = DateTime.new(2013, 3, 17, 19, 25, 0, '-7')
|
25
|
-
|
27
|
+
formatter = described_class.new(finish_time: date)
|
28
|
+
expect(formatter.finished_at).to eq('2013-03-17T19:25:00-07:00')
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
32
|
describe '.duration' do
|
30
33
|
it 'correctly prints the time under a minute' do
|
31
|
-
|
34
|
+
formatter = described_class.new(duration_seconds: 1.1)
|
35
|
+
expect(formatter.duration).to eq('1.1s')
|
32
36
|
end
|
37
|
+
|
33
38
|
it 'correctly prints time over a minute' do
|
34
|
-
|
39
|
+
formatter = described_class.new(duration_seconds: 65)
|
40
|
+
expect(formatter.duration).to eq('1m5.0s')
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
44
|
describe '.status' do
|
39
45
|
it 'is "PASS" when there are 0 failures' do
|
40
|
-
|
46
|
+
formatter = described_class.new(failure_count: 0)
|
47
|
+
expect(formatter.status).to eq('PASS')
|
41
48
|
end
|
42
49
|
|
43
50
|
it 'is "FAIL" when there are >0 failures' do
|
44
|
-
|
51
|
+
formatter = described_class.new(failure_count: 1)
|
52
|
+
expect(formatter.status).to eq('FAIL')
|
45
53
|
end
|
46
54
|
end
|
47
55
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iterm2_tab_formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: iterm2_escape
|
@@ -59,12 +59,15 @@ files:
|
|
59
59
|
- Rakefile
|
60
60
|
- iterm2_tab_formatter.gemspec
|
61
61
|
- lib/iterm2_tab_formatter.rb
|
62
|
-
- lib/iterm2_tab_formatter/
|
62
|
+
- lib/iterm2_tab_formatter/autoload.rb
|
63
63
|
- lib/iterm2_tab_formatter/base.rb
|
64
|
+
- lib/iterm2_tab_formatter/color_parse.rb
|
64
65
|
- lib/iterm2_tab_formatter/controller.rb
|
66
|
+
- lib/iterm2_tab_formatter/rspec_configuration.rb
|
65
67
|
- lib/iterm2_tab_formatter/text_formatter.rb
|
66
68
|
- lib/iterm2_tab_formatter/version.rb
|
67
69
|
- sandbox/slow_spec.rb
|
70
|
+
- spec/color_parse_spec.rb
|
68
71
|
- spec/controller_spec.rb
|
69
72
|
- spec/iterm2_tab_formatter_spec.rb
|
70
73
|
- spec/spec_helper.rb
|
@@ -84,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
87
|
version: '0'
|
85
88
|
segments:
|
86
89
|
- 0
|
87
|
-
hash:
|
90
|
+
hash: 235173726208200768
|
88
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
92
|
none: false
|
90
93
|
requirements:
|
@@ -93,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
96
|
version: '0'
|
94
97
|
segments:
|
95
98
|
- 0
|
96
|
-
hash:
|
99
|
+
hash: 235173726208200768
|
97
100
|
requirements: []
|
98
101
|
rubyforge_project:
|
99
102
|
rubygems_version: 1.8.25
|
@@ -105,6 +108,7 @@ summary: ! 'iTerm2 Tab Formatter communicates your RSpec status through your iTe
|
|
105
108
|
title: * Index of current spec and total number of specs * Window title: * Full
|
106
109
|
spec name for the current spec'
|
107
110
|
test_files:
|
111
|
+
- spec/color_parse_spec.rb
|
108
112
|
- spec/controller_spec.rb
|
109
113
|
- spec/iterm2_tab_formatter_spec.rb
|
110
114
|
- spec/spec_helper.rb
|