From 06bd3ed438eb56cc454193172bb3a3f443b1e298 Mon Sep 17 00:00:00 2001 From: Bill Kilmer Date: Mon, 28 Jan 2013 21:47:47 -0800 Subject: [PATCH] Finish exercises at end of chapter 5 --- spec/helpers/application_helper_spec.rb | 18 ++++++++++ spec/requests/static_pages_spec.rb | 48 ++++++++++++++++++++----- spec/support/utilities.rb | 9 +---- 3 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 spec/helpers/application_helper_spec.rb diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 0000000..decad14 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/requests/static_pages_spec.rb b/spec/requests/static_pages_spec.rb index 3813f3a..9d049c1 100644 --- a/spec/requests/static_pages_spec.rb +++ b/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 \ No newline at end of file diff --git a/spec/support/utilities.rb b/spec/support/utilities.rb index a9082cb..3bc5e9d 100644 --- a/spec/support/utilities.rb +++ b/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 \ No newline at end of file +include ApplicationHelper \ No newline at end of file