Here is the error I am getting:
…F
Failures:
- LayoutLinks should have the right links on the layout
Failure/Error: click_link “Sign up”
Could not find link with text or title or id “Sign up”./spec/requests/layout_links_spec.rb:37:in `block (2 levels) in
<top (required)>’
Finished in 0.28358 seconds
6 examples, 1 failure
Here is the test file for LayoutLinks. The last ‘it block’ has the
click_link that is giving me the problem:
#spec/requests/layout_links_spec.rb:
require ‘spec_helper’
describe “LayoutLinks” do
it “should have a Home page at: /” do
get ‘/’
response.should have_selector(‘title’, :content => “Home”)
end
it “should have an About page at: /about” do
get ‘/about’
response.should have_selector(‘title’, :content => “About”)
end
it “should have a Contact page at: /contact” do
get ‘/contact’
response.should have_selector(‘title’, :content => “Contact”)
end
it “should have a Help page at: /help” do
get ‘/help’
response.should have_selector(‘title’, :content => “Help”)
end
it “should have a Sign up page at: /signup” do
get “/signup”
response.should have_selector(‘title’, :content => “Sign up”)
end
it “should have the right links on the layout” do
visit root_path
click_link “About”
response.should have_selector(‘title’, :content => “About”)
click_link “Contact”
response.should have_selector(‘title’, :content => “Contact”)
click_link “Help”
response.should have_selector(‘title’, :content => “Help”)
click_link “Sign up”
response.should have_selector(‘title’, :content => “Sign up”)
click_link “Home”
response.should have_selector(‘title’, :content => “Home”)
end
The other click_link’s pass their tests. It’s only the ‘Sign up’ link
that is giving me the problem. The only difference I can discern is
that the page with the ‘Sign up’ link is handled by a different
controller: Users v. Pages (the controllers are listed below).
Here is the application layout:
application.html.erb:
<%= title() %> <%= csrf_meta_tag %> <%= render 'layouts/stylesheets' %><div class="container">
<%= render 'layouts/header' %>
<section class="round">
<%= yield %>
</section>
<%= render 'layouts/footer' %>
</div>
Here is the Home page that contains the ‘Sign Up’ link:
home.html.erb: (inserted at ‘yield’ in application layout)
Me
Hi, this is my website.
<%= link_to “Sign up”, signup_path, :class => “signup_button round” %>
Here are my routes:
config/routes.rb:
SampleApp::Application.routes.draw do
get “users/new”
#get “pages/home”
#get “pages/contact”
#get “pages/about”
#get “pages/help”
match ‘/signup’, :to => ‘users#new’
match ‘/about’, :to => ‘pages#about’
match ‘/contact’, :to => ‘pages#contact’
match ‘/help’, :to => ‘pages#help’
root :to => ‘pages#home’
end
Here are my controllers:
users_controller.rb:
class UsersController < ApplicationController
def new
@title = “Sign up”
end
end
pages_controller.rb:
class PagesController < ApplicationController
def home
@title = “Home”
end
def contact
@title = “Contact”
end
def about
@title = “About”
end
def help
@title = “Help”
end
end