A Test with a View

Learn how to add some more tests, code for the view, and view tests, and learn about refactoring the code.

Making the test pass

Let’s look at that end-to-end test again:

Press + to interact
require "rails_helper"
RSpec.describe "adding a project", type: :system do
it "allows a user to create a project with tasks" do
visit new_project_path
fill_in "Name", with: "Project Runway"
fill_in "Tasks", with: "Choose Fabric:3\nMake it Work:5"
click_on("Create Project")
visit projects_path
expect(page).to have_content("Project Runway")
expect(page).to have_content(8)
end
end

So far, this test passes up to the point where the code completes the controller create action. At the end of that action, it redirects to projects_path, which we didn’t know when we started the end-to-end test, and it might mean that we don’t need to explicitly visit projects_path in the test. Either way, projects_path triggers a visit to the path /projects, which is routed to the index method of the ProjectController. Since there isn’t an index method, the current error is The action 'index' could not be found for ProjectsController.

We need the ...