Skip to content

Commit

Permalink
Nyan cat dies if specs finished and their are failed or pending specs…
Browse files Browse the repository at this point in the history
…. :-(
  • Loading branch information
mattsears committed Sep 3, 2012
1 parent 8cb8487 commit 6cf9211
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
27 changes: 22 additions & 5 deletions lib/nyan_cat_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ def tick(mark = PASS)
#
# @return [String] Nyan Cat
def nyan_cat
if @failure_count.to_i > 0 || @pending_count.to_i > 0
if self.failed_or_pending? && self.finished?
ascii_cat('x')[@color_index%2].join("\n") #'~|_(x.x)'
elsif self.failed_or_pending?
ascii_cat('o')[@color_index%2].join("\n") #'~|_(o.o)'
elsif (@current == @example_count)
elsif self.finished?
ascii_cat('-')[@color_index%2].join("\n") # '~|_(-.-)'
else
ascii_cat('^')[@color_index%2].join("\n") # '~|_(^.^)'
Expand Down Expand Up @@ -178,12 +180,27 @@ def highlight(mark = PASS)
def format_duration(duration)
seconds = ((duration % 60) * 100.0).round / 100.0 # 1.8.7 safe .round(2)
seconds = seconds.to_i if seconds.to_i == seconds # drop that zero if it's not needed

message = "#{seconds} second#{seconds == 1 ? "" : "s"}"
message = "#{(duration / 60).to_i} minute#{(duration / 60).to_i == 1 ? "" : "s"} and " + message if duration >= 60

message
end



# Determines if the specs have completed
#
# @returns [Boolean] true if finished; false otherwise
def finished?
(@current == @example_count)
end

# Determines if the any specs failed or are in pending state
#
# @returns [Boolean] true if failed or pending; false otherwise
def failed_or_pending?
(@failure_count.to_i > 0 || @pending_count.to_i > 0)
end

end

19 changes: 15 additions & 4 deletions spec/nyan_cat_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@
].join("\n")
end

it 'should kill nyan if the specs are finished' do
@formatter.example_failed(@example)
@formatter.stub(:finished?).and_return(true)
@formatter.nyan_cat.should == [
'_,------, ',
'_| /\_/\ ',
'~|_( x .x) ',
' "" "" '
].join("\n")
end

end
end

Expand Down Expand Up @@ -155,19 +166,19 @@
it "should return just seconds for sub 60 seconds" do
@formatter.format_duration(5.3).should eq("5.3 seconds")
end

it "should remove that extra zero if it is not needed" do
@formatter.format_duration(1.0).should eq("1 second")
end

it "should plurlaize seconds" do
@formatter.format_duration(1.1).should eq("1.1 seconds")
end

it "add a minute if it is just over 60 seconds" do
@formatter.format_duration(63.2543456456).should eq("1 minute and 3.25 seconds")
end

it "should pluralize minutes" do
@formatter.format_duration(987.34).should eq("16 minutes and 27.34 seconds")
end
Expand Down

0 comments on commit 6cf9211

Please sign in to comment.