Form Test Helper Plugin

This week I found the FormTestHelper plugin by Jason Garber. It both enhances and simplifies form testing in Rails functional and integration tests. The great thing is the FormTestHelper tests the form, not just the submission of the form data. For example, if you try to set a form element that doesn’t exist, an error is thrown.

Here’s my first pass at using FormTestHelper:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
assertions = proc do |response|
  assert_response(response)
  assert(exhibit = assigns(:exhibit), 
   "Should have assigned :exhibit")
  assert(exhibit.errors.empty?, 
   "@exhibit should not have errors: #{exhibit.errors.inspect}")
end

exhibit_count = Exhibit.count
get(:new)
assertions.call(:success)

submit_form('new_exhibit') do |f|
  f.exhibit.title = "New Exhibit"
  f.exhibit.exhibit_type_id = 1
  f.exhibit.license_id = 1
  f.exhibit.annotation = "Exhibit notes."
end

assert_equal(exhibit_count += 1, Exhibit.count )
assertions.call(:redirect)
assert_redirected_to(edit_exhibit_path(assigns(:exhibit)))
assert(flash[:notice])
Advertisements

0 Responses to “Form Test Helper Plugin”



  1. Leave a Comment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Pages

Categories

Copyright ©2008-2013 James E Orchard-Hays, All Rights Reserved

%d bloggers like this: