教材
Railsチュートリアル5章 バージョンRails5
実行コード
% rails test:integration
エラーメッセージ
db/schema.rb doesn't exist yet. Run rails db:migrate
to create it, then try again. If you do not intend to use a database, you should instead alter /Users/ユーザー名/workspace/アプリ名/config/application.rb to limit the frameworks that will be loaded.
Started with run options --seed 29793
FAIL["test_layout_links", SiteLayoutTest, 0.3230340000009164]
test_layout_links#SiteLayoutTest (0.32s)
Expected exactly 2 elements matching "a[href="/"]", found 4..
Expected: 2
Actual: 4
test/integration/site_layout_test.rb:7:in `block in class:SiteLayoutTest'
1/1: [=====================================================================================================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.32359s
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips
integrationファイル
require
1class SiteLayoutTest < ActionDispatch::IntegrationTest 2 test "layout links" do 3 get root_path 4 assert_template 'static_pages/home' 5 assert_select "a[href=?]", root_path, count: 2 6 assert_select "a[href=?]", help_path 7 assert_select "a[href=?]", about_path 8 assert_select "a[href=?]", contact_path 9 end 10end
_header.html.erb(テストが通らないパターン)
<div class="container"> <%= link_to "stapro-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 "Login", '#' %></li> </ul> </nav> </div> </header>
_header.html.erb(テストが通るパターン)
<div class="container"> <%= link_to "stapro-app", '#', id: "logo" %> <nav> <ul class="nav navbar-nav navbar-right"> <li><%= link_to "Home", '#' %></li> <li><%= link_to "Help", help_path %></li> <li><%= link_to "Login", '#' %></li> </ul> </nav> </div> </header>
このようにroot_pathを‘#’に変更したら、うまくテストが通るのですが
root_pathで通るようにしたいです
質問の仕方もわからなく申し訳ありませんがよろしくお願いいたします。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。