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
February 13, 2009 at 6:00 am
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
February 15, 2009 at 3:52 pm
Thanks Bryan. Would incorporate this tip in my tests.