Chapter 6Adding Data to Tests

Creating test data sounds like it should be the easiest thing ever. I mean, we already have ActiveRecord#create; isn’t that enough? Not quite. To be useful, the data you generate for your tests needs to support the goals of testing. You should be able to create the data quickly and easily, both in the amount of typing it takes to create data and the speed at which the test runs. The data should be the same every time you generate it, should be specific to a set of tests, and should be an accurate representation of the objects that will be used when the code runs outside of tests.

Nothing against ActiveRecord#create, but if it’s the only way you get data into your tests, you’re going to have some problems. These ...

Get Rails 5 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.