## Wednesday, May 27, 2009

### Rack Up Some RSpec Tests

Here's a simple rack application to render the output from running RSpec.
(Note: this is tailored to work on windows..)

#\ -w -p 8765use Rack::Reloader, 0use Rack::ContentLengthapp = proc do |env|    formatting = '--require "C:\\...\\Ruby RSpec.tmbundle\\Support\\lib\\text_mate_formatter" -f ' + 'Spec::Runner::Formatter::TextMateFormatter' if env["REQUEST_PATH"] == "/textmate"    formatting = '-f h' if env["REQUEST_PATH"] == "/html"        out = spec.bat spec #{formatting}  2>&1    format = out=~/\    [ 200, {'Content-Type' => format}, out ]endrun app

## How to use it

Install rack if you haven't already. gem install rack

• To start it, save this code into a file called 'spec_rack.ru'.
• Change the '...' to the path to your textmate bundles... (or just ignore it if you don't use E or textmate)
• Run rackup spec_rack.ru
• visit http://localhost:8765 http://localhost:8765/html or http://localhost:8765/textmate

## Why Bother?

I'm using RSpec for testing, but the integration with E (the windows clone of Textmate) seems to hang sometimes when there is an error in my code.
Having explorer open with the results so I can just press refresh is working well for me.

I wanted to post a simple rack application as there don't seem to be many examples around.