| Path: | RDOC_README.rdoc |
| Last Update: | Sun Feb 08 14:57:37 -0700 2009 |
RackBox adds Merb-style blackbox testing]blackbox] to Rack apps (including Rails)
This currently only works with RSpec.
Watch the Screencast
$ 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.
$ 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
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](github.com/remi/rackbox/tree/master/examples/rails)
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](github.com/remi/rackbox/tree/master/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.
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`](rack.rubyforge.org/doc/classes/Rack/Response.html) which has `body`, `headers`, `status` methods (and more](rack.rubyforge.org/doc/classes/Rack/Response.html))