2

I am a beginner and am trying to test whether the following code maps to the "home page":

Rails.application.routes.draw do
  root 'static_pages#home'
end

what should I replace the first and second "FILL_IN" with in the block below?

test "should get root" do
    get FILL_IN
    assert_response FILL_IN
end

Would appreciate your help!

1

1 Answer 1

8

I assume you are following the "Ruby on Rails Tutorial" by Micheal Hartl?

Specifically this step: Listing 3.42: A test for the root route


Although not explicitly disclosed in the tutorial (correct me if im wrong)...

I believe the solution below will pass your test. I tried it myself to double check.

test "should get root" do
  get '/'
  assert_response :success
end

Additional reading can be found here: Rails Guide - Integration Tests


Similar Posts: By filling in the code marked FILL_IN in Listing 3.42, write a test for the root route

Thanks @AlterLagos

3
  • 1
    Thanks Nathan! it worked! Yes, I am following "Ruby on Rails Tutorial" .
    – rstreet
    Dec 7, 2016 at 19:14
  • 1
    Is there also a way to assert that the view that was rendered was indeed home.html.erb, and not just the render html: 'Hello, world!' string?
    – Alexander
    Oct 16, 2019 at 15:22
  • This depends on how you define the "/" route and the file routed to. Common naming conventions usually point the "/" route to a home page (Ex: home.html.erb). Oct 25, 2019 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.