nyan-cat-formatter 0.2.0 → 0.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.
- data/README.md +14 -0
- data/demo.rb +0 -0
- data/lib/nyan_cat_formatter.rb +21 -4
- data/lib/nyan_cat_wide_formatter.rb +19 -0
- data/nyan-cat-formatter.gemspec +1 -1
- data/spec/nyan_cat_formatter_spec.rb +19 -0
- data/spec/nyan_cat_wide_formatter_spec.rb +44 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -75,6 +75,20 @@ Then run `rspec spec` and enjoy Nyan Cat formatted text output accompanied by th
|
|
75
75
|
|
76
76
|
**This currently only works on Mac OS X or on Linux (if you have mpg321 or mpg123 installed).**
|
77
77
|
|
78
|
+
Using the Nyan Cat Wide Formatter
|
79
|
+
---------------------------------
|
80
|
+
|
81
|
+
The classic Nyan Cat Formatter uses a terminal column per test. One
|
82
|
+
test, and single step that the cat goes ahead. The **Nyan Cat Wide
|
83
|
+
Formatter**, instead, uses the whole terminal width, so the cat will
|
84
|
+
always end up reaching the end of the terminal.
|
85
|
+
|
86
|
+
Simple use it by configuring it as the RSpec formatter:
|
87
|
+
|
88
|
+
```
|
89
|
+
--format NyanCatWideFormatter
|
90
|
+
```
|
91
|
+
|
78
92
|
Contributing
|
79
93
|
----------
|
80
94
|
|
data/demo.rb
CHANGED
File without changes
|
data/lib/nyan_cat_formatter.rb
CHANGED
@@ -77,9 +77,14 @@ NyanCatFormatter = Class.new(parent_class) do
|
|
77
77
|
#
|
78
78
|
# @return [Fixnum]
|
79
79
|
def current_width
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
padding_width + example_width + cat_length
|
81
|
+
end
|
82
|
+
|
83
|
+
# Gets the padding for the current example count
|
84
|
+
#
|
85
|
+
# @return [Fixnum]
|
86
|
+
def padding_width
|
87
|
+
@example_count.to_s.length * 2 + 6
|
83
88
|
end
|
84
89
|
|
85
90
|
# A Unix trick using stty to get the console columns
|
@@ -112,13 +117,18 @@ NyanCatFormatter = Class.new(parent_class) do
|
|
112
117
|
#
|
113
118
|
# @return [String] the sprintf format of the Nyan cat
|
114
119
|
def nyan_trail
|
115
|
-
marks = @example_results.map{ |mark| highlight(mark) }
|
120
|
+
marks = @example_results.each_with_index.map{ |mark, i| highlight(mark) * example_width(i) }
|
116
121
|
marks.shift(current_width - terminal_width) if current_width >= terminal_width
|
117
122
|
nyan_cat_lines = nyan_cat.split("\n").each_with_index.map do |line, index|
|
118
123
|
format("%s#{line}", marks.join)
|
119
124
|
end.join("\n")
|
120
125
|
end
|
121
126
|
|
127
|
+
# Times a mark has to be repeated
|
128
|
+
def example_width(item = 1)
|
129
|
+
1
|
130
|
+
end
|
131
|
+
|
122
132
|
# Ascii version of Nyan cat. Two cats in the array allow Nyan to animate running.
|
123
133
|
#
|
124
134
|
# @param o [String] Nyan's eye
|
@@ -202,5 +212,12 @@ NyanCatFormatter = Class.new(parent_class) do
|
|
202
212
|
(@failure_count.to_i > 0 || @pending_count.to_i > 0)
|
203
213
|
end
|
204
214
|
|
215
|
+
# Returns the cat length
|
216
|
+
#
|
217
|
+
# @returns [Fixnum]
|
218
|
+
def cat_length
|
219
|
+
nyan_cat.split("\n").group_by(&:size).max.first
|
220
|
+
end
|
221
|
+
|
205
222
|
end
|
206
223
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'nyan_cat_formatter'
|
3
|
+
|
4
|
+
NyanCatWideFormatter = Class.new(NyanCatFormatter) do
|
5
|
+
def example_width(example = current)
|
6
|
+
net_width_for(example) - net_width_for(example - 1)
|
7
|
+
end
|
8
|
+
|
9
|
+
def net_width_for(example)
|
10
|
+
@net_width ||= {}
|
11
|
+
|
12
|
+
@net_width[example] ||= begin
|
13
|
+
return 0 if example < 0
|
14
|
+
net_width = terminal_width - padding_width - cat_length
|
15
|
+
rough_example_width = (net_width * example.to_f / @example_count.to_f)
|
16
|
+
rough_example_width.round
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/nyan-cat-formatter.gemspec
CHANGED
@@ -183,4 +183,23 @@ describe NyanCatFormatter do
|
|
183
183
|
@formatter.format_duration(987.34).should eq("16 minutes and 27.34 seconds")
|
184
184
|
end
|
185
185
|
end
|
186
|
+
|
187
|
+
describe "example width" do
|
188
|
+
[15, 36, 60].each do |n|
|
189
|
+
context "for #{n} examples" do
|
190
|
+
before { @formatter.start(n) }
|
191
|
+
|
192
|
+
[0.25, 0.5, 0.75].each do |p|
|
193
|
+
i = (n * p).to_i
|
194
|
+
before { i.times { @formatter.tick } }
|
195
|
+
|
196
|
+
context "when in example #{i}" do
|
197
|
+
it "should return 1 as the example width" do
|
198
|
+
@formatter.example_width.should == 1
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
186
205
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
require 'nyan_cat_wide_formatter'
|
4
|
+
|
5
|
+
describe NyanCatWideFormatter do
|
6
|
+
before do
|
7
|
+
@output = StringIO.new
|
8
|
+
@formatter = NyanCatWideFormatter.new(@output)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "cat situation" do
|
12
|
+
before do
|
13
|
+
@formatter.stub!(:terminal_width).and_return(100)
|
14
|
+
@formatter.stub!(:cat_length).and_return(11)
|
15
|
+
@whole_net_width = 100 - 2*2 - 6 - 11
|
16
|
+
end
|
17
|
+
|
18
|
+
context "for 35 examples" do
|
19
|
+
before do
|
20
|
+
@formatter.start(35)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should calculate the net width for example 3" do
|
24
|
+
@formatter.net_width_for(3).should == (@whole_net_width * 3.0 / 35.0).round
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should calculate the net width for example 30" do
|
28
|
+
@formatter.net_width_for(5).should == (@whole_net_width * 5.0 / 35.0).round
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "for 50 examples" do
|
33
|
+
before { @formatter.start(50) }
|
34
|
+
|
35
|
+
it "should calculate the net width for example 1" do
|
36
|
+
@formatter.net_width_for(1).should == (@whole_net_width * 1.0 / 50.0).round
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should calculate the net width for example 25" do
|
40
|
+
@formatter.net_width_for(25).should == (@whole_net_width * 25.0 / 50.0).round
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nyan-cat-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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:
|
12
|
+
date: 2013-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -65,9 +65,11 @@ files:
|
|
65
65
|
- lib/nyan_cat_formatter/rspec1.rb
|
66
66
|
- lib/nyan_cat_formatter/rspec2.rb
|
67
67
|
- lib/nyan_cat_music_formatter.rb
|
68
|
+
- lib/nyan_cat_wide_formatter.rb
|
68
69
|
- nyan-cat-formatter.gemspec
|
69
70
|
- spec/nyan_cat_formatter_spec.rb
|
70
71
|
- spec/nyan_cat_music_formatter_spec.rb
|
72
|
+
- spec/nyan_cat_wide_formatter_spec.rb
|
71
73
|
- spec/spec_helper.rb
|
72
74
|
homepage: http://mtts.rs/nyancat
|
73
75
|
licenses: []
|
@@ -96,4 +98,5 @@ summary: Nyan Cat inspired RSpec formatter!
|
|
96
98
|
test_files:
|
97
99
|
- spec/nyan_cat_formatter_spec.rb
|
98
100
|
- spec/nyan_cat_music_formatter_spec.rb
|
101
|
+
- spec/nyan_cat_wide_formatter_spec.rb
|
99
102
|
- spec/spec_helper.rb
|