English 中文(简体)
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 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.. ;)

问题回答

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.





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签