Skip to content

Instantly share code, notes, and snippets.

@dougo-chris
Created July 12, 2011 16:10
Show Gist options
  • Save dougo-chris/1078302 to your computer and use it in GitHub Desktop.
Save dougo-chris/1078302 to your computer and use it in GitHub Desktop.
Frogger for rspec
####################################################
# this file belongs in the ./spec/support directory
####################################################
require 'rspec/core/formatters/base_formatter'
class Frogger < RSpec::Core::Formatters::BaseFormatter
COLOR_START = "\e[34m" # blue
COLOR_FAILED = "\e[31m" # red
COLOR_PASSED = "\e[32m" # green
COLOR_PENDING = "\e[33m" # yellow
def initialize(output = nil)
super(output)
@group_level = 0
end
def example_group_started(example_group)
@group_level += 1
end
def example_group_finished(example_group)
@group_level -= 1
end
def example_started(example)
log(COLOR_START, "start", example)
end
def example_passed(example)
log(COLOR_PASSED, "passed", example)
end
def example_pending(example)
log(COLOR_PENDING, "pending", example)
end
def example_failed(example)
log(COLOR_FAILED, "failed", example)
end
protected
def current_indentation
'**' * @group_level
end
def log(color_code, action, example)
# for support of itslog
if Rails.logger.respond_to?(:namespace=)
Rails.logger.namespace = "frogger"
end
Rails.logger.info "#{color_code}#{current_indentation} #{action} : #{example.full_description}\e[0m"
end
end
RSpec.configure do |config|
config.formatters << Frogger.new
end
# if using itslog
Itslog.configure do |config|
config.namespace_colors['frogger'] = "\e[35m"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment