December 08, 2007
Webrat 0.1.0 released
Last week I pushed Webrat 0.1.0 out the door. So far the response has been great, and I’ve already received a couple patched (Thanks, David!). Here’s a quick usage example (from the README):
1 2 3 4 5 6 7 8 |
def test_sign_up visits "/" clicks_link "Sign up" fills_in "Email", :with => "good@example.com" select "Free account" clicks_button "Register" ... end |
Behind the scenes, this will perform the following work:
- Verify that loading the home page is successful
- Verify that a “Sign up” link exists on the home page
- Verify that loading the URL pointed to by the “Sign up” link leads to a successful page
- Verify that there is an “Email” input field on the Sign Up page
- Verify that there is an select field on the Sign Up page with an option for “Free account”
- Verify that there is a “Register” submit button on the page
- Verify that submitting the Sign Up form with the values “good@example.com” and “Free account” leads to a successful page
Take special note of the things not specified in that test, that might cause tests to break unnecessarily as your application evolves:
- The input field IDs or names (e.g. “user_email” or “user[email]”), which could change if you rename a model
- The ID of the form element (Webrat can do a good job of guessing, even if 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 you adjust your routes or controllers
- The HTTP method for the login request
A test written with Webrat can handle these changes smoothly.
SVN is at http://svn.eastmedia.net/public/plugins/webrat/. Check out the full README.
December 18, 2007 at 8:06 PM
Awesome, Bryan. I need to add a acceptance/full-stack-integration test, but don’t want the hassle of having to run watir/selenium. I was considering throwing something together with mechanize/hpricot, but now I don’t need to (and this is more full-featured than I’d do for a one-off). :D
February 02, 2008 at 3:03 AM
Hey, I’m working on a post covering the state of view testing and would love to include something about webrat. Working from your README it is not clear how to integrate this library into my spec suite.
is it appropriate to make a new webrat session like so:@webrat = ActionController::Integration::Session.newand then run examples like this?
February 05, 2008 at 5:14 PM
I just started using this today, and it is pretty neat. It seemed to be missing anyhting for radio buttons, so I patched my install with this (in sessions.rb)
and I put this in webrat steps:
It’s ugly and not tested very well but it’s a start.
February 26, 2008 at 5:24 PM
I would like to use webrat with merb – any plans on releasing webrat as a gem?