nyan-cat-formatter 0.0.9 → 0.1.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 +2 -2
- data/lib/nyan_cat_formatter.rb +22 -5
- data/lib/nyan_cat_formatter/rspec1.rb +1 -1
- data/lib/nyan_cat_formatter/rspec2.rb +1 -2
- data/lib/nyan_cat_music_formatter.rb +18 -2
- data/nyan-cat-formatter.gemspec +1 -1
- data/spec/nyan_cat_formatter_spec.rb +15 -4
- data/spec/nyan_cat_music_formatter_spec.rb +10 -5
- metadata +2 -2
data/README.md
CHANGED
@@ -47,7 +47,7 @@ If you want to use Nyan Cat as your default formatter, simply put the options in
|
|
47
47
|
--format NyanCatFormatter
|
48
48
|
```
|
49
49
|
|
50
|
-
Playing the Nyan Cat song
|
50
|
+
Playing the Nyan Cat song
|
51
51
|
-------------------------
|
52
52
|
|
53
53
|
You can then enjoy playback in two ways:
|
@@ -73,7 +73,7 @@ Make sure your .rspec file in your application's root directory contains the fol
|
|
73
73
|
|
74
74
|
Then run `rspec spec` and enjoy Nyan Cat formatted text output accompanied by the Nyan Cat song by default!
|
75
75
|
|
76
|
-
**This currently only works on Mac
|
76
|
+
**This currently only works on Mac OS X or on Linux (if you have mpg321 installed).**
|
77
77
|
|
78
78
|
Contributing
|
79
79
|
----------
|
data/lib/nyan_cat_formatter.rb
CHANGED
@@ -41,9 +41,11 @@ NyanCatFormatter = Class.new(parent_class) do
|
|
41
41
|
#
|
42
42
|
# @return [String] Nyan Cat
|
43
43
|
def nyan_cat
|
44
|
-
if
|
44
|
+
if self.failed_or_pending? && self.finished?
|
45
|
+
ascii_cat('x')[@color_index%2].join("\n") #'~|_(x.x)'
|
46
|
+
elsif self.failed_or_pending?
|
45
47
|
ascii_cat('o')[@color_index%2].join("\n") #'~|_(o.o)'
|
46
|
-
elsif
|
48
|
+
elsif self.finished?
|
47
49
|
ascii_cat('-')[@color_index%2].join("\n") # '~|_(-.-)'
|
48
50
|
else
|
49
51
|
ascii_cat('^')[@color_index%2].join("\n") # '~|_(^.^)'
|
@@ -178,12 +180,27 @@ NyanCatFormatter = Class.new(parent_class) do
|
|
178
180
|
def format_duration(duration)
|
179
181
|
seconds = ((duration % 60) * 100.0).round / 100.0 # 1.8.7 safe .round(2)
|
180
182
|
seconds = seconds.to_i if seconds.to_i == seconds # drop that zero if it's not needed
|
181
|
-
|
183
|
+
|
182
184
|
message = "#{seconds} second#{seconds == 1 ? "" : "s"}"
|
183
185
|
message = "#{(duration / 60).to_i} minute#{(duration / 60).to_i == 1 ? "" : "s"} and " + message if duration >= 60
|
184
|
-
|
186
|
+
|
185
187
|
message
|
186
188
|
end
|
187
|
-
|
189
|
+
|
190
|
+
|
191
|
+
# Determines if the specs have completed
|
192
|
+
#
|
193
|
+
# @returns [Boolean] true if finished; false otherwise
|
194
|
+
def finished?
|
195
|
+
(@current == @example_count)
|
196
|
+
end
|
197
|
+
|
198
|
+
# Determines if the any specs failed or are in pending state
|
199
|
+
#
|
200
|
+
# @returns [Boolean] true if failed or pending; false otherwise
|
201
|
+
def failed_or_pending?
|
202
|
+
(@failure_count.to_i > 0 || @pending_count.to_i > 0)
|
203
|
+
end
|
204
|
+
|
188
205
|
end
|
189
206
|
|
@@ -40,7 +40,7 @@ module RSpec1
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def dump_summary(duration, example_count, failure_count, pending_count)
|
43
|
-
|
43
|
+
NyanCatMusicFormatter.new(NyanCatFormatter).kill_music if NyanCatMusicFormatter
|
44
44
|
@output.puts "\nYou've Nyaned for #{format_duration(duration)}\n".each_char.map {|c| rainbowify(c)}.join
|
45
45
|
summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
|
46
46
|
summary << ", #{pending_count} pending" if pending_count > 0
|
@@ -28,8 +28,7 @@ module RSpec2
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def dump_summary(duration, example_count, failure_count, pending_count)
|
31
|
-
|
32
|
-
system("killall -9 afplay") if File.exists?(mp3_file) && RUBY_PLATFORM.downcase.include?("darwin")
|
31
|
+
NyanCatMusicFormatter.new(NyanCatFormatter).kill_music if NyanCatMusicFormatter
|
33
32
|
dump_profile if profile_examples? && failure_count == 0
|
34
33
|
summary = "\nYou've Nyaned for #{format_duration(duration)}\n".split(//).map { |c| rainbowify(c) }
|
35
34
|
output.puts summary.join
|
@@ -3,7 +3,11 @@ require 'nyan_cat_formatter'
|
|
3
3
|
|
4
4
|
NyanCatMusicFormatter = Class.new(NyanCatFormatter) do
|
5
5
|
def osx?
|
6
|
-
platform.include?("darwin")
|
6
|
+
platform.downcase.include?("darwin")
|
7
|
+
end
|
8
|
+
|
9
|
+
def linux?
|
10
|
+
platform.downcase.include?('linux')
|
7
11
|
end
|
8
12
|
|
9
13
|
def kernel=(kernel)
|
@@ -22,8 +26,20 @@ NyanCatMusicFormatter = Class.new(NyanCatFormatter) do
|
|
22
26
|
@platform ||= RUBY_PLATFORM
|
23
27
|
end
|
24
28
|
|
29
|
+
def nyan_mp3
|
30
|
+
File.expand_path('../../data/nyan-cat.mp3', __FILE__)
|
31
|
+
end
|
32
|
+
|
25
33
|
def start input
|
26
34
|
super
|
27
|
-
kernel.system("afplay #{
|
35
|
+
kernel.system("afplay #{nyan_mp3} &") if osx?
|
36
|
+
kernel.system("[ -e #{nyan_mp3} ] && type mpg321 &>/dev/null && mpg321 #{nyan_mp3} &>/dev/null &") if linux?
|
37
|
+
end
|
38
|
+
|
39
|
+
def kill_music
|
40
|
+
if File.exists? nyan_mp3
|
41
|
+
system("killall -9 afplay &>/dev/null") if osx?
|
42
|
+
system("killall -9 mpg321 &>/dev/null") if linux?
|
43
|
+
end
|
28
44
|
end
|
29
45
|
end
|
data/nyan-cat-formatter.gemspec
CHANGED
@@ -94,6 +94,17 @@ describe NyanCatFormatter do
|
|
94
94
|
].join("\n")
|
95
95
|
end
|
96
96
|
|
97
|
+
it 'should kill nyan if the specs are finished' do
|
98
|
+
@formatter.example_failed(@example)
|
99
|
+
@formatter.stub(:finished?).and_return(true)
|
100
|
+
@formatter.nyan_cat.should == [
|
101
|
+
'_,------, ',
|
102
|
+
'_| /\_/\ ',
|
103
|
+
'~|_( x .x) ',
|
104
|
+
' "" "" '
|
105
|
+
].join("\n")
|
106
|
+
end
|
107
|
+
|
97
108
|
end
|
98
109
|
end
|
99
110
|
|
@@ -155,19 +166,19 @@ describe NyanCatFormatter do
|
|
155
166
|
it "should return just seconds for sub 60 seconds" do
|
156
167
|
@formatter.format_duration(5.3).should eq("5.3 seconds")
|
157
168
|
end
|
158
|
-
|
169
|
+
|
159
170
|
it "should remove that extra zero if it is not needed" do
|
160
171
|
@formatter.format_duration(1.0).should eq("1 second")
|
161
172
|
end
|
162
|
-
|
173
|
+
|
163
174
|
it "should plurlaize seconds" do
|
164
175
|
@formatter.format_duration(1.1).should eq("1.1 seconds")
|
165
176
|
end
|
166
|
-
|
177
|
+
|
167
178
|
it "add a minute if it is just over 60 seconds" do
|
168
179
|
@formatter.format_duration(63.2543456456).should eq("1 minute and 3.25 seconds")
|
169
180
|
end
|
170
|
-
|
181
|
+
|
171
182
|
it "should pluralize minutes" do
|
172
183
|
@formatter.format_duration(987.34).should eq("16 minutes and 27.34 seconds")
|
173
184
|
end
|
@@ -13,10 +13,7 @@ class MockKernel
|
|
13
13
|
end
|
14
14
|
|
15
15
|
describe NyanCatMusicFormatter do
|
16
|
-
|
17
|
-
"#{File.expand_path('data/nyan-cat.mp3')}"
|
18
|
-
end
|
19
|
-
|
16
|
+
let(:path_to_mp3) { NyanCatMusicFormatter.new(NyanCatFormatter).nyan_mp3 }
|
20
17
|
let(:stdout) { StringIO.new }
|
21
18
|
let(:formatter) { described_class.new stdout }
|
22
19
|
let(:mock_kernel) { MockKernel.new }
|
@@ -37,7 +34,7 @@ describe NyanCatMusicFormatter do
|
|
37
34
|
|
38
35
|
describe 'platform' do
|
39
36
|
it 'defaults to RUBY_PLATFORM' do
|
40
|
-
described_class.new(stdout).platform.should
|
37
|
+
described_class.new(stdout).platform.should eq RUBY_PLATFORM
|
41
38
|
end
|
42
39
|
|
43
40
|
it 'can be set' do
|
@@ -67,6 +64,14 @@ describe NyanCatMusicFormatter do
|
|
67
64
|
end
|
68
65
|
end
|
69
66
|
|
67
|
+
context 'when on linux' do
|
68
|
+
before { formatter.platform = 'linux'}
|
69
|
+
it 'plays the song for linux too' do
|
70
|
+
formatter.start 10
|
71
|
+
mock_kernel.seen.any? { |entry| entry. end_with? "mpg321 #{path_to_mp3} &>/dev/null &" }.should be
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
70
75
|
context 'when not on OS X' do
|
71
76
|
before { formatter.platform = 'windows' }
|
72
77
|
|
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.0
|
4
|
+
version: 0.1.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: 2012-
|
12
|
+
date: 2012-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|