Webrat is library to write acceptance tests for ruby web applications. I also like shoulda for its context. However using the two in conjunction has been little fun. I wanted to multiple sessions testing. Following is the code I used to get it done using shoulda and webrat. It might turn out to be useful example for some.

require File.dirname(__FILE__) + '/../test_helper'

class UserStories  'some@one.com'
      fill_in "password", :with => "idunno"
      click_button
      assert_equal '/session', path
    end
  end

  context 'A User' do
    setup do
      visit "login"
      assert_response :success
      fill_in "email",:with => users(:tom).email
      fill_in "password", :with => "123456"
      click_button
      assert_equal '/profile', path
    end

    should 'be able to login with valid email and password' do
      visit 'forums/new'
      assert_response :success
    end
  end

end

  1. One quick tip…

    Webrat automatically verifies that the response is not an error, so you don’t need to do “assert_response :success”

    Cheers,

    -Bryan

  1. 1 Mindtonic » Webrat for integration testing

    [...] http://gitrdoc.com/brynary/webrat/tree/master http://codese.wordpress.com/2009/02/05/using-shoulda-webrat-to-write-integration-tests-for-rails/ [...]




Leave a Comment