0

I am reading the railstutorial.org book and I am stuck. Like the title says, RSpec is not locating the title tag. Before refactoring I did a check and it passed...At the bottom I only added one page but the other two are created. They are all the same minus the title.

cmd RSpec output:

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:40 # Static Pages should have the title 'About Us' rspec ./spec/requests/static_pages_spec.rb:11 # Static Pages Home page should have the title 'Home' rspec ./spec/requests/static_pages_spec.rb:25 # Static Pages Help page should have the title 'Help'

gem file:

source 'https://rubygems.org'

gem "rails", "~> 3.2.12"

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development, :test do    gem 'sqlite3', '~> 1.3.7'   gem 'rspec-rails', '~> 2.12.2' end


# Gems used only for assets and not required
# in production environments by default. group :assets do   gem 'sass-rails',   '~> 3.2.4'   gem 'coffee-rails', '~> 3.2.2'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes   # gem 'therubyracer', :platforms => :ruby

  gem "uglifier", "~> 1.3.0" end

gem "jquery-rails", "~> 2.2.1"

group :test do  gem "capybara", "~> 2.0.2" end

group :production do    gem "pg", "~> 0.14.1" end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

Routes:

SampleApp::Application.routes.draw do
  get "static_pages/home"

  get "static_pages/help"

  get "static_pages/about"
end

spec.rb:

require 'spec_helper'

describe "Static Pages" do

    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 title 'Home'" do
            visit '/static_pages/home'
            page.should have_selector('title',
                        :text => "Ruby on Rails Tutorial Sample App | 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 title 'Help'" do
            visit '/static_pages/help'
            page.should have_selector('title',
                        :text => "Ruby on Rails Tutorial Sample App | Help")
        end
    end

    describe "About page" do

        it "should have the h1 'About Us'" do
            visit '/static_pages/about'
            page.should have_selector('h1', :text => 'About Us')
        end
    end

    it "should have the title 'About Us'" do
        visit '/static_pages/about'
        page.should have_selector('title',
                    :text => "Ruby on Rails Tutorial Sample App | About Us")
    end
end

application.html.erb:

<!DOCTYPE html>
<html>
<head>
  <title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>

home.html.erb:

<% provide(:title, "Home") %>

<h1>Sample App</h1>
<p>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</p>
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
h00d13z
  • 35
  • 4

2 Answers2

1

The reason it didn't work is because you had Capybara version ~> 2.0.2 installed instead of 1.1.2, which is what the tutorial uses.

Version 2.0.0 and up don't have the text in the title tag visible by default in the page anymore (there's a reason why Hartl makes sure to directly specify gem versions in his Gemfile: for issues like this that can spring up).

More details in the Github issue, with a workaround to the issue is in this StackOverflow Q&A (though I would recommend that you just stick with the gem versions the tutorial has specified for now, and perhaps come back to this as a refactoring exercise).

Community
  • 1
  • 1
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
  • Thank you very much for taking a look at this...I was originally using an old pdf of the tutorial and troubleshooting that caused me to go up to the rubygems.org version. It fixed my old problem but then created a new one lol. Capybara issue does make sense, will read up on github now. – h00d13z Feb 15 '13 at 04:03
0

I went to the website and copy and pasted in his gemfile and all works now...Whats odd is I manually copied over all the gems from RubyGems.org so Im not sure why those didnt work...

h00d13z
  • 35
  • 4