Factory Girl - fixtures replacement for focussed and readable tests
Why Factory Girl:
- Fixtures separates the data we are testing with actual behavior
- Makes tests brittle and you have to look at fixture files to understand the tests, which is certainly not the intent for the tests
- Its painful to have fixtures maintained for each model
- You have to keep switching between files to see what fixtures there are, always struggling with dependencies and conflicts
How to get started:
- gem install thoughtbot-factory_girl --source http://gems.github.com
- Add the following code to your test environment file ---> config.gem "thoughtbot-factory_girl", :lib => "factory_girl", :source => http://gems.github.com
- Add test/factories.rb if using UnitTesting framework or spec/factories.rb if using Rspec framework. It will be automatically loaded if defined at this location
- Ryan Bates has an excellent screencast @ http://railscasts.com/episodes/158-factories-not-fixtures
- Excellent documentation
No comments:
Post a Comment