Skip to content

ged/rspec-formatter-webkit

Repository files navigation

A WebKit RSpec Formatter

deveiate.org/webkit-rspec-formatter.html

Description

This is a formatter for RSpec 2 that takes advantage of features in WebKit to make the output from RSpec in Textmate more fun.

Test output looks like this:

Installation

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

$ gem install rspec-formatter-webkit

Usage

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 adding the same variables there:

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.

Loggability

If you’re using Loggability for logging, the WebKit formatter has CSS rules for the output of its HTML formatter, and includes a helper for injecting the logs generated for an example into the output. Just include the Loggability spec helper in your RSpec config:

require 'rspec'
require 'loggability/spechelpers'

RSpec.configure do |config|
    config.include( Loggability::SpecHelpers )
end

Miscellaneous

This formatter is 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.

Contributing

You can check out the current development source with Mercurial via its project page. 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.

License

Copyright © 2009-2015, Michael Granger All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the author/s, nor the names of the project’s contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.