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

The Second Test

One nice feature of test-driven development is that making one test pass often points the way to the next test. The goal of the next test cycle is to write a test that fails given the current code. At this point the code says that done? is always true, so we should create a case where done? is false.

basics_rspec/02/gatherer/spec/models/project_spec.rb
 
it ​"knows that a project with an incomplete task is not done"​ ​do
 
project = Project.new
 
task = Task.new
 
project.tasks << task
 
expect(project.done?).to be_falsy
 
end
 
end

This test is similar to the first one, but now we have a second class, Task, and a related attribute of the Project class, tasks. This time we’re assuming that a new task is undone, and therefore ...

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