2
votes

I am really hoping someone can help me out with this. I am following Michael Hartl' Rails 3 tutorial and have hit a wall in Chapter 5. I spent the better part of yesterday attempting to solve the issue by going back over all of the work, going through all the related questions on Stack Overflow. There was a ton of info out there, but none of it has solved my issue, and I honestly can't understand where I have gone wrong.

Everything was going nicely (the site works exactly as it says it should at this point in the book) until I got to the point where the author walks you through cleaning up your 'static_pages_spec.rb' file. Mine is currently in this state:


require 'spec_helper'

describe "Static pages" do

subject { page }

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

I also have both the 'spec/support/utilities.rb' file, as described by the author:


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

as well as the following in 'app/helpers/application_helper.rb'


module ApplicationHelper

#Returns the full title based 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

When I run 'guard' (I have gone through the setup of Guard, Spork, etc.) I get the following three failures:

1) 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:19:in `block (3 levels) in '

2) 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:26:in `block (3 levels) in '

3) 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:33:in `block (3 levels) in '

The site works correctly (routing seems to be correct), but I do notice that if I view the source for any of the pages, the :title is always "Ruby on Rails Tutorial Sample App". The ' | :page_title ' does nto seem to be prepended. I just can't find what I did to break that, because my rspec tests were working at earlier points in the book.

I have seen a bunch of these questions where those folks trying to help have requested access to the code on GitHub. In the hopes of finding my error quickly, I have placed all of the code up there:

https://github.com/rbrowndev/sampleapp.git

https://github.com/rbrowndev/sampleapp/tree/filling-in-layout

As I am new to this, please let me know if the repository is not configured properly to allow you to clone the project. I believe I have it set up that way, but as I am a newb...

If anyone can help it would be greatly appreciated. Please let me know if you would rather I post more of the source code here on SO rather then just on GitHub.

Thanks.

1

1 Answers

1
votes

There's a bug that keeps us from being able to check the text in title fields (actually, it's any invisible content): https://github.com/jnicklas/capybara/issues/844

So far, this seems like the best way to enable checking title text in our specs: https://stackoverflow.com/a/13755730/359957