Minitest Setup

One of the clearest differences between the RSpec way and the Minitest way is how you set up different data for different tests. In RSpec, the describe method is used to enclose an arbitrary number of tests for the purpose of giving each group of tests a different setup. For example, your Project specs in spec/models/project_spec.rb has three different groups, one without a task, one with a task, and one with a bunch of tasks.

In Minitest, each class has one setup method. (Technically, you can define multiple setup do blocks, but all of them are executed for all tests—you can’t use Minitest setup to have different setups for different tests.) While you could solve this problem by putting each setup in a different class, I think ...

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.