Search code examples
ruby-on-railsunit-testingguard

guard error ActionController::UrlGenerationError:


I am starting to write tests for my rails application, and plan to write them prior to building the actual pages, but I am having trouble. I have searched stack overflow and google and have tried several things. The route is specified in my routes.rb file and looks like:

resources :welcome

I have the following written into my test code.

require 'rails_helper'
require 'spec_helper'

RSpec.describe "Welcomes", type: :request do
  it "checks the welcome page." do
    visit welcome_path
  end
end

I get the following Error from guard:

Failures:

  1) Welcomes checks the welcome page.
     Failure/Error: visit welcome_path
     ActionController::UrlGenerationError:
       No route matches {:action=>"show", :controller=>"welcome"} missing required keys: [:id]
     # ./spec/requests/welcomes_spec.rb:6:in `block (2 levels) in <top (required)>'

Finished in 0.00347 seconds (files took 1.61 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/requests/welcomes_spec.rb:5 # Welcomes checks the welcome page.

Solution

  • Change visit welcome_path to get '/welcome'