Skip to content

Instantly share code, notes, and snippets.

@lenary
Created January 25, 2011 14:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lenary/795021 to your computer and use it in GitHub Desktop.
Save lenary/795021 to your computer and use it in GitHub Desktop.
assorted RSpec 2 formatters

Two formatters i made, just for fun, both heavily based of the specdoc format.

The dragon_formatter.rb just says "HERE BE DRAGONS" after pending tests, and tells you the count in the summary.

the boss_formatter.rb just adds "LIKE A BOSS!" after passing tests, and when it says how long it took.

require 'rspec/core/formatters/documentation_formatter'
# Assertive formatter for rspec
class BossFormatter < RSpec::Core::Formatters::DocumentationFormatter
def passed_output(example)
green("#{current_indentation}#{example.description} LIKE A BOSS!")
end
def dump_summary(duration, example_count, failure_count, pending_count)
super(duration, example_count, failure_count, pending_count)
# Don't print out profiled info if there are failures, it just clutters the output
dump_profile if profile_examples? && failure_count == 0
output.puts "\nFinished in #{format_seconds(duration)} seconds LIKE A BOSS!\n"
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
end
end
require 'rspec/core/formatters/documentation_formatter'
# fun formatter for rspec
class DragonFormatter < RSpec::Core::Formatters::DocumentationFormatter
def pending_output(example, message)
yellow("#{current_indentation}#{example.description} (HERE BE DRAGONS: #{message})")
end
def summary_line(example_count, failure_count, pending_count)
summary = pluralize(example_count, "example")
summary << ", " << pluralize(failure_count, "failure")
summary << ", " << pluralize(pending_count, "DRAGONS") if pending_count > 0
summary
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment