I'm working through Michael Hartl's Ruby on Rails Tutorial. Chapter 5 introduces an integration test that looks like this:
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
The routes look like this:
root 'static_pages#home'
get '/help', to: 'static_pages#help'
get '/about', to: 'static_pages#about'
get '/contact', to: 'static_pages#contact'
The rendered page contains these lines ...
<a id="logo" href="/">Sample app</a>
<li><a href="/">Home</a></li>
<li><a href="/help">Help</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
... obviously among other markup.
The integration test, however, shows this error:
FAIL["test_layout_links", Minitest::Result, 0.2899387989891693]
test_layout_links#Minitest::Result (0.29s)
Expected exactly 2 elements matching "a[href="/"]", found 0..
It sure seems to me as if everything is in order. The test says to expect two links, and the page contains them. If I comment out the root_path test, the help_path test fails as well - but that link is in the page as well. Same thing happens down the line with the other tests, too.
I've looked at a few other descriptions of problems in the same area, and none of them seem to apply. Is there something subtle (or otherwise) that I'm missing?
Aucun commentaire:
Enregistrer un commentaire