Я пытаюсь проверить, сколько ссылок направлено на root_path
. но он продолжает давать 3. Я пытался вынуть все root_path
, проверить, если я что-то пропустил написано, но это выглядело хорошо для меня.
Ошибка
01:11:53 - INFO - Running: test/integration/site_layout_test.rb
Running via Spring preloader in process 88114
Started with run options --seed 8624
FAIL["test_layout_links", #<Minitest::Reporters::Suite:0x00007ffebeae7648 @name="SiteLayoutTest">, 1.9762050000135787]
test_layout_links#SiteLayoutTest (1.98s)
Expected exactly 2 elements matching "a[href="/"]", found 3..
Expected: 2
Actual: 3
test/integration/site_layout_test.rb:8:in `block in <class:SiteLayoutTest>'
1/1: [==================================================================================] 100% Time: 00:00:01, Time: 00:00:01
Finished in 2.02235s
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips
Вот мой код для всех необходимых страниц
IntegrationTest
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
test "layout links" do
get root_url
assert_template 'static_pages/home'
assert_select "a[href=?]", root_path, count: 2
assert_select "a[href=?]", help_path, count: 1
assert_select "a[href=?]", about_path, count: 1
assert_select "a[href=?]", contact_path, count: 1
end
end
_header
<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>
_footer. html .erb
<footer class="footer">
<small>
The <a href="https://www.railstutorial.org/">Ruby on Rails Tutorial</a>
by <a href="https://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="https://news.railstutorial.org/">News</a></li>
</ul>
</nav>
</footer>
application. html .erb
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= render 'layouts/rails_default' %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
</div>
</body>
</html>
rout.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'
end
Home. html .erb
<div class="center jumbotron">
<h1>Welcome to the Sample App</h1>
<h2>
This is the home page for the
<a href="https://www.railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</h2>
<%= link_to "Sign up now!", signup_path, class: "btn btn-lg btn-primary" %>
</div>
<%= link_to image_tag("rails.svg", alt: "Rails logo", width: "200"),
"https://rubyonrails.org/" %>
<%= link_to image_tag("kitten.jpg", alt: "kitten", width: "200") %>
Глобальный поиск по корневому пути Глобальный поиск по корневому пути