2016-08-24 2 views
1

リスト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>' 
+0

この宿題ですか? –

答えて

0

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

詳細情報をルートと自宅が同じが表示されますので、<Home | Ruby on Rails Tutorial Sample App>を探すために、それを伝えるべきです。

1

root_urlで動作させることができました。あなたは、ホームページを提供していることをroutes.rbにチェックしたいかもしれません。

1

あなたの静的なページコントローラにあるあなたのホームページに行くことを将来指示している人は、他のテストの構文をコピーします。 。

test "should get root" do 
    get static_pages_home_url 
    assert_response :success 
    end 
0

これは完全なソリューションです(それが動作する保証)

test "should get root" do 
    get root_url 
    assert_response :success 
    assert_select "title", "Home | #{@base_title}" 
    end 
関連する問題