0
votes

I'm new on StackOverflow as I've recently begun to learn Ruby on Rails with Michael Hartl's Tutorial. I can't seem to pass the test of listing 8.25 ("At this point, the test suite should still be GREEN:" $ bundle exec rake test):

My test is RED and the error is as follows:

~/workspace/sample_app (log-in-log-out) $ bundle exec rake test
Started

ERROR["test_layout_links", SiteLayoutTest, 2016-04-14 23:15:47 +0000]
 test_layout_links#SiteLayoutTest (1460675747.92s)
NoMethodError:         NoMethodError: undefined method `full_title' for #    <SiteLayoutTest:0x0000000a30bad8>
            test/integration/site_layout_test.rb:13:in `block in     <class:SiteLayoutTest>'
    test/integration/site_layout_test.rb:13:in `block in <class:SiteLayoutTest>'

  22/22: [======================================================] 100% Time:     00:00:01, Time: 00:00:01

Finished in 1.30261s
 tests, 49 assertions, 0 failures, 1 errors, 0 skips

I've gone through all the recent changes in chapter 7 and 8 again; the tests of 8.20, 8.21 and 8.24 just pass.

The file site_layout_test mentioned in the error 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
  get signup_path
  assert_select "title", full_title("Sign up")
  end
end

ADDITIONS:

1) This is the tutorial I'm doing: https://www.railstutorial.org/book/log_in_log_out

2) This is the file that the error refers to:

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
  get signup_path
  assert_select "title", full_title("Sign up")
  end
end

If I take the last assert_select out, I don't get the error anymore.

And this is the application_helper:

module ApplicationHelper
  # Returns the full title on a per-page basis.
  def full_title(page_title = '')
    base_title = "Ruby on Rails Tutorial Sample App"
    if page_title.empty?
      base_title
    else
      page_title + " | " + base_title
    end
  end
end

Your help is much appreciated. Thanks in advance!

1
Could you please post a link to the tutorial in question? I couldn't find the specs you are mentioning at the chapter 8. - born4new
Do you have full_title method defined in your test_helper? - Marek Lipka
Thanks for your comments, I added some more info - nannev

1 Answers

1
votes

I would wager the reason is because you haven't performed the step in Listing 5.37, where you include in the ApplicationHelper in your test_helper.rb:

class ActiveSupport::TestCase
  fixtures :all
  include ApplicationHelper
  .
  .
  .
end