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

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 we created a new project we asserted that the project existed and had a specific relationship with newly created tasks.

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 we were trying to test changes when we 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
 
expect(task).to be_complete
 
expect(task).to be_blocked
 
expect(task.end_date).to eq(Date.today.to_s(:db)) ...

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