Skip to content

Instantly share code, notes, and snippets.

@evolve2k
Created August 4, 2011 23:31
Show Gist options
  • Select an option

  • Save evolve2k/1126570 to your computer and use it in GitHub Desktop.

Select an option

Save evolve2k/1126570 to your computer and use it in GitHub Desktop.
RSpec Frogger
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment