views:

104

answers:

1

Hi all,

Just wanted to get some opinions on how to go about testing an extremely long form with 20+ required fields. It seems like my Cucumber scenario could be like 25 lines long if I tried to describe every field that need to be filled in (something like "And I fill in "Name:" with blah, And I fill in "Address" with foo, etc.).

If I simply say "When I provide all required information" as one of the Cucumber steps - it seems a little empty, but it keeps things clean. I then use Factory Girl to create a factory to represent a valid object, to test in cucumber steps and in model specs. Additionally I have model specs to make sure all required fields are included in the creation of the new object.

Question #1 - Does this suffice?

Question #2 - If I have 20+ required fields (this form collects a lot personal contact / history info), do you write a 20+ tests in your rspec model test to ensure each one of those fields is properly accounted for?

I know I cheated, asking 2 questions.. ;)

+1  A: 

You want to test that, when a User fills in the form and presses "Submit" that the app does the right thing based on the information submitted, right?

Assuming you are working on a rails app using the standard Cuke + Webrat combo, you can do:

Background: Login, go to really long form
  Given the user "Fred exists" # Factory a user into existance, something like @user = Factory(:user, :username => "Fred"
  And I am on the "Really long form" page # map "Really long form page" in /features/supposrt/paths.rb

Scenario: Succesfully fill in really long form
  When I fill in the following: # This is defined in Webrat steps
  | field 1  | response 1  |
  | field 2  | response 2  |
...
  | field 19 | response 19 |
  | field 20 | response 20 |

  And I press "Save"
  Then I should see a "success" message # assert there is a div with the calss success. Could be an error message
  And "Fred" should have a valid set of attributes # because you defined @user, you can call whatever assertions you like here i.e. assert equal @user.username, "Fred" (I forget the correct syntax for doing this, but you get the idea).

Does that help?

Rodreegez