Integration tests are probably more important then anything else, and using a library like Webrat makes them very easy to do. […] Webrat rocks for integration tests.
—Gregg Pollack, Rails Envy
Webrat is a Ruby integration test library. It has two main purposes:
It's maintained by Bryan Helmkamp.
class SignupTest < ActionController::IntegrationTest def test_trial_account_sign_up visit home_path click_link "Sign up" fill_in "Email", :with => "good@example.com" select "Free account" click_button "Register" assert_contain "Thanks for joining" end end
Behind the scenes, Webrat will ensure:
Webrat's long term goal is to become a unified API for driving interactions with Web applications from Ruby. To this end, it supports most popular Ruby testing frameworks:
It also works with multiple Ruby web application frameworks:
Finally, Webrat supports swappable adapters. An adapter in this context is the tool Webrat uses to interact with the application under test. Currently supported are:
Additional adapters, like Celerity are in the works.
Users of Debian Linux (e.g. Ubuntu) need to run:
$ sudo apt-get install libxslt1-dev libxml2-dev.
Otherwise the Nokogiri gem, which Webrat depends on, won't install properly.
To install the latest release as a gem:
$ sudo gem install webrat
To install the latest code as a plugin: (_Note:_ This may be less stable than using a released version)
script/plugin install git://github.com/brynary/webrat.git
In your test_helper.rb or env.rb (for Cucumber) add:
require "webrat" Webrat.configure do |config| config.mode = :rails end
In spec_helper.rb (for RSpec), you need the above, plus an addition in the Spec::Runner configuration, like so:
Spec::Runner.configure do |config| include Webrat::Methods ...
Discussion