Managing Sample Data with Fixtures and Factories

Part of Screencast Series: RSpec

Published December 2015

Testing isn't complete without data

You’ve set up RSpec for your new Rails project but… what about data? You can’t write much tests without having some sample data and therefore we need a way to deliver them! However, what would be the optimal solution? Should we type them by hand? Should we generate them somehow?

In this video you are going to learn about two ways of managing sample data: fixtures and factories. Apart from that, you’ll learn about annotate gem to add annotations for models and specs, and faker to easily generate fake data. Testing continues!

Code samples can be found in GitHub:

Free Setting Up Automated Testing with RSpec 18:48
Managing Sample Data with Fixtures and Factories 18:29
Free Testing Your Rails App Models with RSpec 17:06
Free Testing Views, Routes, and Helpers for Problems in Your Rails App 12:54
Free Ensure Functionality with RSpec Controller Testing 13:49
Free Feature Tests with RSpec: Simulate User Behavior and Test Your Ruby App 17:01


Have your say! or become a member now to take part in the discussion

Meet your instructor
Ilya Bodrov-Krukowski

Ilya is a lecturer at MATI-RSTU, senior engineer at Campaigner LLC and seasoned author at SitePoint. When Ilya is not working away on new projects or contributing to open source projects, he's expanding and refining his skills in HTML, CSS, jQuery, Angular, Backbone and Rails. You can read all about his work and development discoveries on his blog Radiant Wind.