[ANN] Webrat 0.1.0 released - Ruby Acceptance Testing for Web applications

Hey guys,

We developed this plugin while writing my first real set of RSpec
stories. It’s still missing a lot of functionality, but it’s useful to
us as is, so I’m shipping 0.1.0. (Patches welcome. :slight_smile: )

Code is available at: http://svn.eastmedia.net/public/plugins/webrat/

What do you think?

-Bryan

Here’s the README:


= Webrat - Ruby Acceptance Testing for Web applications

by Bryan H. [email protected] and Seth Fitzsimmons
[email protected].

Initial development sponsored by EastMedia (http://www.eastmedia.com).

== DESCRIPTION:

Webrat lets you quickly write robust and thorough acceptance tests for a
Ruby
web application. By leveraging the DOM, it can run tests similarly to an
in-browser testing solution without the associated performance hit (and
browser dependency). The result is tests that are less fragile and more
effective at verifying that the app will respond properly to users.

When comparing Webrat with an in-browser testing solution like Watir or
Selenium, the primary consideration should be how much JavaScript the
application uses. In-browser testing is currently the only way to test
JS, and
that may make it a requirement for your project. If JavaScript is not
central
to your application, Webrat is a simpler, effective solution that will
let you
run your tests much faster and more frequently. (Benchmarks
forthcoming.)

== SYNOPSIS:

def test_sign_up
visits “/”
clicks_link “Sign up”
fills_in “Email”, :with => “[email protected]
select “Free account”
clicks_button “Register”

end

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 to
    a
    successful page
  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
    option for
    “Free account”
  6. Verify that there is a “Register” submit button on the page
  7. Verify that submitting the Sign Up form with the values
    [email protected]
    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.

== REQUIREMENTS:

  • Rails >= 1.2.6
  • Hpricot >= 0.6
  • Rails integration tests in Test::Unit or
  • RSpec stories (using an RSpec version >= revision 2997)

== INSTALL:

$ ruby script/plugin install
http://svn.eastmedia.net/public/plugins/webrat/

== HISTORY:

See CHANGELOG in this directory.

== LICENSE:

Copyright (c) 2007 Bryan H., Seth Fitzsimmons.
See MIT-LICENSE in this directory.

On 11/29/07, Bryan H. [email protected] wrote:

Hey guys,

We developed this plugin while writing my first real set of RSpec
stories. It’s still missing a lot of functionality, but it’s useful to
us as is, so I’m shipping 0.1.0. (Patches welcome. :slight_smile: )

Code is available at: http://svn.eastmedia.net/public/plugins/webrat/

What do you think?

Nice! I’m really excited to try this out.

Pat

We’ve been putting something similar together here:

http://faithfulcode.rubyforge.org/svn/plugins/trunk/spec_integration/

It’s for integration testing. The README talks about the navigate_to,
submit_form, and be_showing methods.


John L.
http://wiseheartdesign.com

Code is available at: http://svn.eastmedia.net/public/plugins/webrat/

  • Rails integration tests in Test::Unit or
  • RSpec stories (using an RSpec version >= revision 2997)

I had to add:

require ‘cgi’
require “cgi/session”
require ‘cgi/session/pstore’
require ‘action_controller/cgi_ext/cgi_methods’

in the beginning of lib/webrat/session.rb to get rid of the following
error:

NameError: uninitialized constant

ActionController::Integration::Session::CGIMethods
/Users/jcf/dev/work/quevita/vendor/rails/activerecord/lib/…/…/
activesupport/lib/active_support/dependencies.rb:478:in const_missing' /Users/jcf/dev/work/quevita/vendor/plugins/webrat/lib/webrat/ session.rb:107:in add_form_data’
/Users/jcf/dev/work/quevita/vendor/plugins/webrat/lib/webrat/
session.rb:175:in `add_default_params_for’

nice work!

Jens-Christian

On Nov 30, 2007 3:28 PM, Jens-Christian F.
[email protected] wrote:

require ‘cgi/session/pstore’
require ‘action_controller/cgi_ext/cgi_methods’

You could also apply this patch instead:

diff -r 80ee2d7fc95d -r 617747be70b6
vendor/plugins/webrat/lib/webrat/session.rb
— a/vendor/plugins/webrat/lib/webrat/session.rb Tue Dec 04 13:53:46
2007 -0600
+++ b/vendor/plugins/webrat/lib/webrat/session.rb Tue Dec 04 14:04:50
2007 -0600
@@ -102,7 +102,12 @@ module ActionController

   def add_form_data(input_element, value) # :nodoc:
     form = form_for_node(input_element)
  •    data =
    

CGIMethods::parse_query_parameters(“#{input_element.attributes[“name”]}=#{value}”)

  •    if defined?(CGIMethods)
    
  •      parser = CGIMethods
    
  •    else
    
  •      parser = request.class
    
  •    end
    
  •    data =
    

parser.parse_query_parameters(“#{input_element.attributes[“name”]}=#{value}”)
merge_form_data(form_number(form), data)
end

/me in love
:slight_smile: