Skip to content

Instantly share code, notes, and snippets.

@stanigator
Created May 23, 2012 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stanigator/aadd99fb703233368333 to your computer and use it in GitHub Desktop.
Save stanigator/aadd99fb703233368333 to your computer and use it in GitHub Desktop.
Application helper problem?
<!DOCTYPE html>
<html>
<head>
<title><% full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
module ApplicationHelper
# REturns the full title 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
stanley@ubuntu:~/rails_sample/sample_app$ bundle exec rspec spec/requests/static_pages_spec.rb
.F..F..F..F.
Failures:
1) StaticPages Home page should have the base title
Failure/Error: page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
expected css "title" with text "Ruby on Rails Tutorial Sample App" to return something
# ./spec/requests/static_pages_spec.rb:15
# ./bundler_stubs/rspec:16
2) StaticPages Help page should have the base title
Failure/Error: page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
expected css "title" with text "Ruby on Rails Tutorial Sample App" to return something
# ./spec/requests/static_pages_spec.rb:32
# ./bundler_stubs/rspec:16
3) StaticPages About page should have the base title
Failure/Error: page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
expected css "title" with text "Ruby on Rails Tutorial Sample App" to return something
# ./spec/requests/static_pages_spec.rb:49
# ./bundler_stubs/rspec:16
4) StaticPages Contact page should have the base title
Failure/Error: page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
expected css "title" with text "Ruby on Rails Tutorial Sample App" to return something
# ./spec/requests/static_pages_spec.rb:66
# ./bundler_stubs/rspec:16
Finished in 0.25876 seconds
12 examples, 4 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:13 # StaticPages Home page should have the base title
rspec ./spec/requests/static_pages_spec.rb:30 # StaticPages Help page should have the base title
rspec ./spec/requests/static_pages_spec.rb:47 # StaticPages About page should have the base title
rspec ./spec/requests/static_pages_spec.rb:64 # StaticPages Contact page should have the base title
require 'spec_helper'
describe "StaticPages" do
let(:base_title) { "Ruby on Rails Tutorial Sample App" }
describe "Home page" do
it "should have the h1 'Sample App'" do
visit '/static_pages/home'
page.should have_selector('h1', :text => 'Sample App')
end
it "should have the base title" do
visit '/static_pages/home'
page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit '/static_pages/home'
page.should_not have_selector('title', :text => '| Home')
end
end
describe "Help page" do
it "should have the h1 'Help'" do
visit '/static_pages/help'
page.should have_selector('h1', :text => 'Help')
end
it "should have the base title" do
visit '/static_pages/help'
page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit '/static_pages/help'
page.should_not have_selector('title', :text => '| Help')
end
end
describe "About page" do
it "should have the h1 'About Us'" do
visit '/static_pages/about'
page.should have_selector('h1', :text => 'About Us')
end
it "should have the base title" do
visit '/static_pages/about'
page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit '/static_pages/about'
page.should_not have_selector('title', :text => '| About Us')
end
end
describe "Contact page" do
it "should have the h1 'Contact'" do
visit '/static_pages/contact'
page.should have_selector('h1', :text => 'Contact')
end
it "should have the base title" do
visit '/static_pages/contact'
page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit '/static_pages/contact'
page.should_not have_selector('title', :text => '| Contact')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment