添加根路径清单3.41导致创建一个Rails助手叫root_url(按类似于像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>'
这是功课? –