Skip to content

Commit

Permalink
Merge pull request #1958 from mdeniz/nyan_obs_unicorn
Browse files Browse the repository at this point in the history
[ci] Add NyanUnicornFormatter for RSpec
  • Loading branch information
hennevogel committed Jul 21, 2016
2 parents bafe87a + 1d1871a commit 9bc8dbb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ group :test do
gem 'mocha', '> 0.13.0', require: false
# for testing common Rails functionality with simple one-liners
gem 'shoulda-matchers', '~> 3.1'
# for having fun while waiting for Rspec to finish
gem 'nyan-cat-formatter'
end

# Gems used only during development not required in production environments by default.
Expand Down
7 changes: 7 additions & 0 deletions src/api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ GEM
mini_portile2 (~> 2.0.0)
nokogumbo (1.4.1)
nokogiri
nyan-cat-formatter (0.11)
rspec (>= 2.99, >= 2.14.2, < 4)
parser (2.2.3.0)
ast (>= 1.1, < 3.0)
pkg-config (1.1.6)
Expand Down Expand Up @@ -226,6 +228,10 @@ GEM
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
riddle (1.5.12)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-core (3.4.2)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
Expand Down Expand Up @@ -374,6 +380,7 @@ DEPENDENCIES
mocha (> 0.13.0)
mysql2
nokogiri (~> 1.6.7)
nyan-cat-formatter
poltergeist (>= 1.4)
pry (>= 0.9.12)
pundit
Expand Down
59 changes: 59 additions & 0 deletions src/api/spec/nyan_unicorn_formatter.rb
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
5 changes: 5 additions & 0 deletions src/api/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed

# Custom formatter, but not in Travis-CI
unless ENV['TRAVIS']
config.formatter = 'NyanUnicornFormatter'
end
end

# We never want the backend to autostart itself...
Expand Down

0 comments on commit 9bc8dbb

Please sign in to comment.