So I have been trying to follow along with the rails tutorial but I have been stuck on making the title slightly dynamic. Once I get to this part and run
$ bundle exec rspec spec/requests/static_pages_spec.rb
I receive the following error
Failures:
1) Static pages Help page should have the title 'Help'
Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help")
expected #has_title?("Ruby on Rails Tutorial Sample App | Help") to return true, got false
# ./spec/requests/static_pages_spec.rb:27:in `block (3 levels) in <top (required)>'
2) Static pages Home page should have the title 'Home'
Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | Home")
expected #has_title?("Ruby on Rails Tutorial Sample App | Home") to return true, got false
# ./spec/requests/static_pages_spec.rb:14:in `block (3 levels) in <top (required)>'
3) Static pages About page should have the title 'About Us'
Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
expected #has_title?("Ruby on Rails Tutorial Sample App | About Us") to return true, got false
# ./spec/requests/static_pages_spec.rb:40:in `block (3 levels) in <top (required)>'
Finished in 0.1826 seconds
6 examples, 3 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:25 # Static pages Help page should have the title 'Help'
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the title 'Home'
rspec ./spec/requests/static_pages_spec.rb:38 # Static pages About page should have the title 'About Us'
This is what my Home, Help, and About views are like.
Home
<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</p>
Help
<% provide(:title, 'Help') %>
<h1>Help</h1>
<p>
Get help on the Ruby on Rails Tutorial at the
Rails Tutorial help page.
To get help on this sample app, see the
Rails Tutorial book.
</p>
About
<%= provide(:title, 'About Us') %>
<h1>About Us</h1>
<p>
The Ruby on Rails Tutorial
is a project to make a book and screencasts to teach web development
with Ruby on Rails. This
is the sample application for the tutorial.
</p>
And this is my Application view
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails Tutorial Sample App | <%= yield (:title) %></title>
<%= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
And my Static Page spec
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
it "should have the title 'Home'" do
visit '/static_pages/home'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Home")
end
end
describe "Help page" do
it "should have the content 'Help'" do
visit '/static_pages/help'
expect(page).to have_content('Help')
end
it "should have the title 'Help'" do
visit '/static_pages/help'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help")
end
end
describe "About page" do
it "should have the content 'About Us'" do
visit '/static_pages/about'
expect(page).to have_content('About Us')
end
it "should have the title 'About Us'" do
visit '/static_pages/about'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
end
end
end
and lastly my gemfile
source 'https://rubygems.org'
ruby '2.1.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.2'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
Change your view like below(notice = before provide in the first line). Do the same for all your three views
Home
<%= provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</p>
Have you tried going to each page manually and checking the title yourself?
I pasted literally everything you provided into a project (I did the tutorial not long ago so I already had one set up with the static_pages controller) and all those tests passed. I would have said that you might have mixed up the filenames for your views, or the names in the routes file, but the content tests are passing so that can't be it. I guess it's possible that one of your files has been saved in the wrong encoding by your editor, or something else along those lines. Also check that you have in fact saved all your files before running your tests.
Also a quick note that = is NOT necessary for <% provide ... so you should probably remove it from your about view.
I think you may have forgotten to add the 'contact' page to your routes.rb file, like so:
SampleApp::Application.routes.draw do
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
get "static_pages/contact"
Try this :
static_pages_spec.rb
require 'spec_helper'
describe "Static pages" do
let(:base_title) { "Ruby on Rails Tutorial Sample App" }
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
it "should have the title 'Home'" do
visit '/static_pages/home'
#expect(page).to have_title("#{base_title} | Home")
page.should have_title("#{base_title} | Home")
end
end
describe "Help page" do
it "should have the content 'Help'" do
visit '/static_pages/help'
expect(page).to have_content('Help')
end
it "should have the title 'Help'" do
visit '/static_pages/help'
#expect(page).to have_title("#{base_title} | Help")
page.should have_title("#{base_title} | Help")
end
end
describe "About page" do
it "should have the content 'About Us'" do
visit '/static_pages/about'
expect(page).to have_content('About Us')
end
it "should have the title 'About Us'" do
visit '/static_pages/about'
page.should have_title("#{base_title} | About Us")
end
end
describe "Contact page" do
it "should have the content 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_content('Contact')
end
it "should have the title 'Contact'" do
visit '/static_pages/contact'
# expect(page).to have_title("#{base_title} | Contact")
page.should have_title("#{base_title} | Contact")
end
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", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
gem 'capybara', '2.1.0'
Becarful with spaces in the title
Related
I've been working through Michael Hartl's Rails tutorial, and for some reason I've gotten stuck on the first exercise in section 3. I've checked and rechecked my code to ensure that it matches his, but I still get this error:
Failures:
1) Static pages Contact page should have the content 'Contact'
Failure/Error: expect(page).to have_content('Contact')
expected #has_content?("Contact") to return true, got false
# ./spec/requests/static_pages_spec.rb:48:in `block (3 levels) in <top (required)>'
2) Static pages Contact page should have the title 'Contact'
Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact")
expected #has_title?("Ruby on Rails Tutorial Sample App | Contact") to return true, got false
# ./spec/requests/static_pages_spec.rb:53:in `block (3 levels) in <top (required)>'
Finished in 0.09624 seconds
8 examples, 2 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:46 # Static pages Contact page should have the content 'Contact'
rspec ./spec/requests/static_pages_spec.rb:51 # Static pages Contact page should have the title 'Contact'
Here is my code
static_pages_spec.rb
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
it "should have the title 'Home'" do
visit '/static_pages/home'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Home")
end
end
describe "Help page" do
it "should have the content 'Help'" do
visit '/static_pages/help'
expect(page).to have_content('Help')
end
it "should have the title 'Help'" do
visit '/static_pages/help'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help")
end
end
describe "About page" do
it "should have the content 'About Us'" do
visit '/static_pages/about'
expect(page).to have_content('About Us')
end
it "should have the title 'About Us'" do
visit '/static_pages/about'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
end
end
describe "Contact page" do
it "should have the content 'Contact'" do
visit '/static_pages/about'
expect(page).to have_content('Contact')
end
it "should have the title 'Contact'" do
visit '/static_pages/about'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact")
end
end
end
application.html.erb, which is saved under app/views/layouts
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>
<%= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
contact.html.erb
<% provide(:title, 'Contact') %>
<h1>Contact</h1>
<p>
Contact Ruby on Rails Tutorial about the sample app at the
contact page.
</p>
routes.rb
SampleApp::Application.routes.draw do
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
get "static_pages/contact"
end
static_pages_controller.rb
class StaticPagesController < ApplicationController
def home
end
def help
end
def about
end
def contact
end
end
With the limited information you're providing (I know it's hard to diagnose when you're a beginner, it gets easier). It looks like you're telling your test to check your about page and checking for content that only exists in your contact page.
I hate to be a help-vampire, but I'm new and I've been looking at this almost two days.
I'm working on Ruby on Rails Tutorial by Michael Hartl. I'm running the test in listing 4.4, which I will include below. The specific test that I'm trying to get to pass checks to see if the page has a selector with the text, "Ruby on Rails Tutorial Sample App". I'll probably find the answer to this problem during the process of asking it on SO, but here we go. Below are, what I believe, the relevant files:
/spec/requests/static_pages_spec.rb
require 'spec_helper'
describe "StaticPages" 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 base title" do
visit '/static_pages/home'
page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample 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
...[other tests for other pages, let me know if you think they're necessary]
end
app/helpers/application_helper.rb
module ApplicationHelper
# It is a good idea to put controller specific helpers in their
# related helper file (e.g., helpers specifically for the
# StaticPages controller).
# Returns the full title on a per-page basis:
# This helper will be used for each page's title (unless
# otherwise noted).
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
app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title))%></title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
app/views/static_pages/home.html.erb
<% provide :title, "Home" %>
<h1>Sample App</h1>
<p>
This is the home page for a
Ruby on Rails tutorial.
</p>
<p>
It's by Michael Hartl
</p>
I have not configured Sublime to run rspec in the console, yet. When I run the test in Terminal from a bash, I get the following:
.......F.
Failures:
1) StaticPages Home page should have the base title
Failure/Error: page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
expected #has_selector?("title", {:text=>"Ruby on Rails Tutorial Sample App"}) to return true, got false
# ./spec/requests/static_pages_spec.rb:14:in `block (3 levels) in <top (required)>'
Finished in 0.14273 seconds
9 examples, 1 failure
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:12 # StaticPages Home page should have the base title
Randomized with seed #####
When I look at the source code in chrome, I can clearly see a pair of tags with "Ruby on Rails Tutorial Sample App | Home" in between them.
Well, I've gone through it all and I can't figure out what's going on. Hello, SO world! Please help. Thank you.
I would push to github right now, but they're down. I'll update when possible.
change
have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
to
have_title("Ruby on Rails Tutorial Sample App | Home")
It's a change to Capybara and was updated in Michael Hartl's tutorial. To see the update search for "Change have_selector(’title’, …) to have_title(…)" once in the tutorial.
I have this test from michael hartl book:
require 'spec_helper'
describe "Static pages" do
let(:base_title) { "Ruby on Rails Tutorial Sample App" }
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 => "#{base_title} | Home")
end
end
end
And the view:
<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</p>
When I run the test it says:
....
Finished in 1.91 seconds
4 examples, 0 failures
Randomized with seed 42247
.F...
Failures:
1) Static pages Home page should have the title 'Home'
Failure/Error: page.should have_selector('title', :text => "#{base_title} | Home")
expected #has_selector?("title", {:text=>"Ruby on Rails Tutorial Sample App | Home"}) to return true, got false
# ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in <top (required)>'
Finished in 1.91 seconds
5 examples, 1 failure
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:14 # Static pages Home page should have the title 'Home'
Randomized with seed 17491
But It should pass, because when I view the page in browser the title is: Ruby on Rails Tutorial Sample App | Sample App, which is correct!
Make sure you're using capybara 1.1.2 in your Gemfile. Starting from 2.0 capybara does not works for title testing (https://github.com/jnicklas/capybara/issues/844)
...
group :test do
gem 'capybara', '1.1.2'
end
For the time being, you should do what #dimuch suggests and make sure you specify the same Capybara version Michael Hartl uses in the tutorial (1.1.2).
If you want to upgrade to Capybara 2.0 in the future and keep your tests for titles, have a look at this StackOverflow answer for a guide to creating a RSpec matcher that will do what you're expecting.
Using capubara 2.0 you should use
page.should have_title("The title")
But in aint work if you dont add
<style type="text/css">head, head title { display: block }</style>
To your application.html
page.title # => "The title"
page.has_title?("The title") # => true
page.should have_title("The title")
I've been using the following and they have been posting green. I dropped have_selector and went with have_title.
it { should have_title( full_title('Sign up') ) }
-- and --
it { should have_title(user.name) }
This is with capybara 2.2.0.
I've been scouring the web & Stack Overflow to tr and figure out how to get these tests working. I'm brand new to Ruby & to Rails, I'm simply following along Hartl's tutorial - copy pasting most of the code to see how it all falls together in the end.
Now, I'm getting stuck in section 3.3 "Slightly Dynamic Pages".
This is the error I'm recieving:
C:\Sites\sample_app>bundle exec rspec --no-color spec/requests/static_pages_spec.rb
F.F.F.
Failures:
1) Static pages About page should have the title 'About Us'
Failure/Error: page.should have_selector('title',
expected css "title" with text "Ruby on Rails Tutorial Sample App | About Us" to return something
# ./spec/requests/static_pages_spec.rb:44:in `block (3 levels) in <top (required)>'
2) Static pages Help page should have the title 'Help'
Failure/Error: page.should have_selector('title',
expected css "title" with text "Ruby on Rails Tutorial Sample App | Help" to return something
# ./spec/requests/static_pages_spec.rb:29:in `block (3 levels) in <top (required)>'
3) Static pages Home page should have the title 'Home'
Failure/Error: page.should have_selector('title',
expected css "title" with text "Ruby on Rails Tutorial Sample App | Home" to return something
# ./spec/requests/static_pages_spec.rb:14:in `block (3 levels) in <top (required)>'
Finished in 3.09 seconds
6 examples, 3 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:42 # Static pages About page should have the title 'About Us'
rspec ./spec/requests/static_pages_spec.rb:27 # Static pages Help page should have the title 'Help'
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the title 'Home'
Randomized with seed 25648
The error is occuring as soon as I swtich from this HTML Structure (in my About/Home/Help.html.erb files):
<% provide(:title, 'Home') %>
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>
</head>
<body>
<h1>Sample App</h1>
<p>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</p>
</body>
</html>
To this:
<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</p>
Other related files:
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>
static_pages_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")
// The line below is something I tried replacing the page.should have_selector with
// page.should have_xpath("//title", :text => "Home")
end
end
.... (other describe pages, same structure)
end
I might've just gone blind over the course of copying/pasting/reading from Hartl's tutorial, but I am pretty damn sure it looks the same way as he described it.
I've done my best at looking for a solution to this, but alas I haven't been able to figure it out, so here goes!
Cheers!
Edit: Answer to Fiona #1
On this url : "http://localhost:3000/static_pages/home"
The document title is nothing.
The source of the document looks like this:
<h1>Sample App</h1>
<p>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</p>
There is no doctype, head, body or title declaration in the source.
For Rails to pick up the layout file, the application.html.erb file should be in app/views/layouts/application.html.erb.
I have a request spec that is failing even thought it should be passing. ALL of the content the spec is looking for appears in the source ( HTML ) of the app. These test should be passing as far as I can tell.I'm going to list in order:
The test
The helper helper method full_title that is used in the test
The relevant view templates in haml
The HTML output of the home page or root route
The Rspec failures
The Gemfile
The layout file
Here is the spec code:
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
before { visit root_path }
it { should have_selector('h1', text: 'Sample App') }
it { should have_selector('title', text: full_title('')) }
it { should_not have_selector('title', text: ' | Home') }
end
describe "Help page" do
before { visit help_path }
it { should have_selector('h1', text: 'Help') }
it { should have_selector('title', text: full_title('Help')) }
end
describe "About page" do
before { visit about_path }
it { should have_selector('h1', text: 'About') }
it { should have_selector('title', text: full_title('About Us')) }
end
describe "Contact page" do
before { visit contact_path }
it { should have_selector('h1', text: 'Contact') }
it { should have_selector('title', text: full_title('Contact')) }
end
end
Here is the helper method full_title:
module ApplicationHelper
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
The home view or /home route:
.center.hero-unit
%h1
Welcome to the Sample App
%h2
This is the home page for the
%a{ href: "http://railstutorial.org"}Ruby on Rails Tutorial sample app
= link_to "Sign up now!", '#', class: "btn btn-large btn-primary"
= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org'
The about page:
- provide(:title, 'About Us')
%body
%h1
About Us
%p
The
%a(href="http://railstutorial.org/")Ruby on Rails Tutorial
is a project to make a book and screencasts to teach web development with
%a(href="http://rubyonrails.org/")Ruby on Rails
This is the sample application for the tutorial
The help page:
- provide(:title, 'Help')
%body
%h1
Help
%p
Get help on the Ruby on Rails Tutorial at the
%a(href="http://railstutorial.org/help")Rails tutorial help page
To get help on this sample app, see the
%a(href="http://railstutorial.org/book")Rails Tutorial book
The contact page:
- provide(:title, 'Contact')
%h1 Contact
%p
Contact ruby on Rails Tutorial about the sample app at the
%a{ href: "http://railstutorial.org/contact"}Contact page
The HTML for the home page:
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails Tutorial Sample App</title>
<link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/custom.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/static_pages.css?body=1" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/static_pages.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="KLYiW09+IfyIcxG2jcCX8tt3vts7aCTzYuiYA0ks8tM=" name="csrf-token" />
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
[![endif]-->
</head>
<body>
<header class='navbar navbar-fixed-top'>
<div class='navbar-inner'>
<div class='container'>
sample app
<nav>
<ul class='nav pull-right'>
<li>Home</li>
<li>help</li>
<li>Sign in</li>
</ul>
</nav>
</div>
</div>
</header>
<div class='container'>
<div class='center hero-unit'>
<h1>
Welcome to the Sample App
</h1>
<h2>
This is the home page for the
<a href='http://railstutorial.org'>Ruby on Rails Tutorial sample app</a>
</h2>
Sign up now!
</div>
<img alt="Rails" src="/assets/rails.png" />
<footer class='footer'>
<small>
<a href='http://railstutorial.org'>Rails Tutorial by Michael Hartl</a>
</small>
<nav>
<ul>
<li>About</li>
<li>Contact</li>
<li>
<a href='http://railstutorial.org'>News</a>
</li>
</ul>
</nav>
</footer>
</div>
</body>
</html>
The Rspec failures:
FF.FFFFFF
Failures:
1) Static pages Home page
Failure/Error: it { should have_selector('h1', text: 'Sample App') }
expected css "h1" with text "Sample App" to return something
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
2) Static pages Home page
Failure/Error: it { should have_selector('title', text: full_title('')) }
expected css "title" with text "Ruby on Rails Tutorial Sample App" to return something
# ./spec/requests/static_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
3) Static pages Help page
Failure/Error: it { should have_selector('h1', text: 'Help') }
expected css "h1" with text "Help" to return something
# ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in <top (required)>'
4) Static pages Help page
Failure/Error: it { should have_selector('title', text: full_title('Help')) }
expected css "title" with text "Ruby on Rails Tutorial Sample App | Help " to return something
# ./spec/requests/static_pages_spec.rb:17:in `block (3 levels) in <top (required)>'
5) Static pages About page
Failure/Error: it { should have_selector('h1', text: 'About') }
expected css "h1" with text "About" to return something
# ./spec/requests/static_pages_spec.rb:23:in `block (3 levels) in <top (required)>'
6) Static pages About page
Failure/Error: it { should have_selector('title', text: full_title('About Us')) }
expected css "title" with text "Ruby on Rails Tutorial Sample App | About Us " to return something
# ./spec/requests/static_pages_spec.rb:24:in `block (3 levels) in <top (required)>'
7) Static pages Contact page
Failure/Error: it { should have_selector('h1', text: 'Contact') }
expected css "h1" with text "Contact" to return something
# ./spec/requests/static_pages_spec.rb:30:in `block (3 levels) in <top (required)>'
8) Static pages Contact page
Failure/Error: it { should have_selector('title', text: full_title('Contact')) }
expected css "title" with text "Ruby on Rails Tutorial Sample App | Contact " to return something
# ./spec/requests/static_pages_spec.rb:31:in `block (3 levels) in <top (required)>'
Finished in 0.34035 seconds
9 examples, 8 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:8 # Static pages Home page
rspec ./spec/requests/static_pages_spec.rb:9 # Static pages Home page
rspec ./spec/requests/static_pages_spec.rb:16 # Static pages Help page
rspec ./spec/requests/static_pages_spec.rb:17 # Static pages Help page
rspec ./spec/requests/static_pages_spec.rb:23 # Static pages About page
rspec ./spec/requests/static_pages_spec.rb:24 # Static pages About page
rspec ./spec/requests/static_pages_spec.rb:30 # Static pages Contact page
rspec ./spec/requests/static_pages_spec.rb:31 # Static pages Contact page
The Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'haml-rails'
gem 'bootstrap-sass', '2.0.0'
gem 'capybara', '1.1.2'
group :development, :test do
gem 'sqlite3' , '1.3.5'
gem 'rspec-rails', '2.10.0'
end
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# 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'
gem 'uglifier', '1.2.3'
end
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'jquery-rails'
group :test do
gem 'capybara', '1.1.2'
end
group :production do
gem 'pg', '0.12.2'
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'
The layout file
!!! 5
%html
%head
%title= full_title(yield(:title))
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
= render 'layouts/shim'
%body
= render 'layouts/header'
.container
= yield
= render 'layouts/footer'
This is a very subtle error for a new programmer to debug. I'm using the vim editor and for some reason 4 spaces was expanding to a tab. A hidden tab character in the layouts file was causing the specs to fail.