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

Testing Controllers

We’ve already written a few controller tests as part of our earlier testing walkthroughs. Let’s take a look at one of them:

display/01/gatherer/spec/controllers/projects_controller_spec.rb
Line 1 
require ​'rails_helper'
RSpec.describe ProjectsController, type: :controller ​do
describe ​"POST create"​ ​do
it ​"creates a project"​ ​do
post :create, project: {name: ​"Runway"​, tasks: ​"Start something:2"​}
expect(response).to redirect_to(projects_path)
expect(assigns(:action).project.name).to eq(​"Runway"​)
10 
end

This test is simple but has most of the features of a basic controller test. Like many tests we have seen, controller tests have three parts. First, the controller test may create data ...

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