pickle refs to factories

7 views
Skip to first unread message

Erich

unread,
Oct 19, 2010, 7:58:50 PM10/19/10
to pickle
This is to some extent just a 'golden rule' post--the one I wish I'd
seen when I started hitting issues. Of course, I'm sure there's room
for improvement--I'm in no way qualified to say "this is how you do
it". I can only say, this is how I got past some error messages. So
refinements would be of interest.

I was using the Rspec book as a starting point, but it doesn't go very
far into topics like using models in cucumber tests.

the relevant part of Gemfile is:

group :development, :test, :cucumber do
gem "rspec-rails", ">= 2.0.0.beta.19"
gem 'factory_girl_rails'
gem "cucumber-rails", ">= 0.3.2"
gem "webrat", ">= 0.7.2.beta.1"
gem 'pickle'
end

(the :cucumber part might well not be needed)




#sequence to satisfy uniqueness, self reference for confirmation and
email
Factory.define :user do |f|
f.sequence(:username) {|n| "test_user#{n}"}
f.password "test"
f.password_confirmation { |u| u.password }
f.email { |u| "#{u.username}@testers.org"}
end


Factory.define :contact_start, :class => Contact do |f|
f.sequence(:startfirstname) {|n| "Starter_#{n}"}
f.startlastname "User"
f.startemail {|c| "#{c.startfirstname}@test.org"}
#...
end

# user-contact join model, associations to allow auto creation of
related models
Factory.define :user_contact do |f|
f.association :user
f.association :contact, :factory => :contact_start
end


Now the goal is just to test factory visibility, referencing syntax,
etc.

Feature: Contact Editing
Cucumber should be able to use factories.

Scenario: Fire up the factories
Given the following contact_starts exist:
|contact_start |startfirstname | startlastname |
| Bob | Bob | Test |
| Sally | Sally | Test |
And the following users exist:
| user | username |
| foo | foo |
And the following user_contacts exist:
| user | contact |
| user: "foo" | contact: "Bob" |
| user: "foo" | contact: "Sally" |
Then 2 contacts should exist
And 1 users should exist
# undefined if users isn't pluralized
And 2 user_contacts should exist

Big notes--model name column to create pickle refs, see user_contacts
for how to make use of those refs, and note the required
mispluralization on users in the Then step.

Then there were some edits required to get webrat working with Rails
3. One to features/support/env.rb and one to webrat's /lib/webrat/
core/session.rb Those seem tangential here, and "webrat Rails 3" is
enough to find them so I'll skip over them.

# because When I go to "Sally"'s edit page isn't supported (yet)
(right?)
Then a contact "Sally" should exist with startfirstname: "Sally"
When I go to the contact's edit page

Is enough for me to hit the authlogic/declarative_authorization hurdle
so that's next.
Reply all
Reply to author
Forward
0 new messages