A WebKit RSpec Formatter

This is a formatter for RSpec 2 that takes advantage of features in WebKit:http://webkit.org/ to make the output from RSpec in TextMate more fun.

Test output looks like this:



To get started, install the `rspec-formatter-webkit` gem:

$ gem install rspec-formatter-webkit


If you’re running specs in Textmate 2 via the RSpec bundle, include these in your .tm_properties file:

TM_RSPEC_OPTS      = '-rrspec/core/formatters/webkit'
TM_RSPEC_FORMATTER = 'RSpec::Core::Formatters::WebKit'

To do the same in TextMate 1, open the ‘Advanced’ Preferences and add the same variables there:

Preferences Dialog

That’s it!

Logging Output

If you have some kind of log output that you’d like to show up underneath the example, you can append lines of HTML to the logger-output thread-local variable and they’ll be inserted into a div under the example line that can be toggled open and closed by clicking the example line:

Thread.current['logger-output'] << %{<p>Some stuff happened.</p>}

Each line that has such logging appended will appear with an asterisk after it in the output.

Logging Output Example


If you’re using Loggability for logging, the WebKit formatter has CSS rules for the output of its HTML formatter. You can inject logs into the spec output with the following helper methods:

### Reset the logging subsystem to its default state.
def reset_logging
	Loggability.format_as( :color )
	Loggability.output_to( $stderr )
	Loggability.level = :fatal

### Alter the output of the default log formatter to be pretty in SpecMate output
def setup_logging( level=:fatal )

	# Only do this when executing from a spec in TextMate or when
	# HTML_LOGGING=1 is set in the environment
	  (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
		logarray = []
		Thread.current['logger-output'] = logarray
		Loggability.output_to( logarray )
		Loggability.format_as( :html )
		Loggability.level = :debug
		Loggability.level = level

Then, in your examples:

before( :all ) { setup_logging }
after( :all )  { reset_logging }


It’s also usable anywhere else the standard HTML formatter is, of course. Also, while it’s specifically intended to be used under the Textmate HTML viewer that the RSpec bundle uses, the output should work fine under recent Gecko/Firefox-based viewers, as well.

Patches/suggestions welcomed.


You can check out the current development source with Mercurial via its canonical repo. Or if you prefer Git, via its Github mirror.

After checking out the source, run:

$ rake newb

This task will install any missing dependencies and generate the API documentation.