I'm trying to check how many links are routed to root_path here is my code for the integration test. My question is why is every route in my _header.html.erb file, when counted by assert_select is being doubled. root_path is used in the page twice <%= link_to "sample app", root_path, id: "logo" %> and
- <%= link_to "Home", root_path %>
- so why is it giving me 4? I'm new to rails and i'm follwing hartls tutorial.
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
test "layout links" do
get root_path
assert_template 'static_pages/home'
assert_select "a[href=?]", root_path, count:2
assert_select "a[href=?]", help_path
assert_select "a[href=?]", about_path
assert_select "a[href=?]", contact_path
end
end
and this is the partial code for my html file (_header.html.erb)
<header class="nav-bar navbar-fixed-top navbar-inverse" id="header">
<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>
when I run bundle exec rake test it gives me 1 failure which is
FAIL["test_layout_links", SiteLayoutTest, 2016-06-15 20:11:58 +0800] test_layout_links#SiteLayoutTest (1465992718.76s) Expected exactly 2 elements matching "a[href="/"]", found 4.. Expected: 2 Actual: 4 test/integration/site_layout_test.rb:6:in `block in '
Aucun commentaire:
Enregistrer un commentaire