Working in ruby '2.5.7' and rails '5.2.3'.
I am having trouble passing the "get index" test for my controller test (code below). I am not sure what is the problem because the other test "get about" works just fine.
Here's my Controller Test file:
class HomeControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get home_path
assert_response :success
end
test "should get about" do
get about_path
assert_response :success
end
end
Here's the outcome after running "rails test":
HomeControllerTest
test_should_get_about PASS (0.03s)
HomeControllerTest
test_should_get_index FAIL (0.13s)
Minitest::Assertion: Expected response to be a <2XX: success>, but was a <500: Internal Server Error>
test/controllers/home_controller_test.rb:7:in `block in <class:HomeControllerTest>'
If it helps, this is my routes.rb file in the config folder:
Rails.application.routes.draw do
get 'home', to: 'home#index', as: :home
get 'home/about', to: 'home#about', as: :about
end
This is my home_controller.rb file:
class HomeController < ApplicationController
def index
end
def about
end
end
And lastly, I have the following files in my views directory:
I've tried a lot of things but none of them seem to resolve this issue. I'm mainly baffled as to why the "about" test is working while the "index" test is not (even though they're both handled in a similar manner...)
Thank you!
I just realized my stupid mistake😅
Thank you @Vasilisa for pointing me in the right direction!
In 'home/index.html.erb' (within my views directory), I had accidentally referenced another path that was not listed in my 'routes.rb' file. Removing that from 'home/index.html.erb' immediately resolved the problem. This explains why my "about" test was working but my "index" test was not...
(Previously I wasn't aware that the controller test would care about the contents of the Views - especially when my controller test is so basic.)