-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1958 from mdeniz/nyan_obs_unicorn
[ci] Add NyanUnicornFormatter for RSpec
- Loading branch information
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
require 'nyan_cat_formatter' | ||
|
||
class NyanUnicornFormatter < NyanCatFormatter | ||
RSpec::Core::Formatters.register self, :example_started, :example_passed, :example_pending, :example_failed, :start_dump, :start | ||
|
||
# Determine which Ascii Nyan Cat to display. If tests are complete, | ||
# Nyan Cat goes to sleep. If there are failing or pending examples, | ||
# Nyan Cat is concerned. | ||
# | ||
# @return [String] Nyan Cat | ||
def nyan_cat | ||
if self.failed_or_pending? && self.finished? | ||
ascii_cat('x')[@color_index%2].join("\n") | ||
elsif self.failed_or_pending? | ||
ascii_cat('o')[@color_index%2].join("\n") | ||
elsif self.finished? | ||
ascii_cat('-')[@color_index%2].join("\n") | ||
else | ||
ascii_cat('·')[@color_index%2].join("\n") | ||
end | ||
end | ||
|
||
def progress_lines | ||
last_length = 1 | ||
[ | ||
nyan_trail.split("\n").each_with_index.inject([]) do |result, (trail, index)| | ||
last_length = format("%s", "#{scoreboard[index]}/#{@example_count}:").length unless scoreboard[index].nil? | ||
value = scoreboard[index].nil? ? ' ' * (last_length / 2) : "#{scoreboard[index]}/#{@example_count}:" | ||
result << format("%s %s", value, trail) | ||
end | ||
].flatten | ||
end | ||
|
||
# Ascii version of Nyan cat. Two cats in the array allow Nyan to animate running. | ||
# | ||
# @param o [String] Nyan's eye | ||
# @return [Array] Nyan cats | ||
def ascii_cat(o = '.') | ||
[ | ||
[ | ||
'OBS· / ', | ||
"*·* sS#{o}\\ ", | ||
' .--,__sS/\,)', | ||
' S( /_ \ ) ', | ||
'Ss || || ', | ||
" '' '' " | ||
], | ||
[ | ||
'OBS* / ', | ||
"·*· sS#{o}\\ ", | ||
' .--,__sS/\,)', | ||
' S( /_ \ ) ', | ||
'Ss \\\\ \\\\ ', | ||
" '' '' " | ||
] | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters