Skip to content

Commit

Permalink
Finish exercises at end of chapter 5
Browse files Browse the repository at this point in the history
  • Loading branch information
wdk122 committed Jan 29, 2013
1 parent a2bbfbf commit 06bd3ed
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 17 deletions.
18 changes: 18 additions & 0 deletions spec/helpers/application_helper_spec.rb
@@ -0,0 +1,18 @@
require 'spec_helper'

describe ApplicationHelper do

describe "full_title" do
it "should include the page title" do
full_title("foo").should =~ /foo/
end

it "should include the base title" do
full_title("foo").should =~ /^Ruby on Rails Tutorial Sample App/
end

it "should not include a bar for the home page" do
full_title("").should_not =~ /\|/
end
end
end
48 changes: 39 additions & 9 deletions spec/requests/static_pages_spec.rb
@@ -1,35 +1,65 @@
require 'spec_helper'

# updated according to hartl listing 5.35
describe "Static pages" do

subject { page }

shared_examples_for "all static pages" do
it { should have_selector('h1', text: heading) }
it { should have_selector('title', text: full_title(page_title)) }
end

describe "Home page" do
before { visit root_path }
let(:heading) { 'Sample App' }
let(:page_title) { '' }

it { should have_selector('h1', text: 'Sample App') }
it { should have_selector('title', text: full_title('')) }
it_should_behave_like "all static pages"
it { should_not have_selector 'title', text: '| Home'}
end

describe "Help page" do
before { visit help_path }
let(:heading) { 'Help' }
let(:page_title) { 'Help' }
it_should_behave_like "all static pages"

it { should have_selector('h1', text: 'Help') }
it { should have_selector('title', text: full_title('Help')) }
# 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 }
let(:heading) { 'About' }
let(:page_title) { 'About Us' }
it_should_behave_like "all static pages"

it { should have_selector('h1', text: 'About') }
it { should have_selector('title', text: full_title('About Us')) }
# 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 }
let(:heading) { 'Contact' }
let(:page_title) { 'Contact' }
it_should_behave_like "all static pages"

# it { should have_selector('h1', text: 'Contact') }
# it { should have_selector('title', text: full_title('Contact')) }
end

it { should have_selector('h1', text: 'Contact') }
it { should have_selector('title', text: full_title('Contact')) }
it "should have the right links on the layout" do
visit root_path
click_link "About"
page.should have_selector 'title', text: full_title('About Us')
click_link "Help"
page.should have_selector 'title', text: full_title('Help')
click_link "Contact"
page.should have_selector 'title', text: full_title('Contact')
click_link "Home"
click_link "Sign up now!"
page.should have_selector 'title', text: full_title('')
click_link "sample app"
page.should have_selector 'title', text: full_title('')
end
end
9 changes: 1 addition & 8 deletions spec/support/utilities.rb
@@ -1,8 +1 @@
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
include ApplicationHelper

0 comments on commit 06bd3ed

Please sign in to comment.