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'â |
â2Â | |
â3Â | RSpec.describe ProjectsController, type: :controller âdoâ |
â4Â | |
â5Â | describe â"POST create"â âdoâ |
â6Â | it â"creates a project"â âdoâ |
â7Â | post :create, project: {name: â"Runway"â, tasks: â"Start something:2"â} |
â8Â | expect(response).to redirect_to(projects_path) |
â9Â | 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 ...
Get Rails 4 Test Prescriptions now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.