24 May '12, 5pm

Remove Duplication with FactoryGirl’s Traits:

May 24, 2012 Tagged: factory girl testing traits ruby rails Comments (View) Remove Duplication with FactoryGirl’s Traits 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 ...

Full article: http://robots.thoughtbot.com/post/23673635798/remove-dupl...

Tweets

How to Remove a Bat from Indoors

How to Remove a Bat from Indoors

treehugger.com 29 May '12, 9am

Few other mammals can strike a streak of fear in the heart quite like a bat can. And even the most bat-loving of us might ...