Skip to Main Content
Rails 5 Test Prescriptions
book

Rails 5 Test Prescriptions

by Noel Rappin
February 2018
Intermediate to advanced content levelIntermediate to advanced
406 pages
9h 52m
English
Pragmatic Bookshelf
Content preview from Rails 5 Test Prescriptions

A Note on Assertions per Test

You’ll often find that a common setup results in multiple assertions in a test. This is particularly true of integration tests. For example, when you wrote your initial test to add tasks back in Chapter 3, Test-Driven Rails, you made several assertions about the existence of the project and its relationship with the tasks you’d just created.

There are two contrasting styles for writing tests with multiple assertions. In one style, the setup and all the assertions are part of the same test. If you were trying to test changes when you mark a task complete, then having all the assertions in the same test might look like this:

 it ​"marks a task complete"​ ​do
  task = tasks(​:incomplete​)
  task.mark_complete
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rails 4 Test Prescriptions

Rails 4 Test Prescriptions

Noel Rappin
Agile Web Development with Rails 5.1

Agile Web Development with Rails 5.1

Sam Ruby, David B. Copeland, Dave Thomas
Rspec Essentials

Rspec Essentials

Mani Tadayon

Publisher Resources

ISBN: 9781680505566Errata Page