I’ve kept factory_girl in my testing toolkit for some time now, and recently, I started using guard to run my tests automatically as I make changes. I wanted guard to run the appropriate model, controller and request specs when I change a particular factory. Guard doesn’t know what to do with factory files by default, so I added the following to my Guardfile:
By convention, my factories are named after the plural form of the model name, and the files live in spec/factories, so, for example, my User factories are defined in spec/factories/users.rb. I require active_support/inflector at the top of the Guardfile because I need access to String#singularize to convert the plural factory name (also used in the name of controller and request specs) into the singular model name. Then I call #watch with the pattern matching the factory files and use the name of the factory to build the array of specs that need to be run.
© 2012 John Parker | Valid XHTML 1.0 Strict | Valid CSS 2.1