railsチュートリアルをやっていて、第5章のリンクのテストでつまづいています。
require 'test_helper' class SiteLayoutTest < ActionDispatch::IntegrationTest test "layout links" do get root_path assert_template 'static_pages/home' assert_select "a[herf=?]", root_path, count:2 assert_select "a[herf=?]", help_path assert_select "a[herf=?]", about_path assert_select "a[herf=?]", contact_path get contact_path assert_select "title", full_title("Contact") get signup_path assert_select "title", full_title("Signup") end end
テスト結果は以下のようになります。
(base) rails test:integration Started with run options --seed 31491 FAIL["test_layout_links", SiteLayoutTest, 0.39078600000357255] test_layout_links#SiteLayoutTest (0.39s) Expected exactly 2 elements matching "a[herf="/"]", found 0.. Expected: 2 Actual: 0 test/integration/site_layout_test.rb:8:in `block in <class:SiteLayoutTest>' 1/1: [=======================================] 100% Time: 00:00:00, Time: 00:00:00 Finished in 0.39166s 1 tests, 2 assertions, 1 failures, 0 errors, 0 skips
このテスト結果のFAILはどのようなことを言っているのでしょうか?
リンク2つあると書いてあるけど、実際は0だよーと返しているのでしょうか?
サーバーにアクセスしてリンクを押して実際に調べても、リンクが全て合っているので、テストの書き方が間違っているのでしょうか?
下記がconfig/routes.rbになります
Rails.application.routes.draw do root 'static_pages#home' get '/help', to:'static_pages#help' get '/about', to:'static_pages#about' get '/contact', to:'static_pages#contact' get '/signup', to:'users#new' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end
app/views/layouts/application.html.erb
<!DOCTYPE html> <html> <head> <%= render 'layouts/head' %> </head> <body> <%= render 'layouts/header' %> <div class="container"> <%= yield %> <%= render 'layouts/footer' %> </div> </body> </html>
app/layouts/_header.html.erb
<header class="navbar navbar-fixed-top navbar-inverse"> <div class="container"> <%= link_to "sample app", root_path, id: "logo" %> <nav> <ul class="nav navbar-nav navbar-right"> <li><%= link_to "Home", root_path %></li> <li><%= link_to "Help", help_path %></li> <li><%= link_to "Log in", '#' %></li> </ul> </nav> </div> </header>
app/layouts/_footer.html.erb
<footer class="footer"> <small> The <a href="https://railstutorial.jp/">Ruby on Rails Tutorial</a> by <a href="http://www.michaelhartl.com/">Michael Hartl</a> </small> <nav> <ul> <li><%= link_to "About", about_path %></li> <li><%= link_to "Contact", contact_path %></li> <li><a href="http://news.railstutorial.org/">News</a></li> </ul> </nav> </footer>
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー