michael hartl 3rd edition 5.26 test failure site_layout test showing no about path

555 Views Asked by At

I'm following along through the tutorial and my site links work, but the only site_layout link test that doesn't pass is /about path. I checked over my routes file, footer file and site_layout_test and can't seem to find whats wrong

     1) Failure:
     SiteLayoutTest#test_layout_links        [/home/ubuntu/workspace/sample_app/test/integration/site_layout_test.rb:10]:
Expected at least 1 element matching "a[href="/about"]", found 0..
Expected 0 to be >= 1.

    Rails.application.routes.draw do
       root 'static_pages#home'

       get 'help' => 'static_pages#help'

       get 'about' => 'static_pages#about'

       get 'contact' => 'static_pages#contact'

<footer class="footer">
  <small>
  The <a href= "http://www.railstutorial.org/">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>

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
3

There are 3 best solutions below

2
On BEST ANSWER

This seems to be a bug that common bug with the cloud 9 ide. I double checked every view file and my integration tests find 3 links to root_path when there are only 2. If you run the tests on your a local app inside your local rails console, they work. c9's console is not correct.

0
On

I just checked the tutorial and found that if you remove "count: 2" from site_layout_test.rb test would pass.Place this in your " /home/ubuntu/workspace/sample_app/test/integration/site_layout_test.rb" 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
assert_select "a[href=?]", help_path
assert_select "a[href=?]", about_path
assert_select "a[href=?]", contact_path
end
0
On

Just to be sure... You didn't say you checked your view file (about.html.erb), with the code: <% provide(:title, "About") %> Maybe something misspelled in the title here? Caps/lowercase?