リスト3.41のルートルートを追加すると、root_urlという名前のRailsヘルパーが作成されます(static_pages_home_urlのようなヘルパーと同様です)。コードリスト3.42のFILL_INと記されたコードを記入して、ルートルートのテストを作成します。リスト3.42のFILL_INのコードを記入し、ルートルートのテストを書く
Listing 3.41: Setting the root route to the Home page.
config/routes.rb
Rails.application.routes.draw do
root 'static_pages#home'
end
Listing 3.42: A test for the root route. green
test/controllers/static_pages_controller_test.rb
require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest
test "should get root" do
get FILL_IN
assert_response FILL_IN
end
end
何がFILL_INであるべきですか? 私はstatic_pages_root_url、root_urlを試しました。
rails test fails.
F
Failure:
StaticPagesControllerTest#test_should_get_root [/home/ubuntu/workspace/sample_app/test/controllers/static_pages_controller_test.rb:12]:
<Root | Ruby on Rails Tutorial Sample App> expected but was
<Home | Ruby on Rails Tutorial Sample App>..
Expected 0 to be >= 1.
E
Error:
StaticPagesControllerTest#test_should_get_root:
ArgumentError: Invalid response name: root_url
test/controllers/static_pages_controller_test.rb:11:in `block in <class:StaticPagesControllerTest>'
この宿題ですか? –