O'Reilly logo

Rails 4 Test Prescriptions by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6Adding Data to Tests

Creating test data sounds like it should be the easiest thing ever. We already have ActiveRecord#create, right? Not quite. To be useful, the data that 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 is the only way you get data into your tests, you’re going to have some problems. These problems include ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required