21 Dec '13, 11am

Cleanup up your factory girl with traits.

Remove Duplication with FactoryGirl's Traits Josh Clayton May 24, 2012 factory girl testing traits ruby rails FactoryGirl 's traits are an outstanding way to DRY up your tests and factories by naming groups of attributes, callbacks, and associations in one concise area. Imagine defining factories but without the attributes backed by a specific object. Here's a basic example of a factory with two traits: FactoryGirl.define do factory :todo_item do name 'Pick up a gallon of milk' trait :completed do complete true end trait :not_completed do complete false end end end This would allow you to declare a complete or incomplete todo item very easily: create(:todo_item, :completed) create(:todo_item, :not_completed) Pretty handy, eh? The other way to go about this would be to have different factories altogether for complete and incomplete: FactoryGirl.define do factory :todo_item,...

Full article: http://robots.thoughtbot.com/remove-duplication-with-fact...

Tweets

Get Your Callbacks On with Factory Girl 3.3:

robots.thoughtbot.com 26 Dec '13, 11pm

Get Your Callbacks On with Factory Girl 3.3 Josh Clayton May 15, 2012 factory girl callbacks rails testing FactoryGirl 3.3...