Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish exercises at end of chapter 5
- Loading branch information
Showing
3 changed files
with
58 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |