Note that there are some explanatory texts on larger screens.

plurals
  1. PORequest spec failing from Rails Tutorial from Michael Hartl
    primarykey
    data
    text
    <p>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:</p> <ul> <li>The test</li> <li>The helper helper method full_title that is used in the test</li> <li>The relevant view templates in haml</li> <li>The HTML output of the home page or root route</li> <li>The Rspec failures</li> <li>The Gemfile</li> <li>The layout file</li> </ul> <p>Here is the spec code:</p> <pre><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 </code></pre> <p>Here is the helper method <code>full_title</code>:</p> <pre><code>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 </code></pre> <p>The home view or /home route:</p> <pre><code>.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' </code></pre> <p>The about page:</p> <pre><code>- 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 </code></pre> <p>The help page:</p> <pre><code>- 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 </code></pre> <p>The contact page:</p> <pre><code>- 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 </code></pre> <p>The HTML for the home page:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Ruby on Rails Tutorial Sample App&lt;/title&gt; &lt;link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" /&gt; &lt;link href="/assets/custom.css?body=1" media="all" rel="stylesheet" type="text/css" /&gt; &lt;link href="/assets/static_pages.css?body=1" media="all" rel="stylesheet" type="text/css" /&gt; &lt;script src="/assets/jquery.js?body=1" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/assets/jquery_ujs.js?body=1" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/assets/static_pages.js?body=1" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/assets/application.js?body=1" type="text/javascript"&gt;&lt;/script&gt; &lt;meta content="authenticity_token" name="csrf-param" /&gt; &lt;meta content="KLYiW09+IfyIcxG2jcCX8tt3vts7aCTzYuiYA0ks8tM=" name="csrf-token" /&gt; &lt;!--[if lt IE 9]&gt; &lt;script src="http://html5shim.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt; [![endif]--&gt; &lt;/head&gt; &lt;body&gt; &lt;header class='navbar navbar-fixed-top'&gt; &lt;div class='navbar-inner'&gt; &lt;div class='container'&gt; &lt;a href="/" id="logo"&gt;sample app&lt;/a&gt; &lt;nav&gt; &lt;ul class='nav pull-right'&gt; &lt;li&gt;&lt;a href="/"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/help"&gt;help&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Sign in&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/nav&gt; &lt;/div&gt; &lt;/div&gt; &lt;/header&gt; &lt;div class='container'&gt; &lt;div class='center hero-unit'&gt; &lt;h1&gt; Welcome to the Sample App &lt;/h1&gt; &lt;h2&gt; This is the home page for the &lt;a href='http://railstutorial.org'&gt;Ruby on Rails Tutorial sample app&lt;/a&gt; &lt;/h2&gt; &lt;a href="#" class="btn btn-large btn-primary"&gt;Sign up now!&lt;/a&gt; &lt;/div&gt; &lt;a href="http://rubyonrails.org"&gt;&lt;img alt="Rails" src="/assets/rails.png" /&gt;&lt;/a&gt; &lt;footer class='footer'&gt; &lt;small&gt; &lt;a href='http://railstutorial.org'&gt;Rails Tutorial by Michael Hartl&lt;/a&gt; &lt;/small&gt; &lt;nav&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="/about"&gt;About&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/contact"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;li&gt; &lt;a href='http://railstutorial.org'&gt;News&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/nav&gt; &lt;/footer&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The Rspec failures:</p> <pre><code>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 &lt;top (required)&gt;' 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 &lt;top (required)&gt;' 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 &lt;top (required)&gt;' 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 &lt;top (required)&gt;' 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 &lt;top (required)&gt;' 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 &lt;top (required)&gt;' 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 &lt;top (required)&gt;' 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 &lt;top (required)&gt;' 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 </code></pre> <p>The Gemfile</p> <pre><code>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 =&gt; '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 =&gt; :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', '~&gt; 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' </code></pre> <p>The layout file</p> <pre><code>!!! 5 %html %head %title= full_title(yield(:title)) = stylesheet_link_tag "application", :media =&gt; "all" = javascript_include_tag "application" = csrf_meta_tags = render 'layouts/shim' %body = render 'layouts/header' .container = yield = render 'layouts/footer' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload