Webrat - Ruby Acceptance Testing for Web applications - version 0.1.0
Webrat lets you quickly write robust and thorough acceptance tests for
web application. By leveraging the DOM, it can run tests similarly to
in-browser testing solution without the associated performance hit
browser dependency). The result is tests that are less fragile and
effective at verifying that the app will respond properly to users.
Webrat works with vanilla Rails integration tests run via Test::Unit
run by the RSpec story runner.
clicks_link "Sign up"
fills_in "Email", :with => "email@example.com"
select "Free account"
Behind the scenes, this will perform the following work:
1. Verify that loading the home page is successful
2. Verify that a "Sign up" link exists on the home page
3. Verify that loading the URL pointed to by the "Sign up" link leads
4. Verify that there is an "Email" input field on the Sign Up page
5. Verify that there is an select field on the Sign Up page with an
6. Verify that there is a "Register" submit button on the page
7. Verify that submitting the Sign Up form with the values
and "Free account" leads to a successful page
Take special note of the things _not_ specified in that test, that
tests to break unnecessarily as your application evolves:
* The input field IDs or names (e.g. "user_email" or "user[email]"),
could change if you rename a model
* The ID of the form element (Webrat can do a good job of guessing,
there are multiple forms on the page.)
* The URLs of links followed
* The URL the form submission should be sent to, which could change if
adjust your routes or controllers
* The HTTP method for the login request
A test written with Webrat can handle all of these changes smoothly.
$ ruby script/plugin install http://svn.eastmedia.net/public/plugins/webrat/