public
Description: BlackBox testing for Rack apps (and Rails)
Homepage: http://code.remi.org/rackbox
Clone URL: git://github.com/remi/rackbox.git
name age message
file .gitignore Tue Feb 03 16:19:53 -0800 2009 ignoring rdoc [remi]
file LICENSE Fri Feb 06 12:58:01 -0800 2009 added license [remi]
file RDOC_README.rdoc Tue Feb 03 16:39:04 -0800 2009 RDoc tweaks [remi]
file README.markdown Sun Jun 28 23:39:53 -0700 2009 rack-contrib has a middleware for handling Nest... [remi]
file Rakefile Sat Mar 14 21:37:27 -0700 2009 added a simple 'rackbox' script, run it for usa... [remi]
file VERSION.yml Wed Apr 01 21:20:15 -0700 2009 version bump to 1.1.6 to rebuild gem because so... [remi]
directory bin/ Sat Mar 14 21:37:27 -0700 2009 added a simple 'rackbox' script, run it for usa... [remi]
directory examples/ Fri Mar 13 19:32:07 -0700 2009 it's FAR from perfect ... but i got this workin... [remi]
directory lib/ Wed Apr 01 21:19:39 -0700 2009 added HTTP BASIC AUTH support ... request('/', ... [remi]
file rackbox.gemspec Wed Apr 01 21:20:18 -0700 2009 Regenerated gemspec for version 1.1.6 [remi]
directory rails_generators/ Thu Jan 29 00:36:23 -0800 2009 added rails generator, ./script/generate blackb... [remi]
file run-specs Thu Jan 29 00:39:04 -0800 2009 updated ./run-specs to run all specs (main rack... [remi]
directory spec/ Wed Apr 01 21:19:39 -0700 2009 added HTTP BASIC AUTH support ... request('/', ... [remi]
README.markdown

RackBox

RackBox adds Merb-style blackbox testing to Rack apps (including Rails)

This currently only works with RSpec.

Screencast

Watch the 'Screencast'

Installation

$ sudo gem install remi-rackbox -s http://gems.github.com

NOTE: right now, RackBox requires thin. Soon, I'll likely remove thin as a dependency and will only require rack.

Rails (fast!)

$ sudo gem install rspec rspec-rails thin
$ sudo gem install remi-rackbox -s http://gems.github.com

$ rails new_app
$ cd new_app
$ ./script/generate rspec
$ ./script/generate blackbox_spec Home Page

$ rake spec

Rails (manual)

To write RackBox tests in Rails apps, make a blackbox directory under your spec directory and add this to the Spec configure block in your spec_helper.rb file:

config.use_blackbox = true

Also, add require 'rackbox' to the top of your spec_helper.rb

You can see a working example of blackbox testing a Rails application here: examples/rails

Rack

To write RackBox tests in Rack apps, I'm currently assuming that you have a config.ru rackup file. If so, your app should load, otherwise you can explicitly configure RackBox to read your Rack app:

RackBox.app = [your Rack app]

Basides that, the configuration is the same as Rails. Make a blackbox directory under your spec directory and add this to the Spec configure block in your spec_helper.rb file:

config.use_blackbox = true

Also, add require 'rackbox' to the top of your spec_helper.rb

You can see a working example of blackbox testing a Rack application here: examples/rack

NOTE: If you want to be able to use nice RSpec matchers like request('/').should have_tag('p') in your blackbox specs in your Rack apps, you should sudo gem install webrat and RackBox will include Webrat's helpers in your specs.

Usage

Ideally, the usage of RackBox should be identical to Merb-style blackbox testing. I need to find good documentation on how things work in Merb so I can duplicate any functionality I'm missing. For now, it's really simple!

describe Foo do

  it 'should have foxes on the home page' do
    request('/').body.should include('Foxes')
  end

  it 'should let me know that I was logged in' do
    response = request(login_path, :method => :post, :params => { 'user' => 'bob', :password => 'secret' })
    response.body.should include('Welcome bob, you were successfully logged in!')
  end

end

request gives you a Rack::Response which has body, headers, status methods (and more)

Script

RackBox also comes with a rackbox script.

# prints usage ... this is all you really need  :)
$ rackbox

# prints out information about the app in the current directory (if found).
# this looks like a config.ru or a Rails environment
$ rackbox info

# prints out the response for a call to GET '/' on your application
$ rackbox request --method get /foo
$ rackbox get /foo
$ rackbox /foo

TODO

see RackBox's Lighthouse Tickets look at using Rack::Cookies as a cookie jar instead of doing it ourselves look at Rack::NestedParams and see if it can replace our own logic