开发者

Guidance on testing extremely long form with 20+ required fields, using Rspec / Cucumber

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 fac开发者_高级运维tory 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.. ;)


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?


I think you do want your test to actually fill in all the fields, to assure that all the fields are actually present on the form and will accept valid data.

Assuming that some fields are required and some are optional, I would probably have three tests: one that fills in every field, one that fills in only the required field, and one that omits one of the required fields. Maybe a fourth test to cover submitting the button with no fields at all filled in if it seems useful. That should assure you that you aren't requiring too many fields, and may alert you to change the view if you later change the model to require more fields or fewer fields, and assure that you can display a nice error message if a required field is missing. But you can save the individual field requirements for the model specs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜