Mr Rails Mr Rails - 1 year ago 69
Ruby Question

Getting a rails test to pass

Following a rails tutorial but when off on a slight tangent and now cant get a test to pass.
Below is my routes file and my test file. The

test is failing and this line
, to: "static_pages#home", as: "home"
is the line that makes it appear. i.e remove this and it'll pass. I was wondering why someone could explain why this is failing and how to alter the test to make it pass but keeping this line in?

My routes file:

Rails.application.routes.draw do

resources :static_pages
get 'static_pages/help'
get 'static_pages/test'
get 'static_pages/home', to: "static_pages#home", as: "home"
root 'application#hello'


My test file:

require 'test_helper'

class StaticPagesControllerTest < ActionDispatch::IntegrationTest
test "should get home" do
get static_pages_home_url
assert_response :success

test "should get help" do
get static_pages_help_url
assert_response :success

test "should get test" do
get static_pages_test_url
assert_response :success


Answer Source

static_pages_home_url is the default helper method for that route with controller static_pages and action home but you set the name as home so your test should be

test "should get home" do
  get home_url
  assert_response :success
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download