avinj86
avinj86

Reputation: 45

Rspec issue with should_have_content

I am doing Hartl's Rails tutorial (section 5, listing 5.17) http://www.railstutorial.org/book/filling_in_the_layout#sec-layout_links and am consistently getting a strange series of unexpected errors when I run Rspec. Note that at this stage of the tutorial, one link in the footer partial is intentionally commented out, and the tests should still pass per the tutorial. If I uncomment the the link in the footer partial, the tests all pass, but this doesn't make any sense to me. Anyway, here are the errors:

 rspec ./spec/requests/static_pages_spec.rb:17 # Static pages Home page should not have a custom page title
rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the content 'Sample App'
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the title 'Home'
rspec ./spec/requests/static_pages_spec.rb:52 # Static pages Contact page should have the content 'Contact'
rspec ./spec/requests/static_pages_spec.rb:57 # Static pages Contact page should have the title 'Contact'
rspec ./spec/requests/static_pages_spec.rb:26 # Static pages Help page should have the content 'Help'
rspec ./spec/requests/static_pages_spec.rb:31 # Static pages Help page should have the title 'Help'
rspec ./spec/requests/static_pages_spec.rb:39 # Static pages About page should have the content 'About Us'
rspec ./spec/requests/static_pages_spec.rb:44 # Static pages About page should have the title 'About

This does not make any sense, since when I look at the HTML for each of these pages, the content/title are all clearly there. However, when I look more closely at the logs, I notice that there consistently seems to be an error in the footer partial.

2) Static pages Home page should have the content 'Sample App'
     Failure/Error: visit '/static_pages/home'
     SyntaxError:
       /Users/anant/helpondemand/sample_app2/app/views/layouts/_footer.html.erb:10: syntax error, unexpected '<'
             <li> <a href="http://news.railstutorial.org/">News</a> </li>
              ^
       /Users/anant/helpondemand/sample_app2/app/views/layouts/_footer.html.erb:10: unknown regexp option - l
       /Users/anant/helpondemand/sample_app2/app/views/layouts/_footer.html.erb:11: syntax error, unexpected '<'
           </ul>
            ^
       /Users/anant/helpondemand/sample_app2/app/views/layouts/_footer.html.erb:12: unknown regexp options - av
       /Users/anant/helpondemand/sample_app2/app/views/layouts/_footer.html.erb:13: syntax error, unexpected '<'
       </footer>'.freeze;@output_buffer.to_s
        ^
       /Users/anant/helpondemand/sample_app2/app/views/layouts/_footer.html.erb:13: unterminated regexp meets end of file
     # ./app/views/layouts/application.html.erb:15:in `_app_views_layouts_application_html_erb___4305927437372856517_2202294640'
     # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'

Here is the footer partial in question. Note that a link is intentionally commented out. It doesn't make sense that this many errors should be produced, right? In fact, in the tutorial, the link remains commented out, and the tests all pass.

footer class="footer">
  <small>
    <a href="http://railstutorial.org/">Rails Tutorial</a>
    by Michael Hartl
  </small>
  <nav>
    <ul>
      <li> <%= link_to "About",   '#' %> </li>
      <li> <%=# link_to "Contact", '#' %> </li>
      <li> <a href="http://news.railstutorial.org/">News</a> </li>
    </ul>
  </nav>
</footer>

Any idea what is going on here?

Upvotes: 0

Views: 88

Answers (1)

Frederick Cheung
Frederick Cheung

Reputation: 84114

<%=# is not valid erb.

The only valid way of commenting out bits of erb is

<%# ... %>

If you look carefully at the tutorial it contains

   <li><%#= link_to "Contact", '#' %></li>

Instead of what you have.

Upvotes: 1

Related Questions