Returning unsaved records? (e.g. with factory_girl, Factory.build() instead of Factory.create)

3 views
Skip to first unread message

Gabe

unread,
Nov 13, 2009, 3:00:24 PM11/13/09
to pickle
This is less of a question and more of a new feature idea, but I want
to see what people think, or if there's an easier way to accomplish
this.

I'd like to be able to make a Scenario along the lines of

Given an unsaved product: "apples" with name: "Apple", category:
"Fruit"
When I visit the new product page
And I fill in the form with product: "apples"
Then product product: "apples" should exist


This would mostly be useful for testing create forms with lots of
fields, such that I could rely on the factory to supply values for
everything in the form.

Is there any utility in this?

nruth

unread,
Nov 14, 2009, 12:19:22 PM11/14/09
to pickle
I think this is an interesting idea and will have a play around with
it, but will present an alternative first:

To see what happens when you change a particular field you can use
scenario outlines and steps with table arguments, or even simpler by
using the feature background to fill in the form, then in your
particular scenarios change the fields you want to exercise for that
test.

I haven't come across forms where this was not viable. If there are
such forms it may be worth wondering whether they are the best way for
a user to present data to the site, as they may be quite unpleasant to
fill in.

A problem may present itself in virtual attributes - some are written
and not read; this would be worked around by using machinist's plan
functionality (for controller testing). I don't know how it would
apply to factory_girl.

Another problem may be when you start to introduce selection boxes,
tickboxes, and the like. I don't think you can tell from the
attributes how the user interacts with the view to provide them. If
you take this away, then you're really talking about something better
suited to RSpec than Cucumber in my opinion, namely model specs.

Hope that helps

Nick
Reply all
Reply to author
Forward
0 new messages