Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8279141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:14:11+00:00 2026-06-08T09:14:11+00:00

I am on Chapter 4 of Michael Hartl’s RoR tutorial, and having some troubles

  • 0

I am on Chapter 4 of Michael Hartl’s RoR tutorial, and having some troubles with rspec and using the full_title helper function. In part 4.1 of the tutorial, I have the helper code as follows. It’s purpose is to make it so my help, contact, home, and about pages don’t need to be supplied a title on each view.

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
        "#{base_title} | #{page_title}"
    end
end

end

My layout page looks like

<!DOCTYPE html>
<html>
  <head>
    <title><title><%= full_title(yield(:title)) %></title></title>
    <%= stylesheet_link_tag    "application", :media => "all" %>
    <%= javascript_include_tag "application" %>
    <%= csrf_meta_tags %>
  </head>
  <body>
    <%= yield %>
  </body>
</html>

and my static_pages_spec.rb file looks like:

require 'spec_helper'

describe "Static Pages" do

  include ApplicationHelper


    describe "Home page" do

        it "should have the h1 'Sample App'" do
            visit '/static_pages/home'
            page.should have_selector('h1', :text => 'Sample App')
      end
      it "should have the base title 'Home'" do
        visit '/static_pages/home'
        page.should have_selector('title',
                              :text => "Ruby on Rails Tutorial App")

      end
      it "should not have a custom page title" do
        visit '/static_pages/home'
        page.should_not have_selector('title', :text => '| Home')
      end
  end

  describe "Help page" do

    it "should have the h1 'Help'" do
        visit '/static_pages/help'
        page.should have_selector('h1', :text => 'Help')
    end
    it "should have the right title 'Help'" do
        visit '/static_pages/help'
        page.should have_selector('title',
                              :text => "#{base_title} | Help")
    end
  end

  describe "About us" do

    it "should have the h1 'About Us'" do
      visit '/static_pages/about'
      page.should have_selector("h1", :text => "About Us")
    end
    it "should have the right title 'About Us'" do
        visit '/static_pages/about'
        page.should have_selector('title',
                              :text => "#{base_title} | About Us")
    end
  end

  describe "Contact" do

    it "should have the h1 'Contact'" do
      visit '/static_pages/contact'
      page.should have_selector('h1', :text => "Contact")
    end
    it "should have the right title 'Contact'" do
        visit '/static_pages/contact'
        page.should have_selector('title',
                              :text => "#{base_title} | Contact")
    end
  end
end

Yet when I run rspec, I get 4 test failures. 3 of them refer to the contact, about us, and help pages and say something along the lines of

Failure/Error: :text => “#base_title} | Contact”)
NameError:
undefined local variable or method “base_title” for #

Can anyone tell me what’s going wrong here? I suspect it has something to do with the helper function ans the base_title variable not being recognized by Rspec, but according to the tutorial the test suite should be passing all green.

Update: I figured out why one of the tests was failing. But I still have a problem with those 3 views saying base_title is an undefined method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:14:12+00:00Added an answer on June 8, 2026 at 9:14 am

    In the following test, how rspect knows what is base_title (2nd last line).

    describe "Help page" do
    
      it "should have the h1 'Help'" do
        visit '/static_pages/help'
        page.should have_selector('h1', :text => 'Help')
      end
      it "should have the right title 'Help'" do
        visit '/static_pages/help'
        page.should have_selector('title',
                              :text => "#{base_title} | Help")
      end
    end
    

    You have not defined it. I guess that’s why your tests are failing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking at some RSpec code in Chapter 6 of Michael Hartl's [Rail Tutorial]:
I am practicing this RoR tutorial project of Michael Hartl: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book I am using
Im following the RoR tutorial by Michael Hartl and im at chapter 9.3 Showing
On Chapter 7 from Michael Hartl's tutorial there is a User model < code
I'm working through Michael Hartl's Ruby on Rails tutorial on http://ruby.railstutorial.org . I'm having
I am doing Michael Hartl's Rails Tutorial screencast + online book on Chapter 10,
I'm going through the tutorial on http://ruby.railstutorial.org/ by Michael Hartl. I'm on chapter six
Doing Michael Hartl's Rails Tutorial, on chapter 10, section 5, exercise 2 . I
I'm following Chapter 5 of the Michael Hartl tutorial. When I run the following
i m following michael hartl's ruby on rails online tutorial book and finished chapter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.