nyan-cat-formatter 0.0.8.1 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
data/lib/nyan_cat_formatter.rb
CHANGED
@@ -171,5 +171,19 @@ NyanCatFormatter = Class.new(parent_class) do
|
|
171
171
|
else mark
|
172
172
|
end
|
173
173
|
end
|
174
|
+
|
175
|
+
# Converts a float of seconds into a minutes/seconds string
|
176
|
+
#
|
177
|
+
# @return [String]
|
178
|
+
def format_duration(duration)
|
179
|
+
seconds = ((duration % 60) * 100.0).round / 100.0 # 1.8.7 safe .round(2)
|
180
|
+
seconds = seconds.to_i if seconds.to_i == seconds # drop that zero if it's not needed
|
181
|
+
|
182
|
+
message = "#{seconds} second#{seconds == 1 ? "" : "s"}"
|
183
|
+
message = "#{(duration / 60).to_i} minute#{(duration / 60).to_i == 1 ? "" : "s"} and " + message if duration >= 60
|
184
|
+
|
185
|
+
message
|
186
|
+
end
|
187
|
+
|
174
188
|
end
|
175
189
|
|
@@ -41,7 +41,7 @@ module RSpec1
|
|
41
41
|
|
42
42
|
def dump_summary(duration, example_count, failure_count, pending_count)
|
43
43
|
system("killall -9 afplay") if File.exists?(File.expand_path("~/.nyan-cat.mp3")) && RUBY_PLATFORM.downcase.include?("darwin")
|
44
|
-
@output.puts "\nYou've Nyaned for #{duration}
|
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
|
47
47
|
|
@@ -31,7 +31,7 @@ module RSpec2
|
|
31
31
|
mp3_file = File.expand_path( File.join( File.dirname(__FILE__), "../../data/nyan-cat.mp3"))
|
32
32
|
system("killall -9 afplay") if File.exists?(mp3_file) && RUBY_PLATFORM.downcase.include?("darwin")
|
33
33
|
dump_profile if profile_examples? && failure_count == 0
|
34
|
-
summary = "\nYou've Nyaned for #{
|
34
|
+
summary = "\nYou've Nyaned for #{format_duration(duration)}\n".split(//).map { |c| rainbowify(c) }
|
35
35
|
output.puts summary.join
|
36
36
|
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
|
37
37
|
if respond_to?(:dump_commands_to_rerun_failed_examples)
|
data/nyan-cat-formatter.gemspec
CHANGED
@@ -151,4 +151,25 @@ describe NyanCatFormatter do
|
|
151
151
|
|
152
152
|
end
|
153
153
|
|
154
|
+
describe "#format_duration" do
|
155
|
+
it "should return just seconds for sub 60 seconds" do
|
156
|
+
@formatter.format_duration(5.3).should eq("5.3 seconds")
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should remove that extra zero if it is not needed" do
|
160
|
+
@formatter.format_duration(1.0).should eq("1 second")
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should plurlaize seconds" do
|
164
|
+
@formatter.format_duration(1.1).should eq("1.1 seconds")
|
165
|
+
end
|
166
|
+
|
167
|
+
it "add a minute if it is just over 60 seconds" do
|
168
|
+
@formatter.format_duration(63.2543456456).should eq("1 minute and 3.25 seconds")
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should pluralize minutes" do
|
172
|
+
@formatter.format_duration(987.34).should eq("16 minutes and 27.34 seconds")
|
173
|
+
end
|
174
|
+
end
|
154
175
|
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.0.
|
4
|
+
version: 0.0.9
|
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-08-
|
12
|
+
date: 2012-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|