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

Back on Task

What remains of our definition of done? is the distinction between complete and incomplete tasks. Let’s start with that, with a test for Task:

basics_rspec/03/gatherer/spec/models/task_spec.rb
 
require ​'rails_helper'
 
 
RSpec.describe Task ​do
 
it ​"can distinguish a completed task"​ ​do
 
task = Task.new
 
expect(task).not_to be_complete
 
task.mark_completed
 
expect(task).to be_complete
 
end
 
end

This test makes two assertions, which I normally try to avoid, but the two assertions in this test are pretty intimately related—it would be awkward to separate them. We create a new Task (expecting that it is not complete at this point), then we complete the task and expect that it is, in fact, complete.

By including both assertions ...

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