Reputation: 8131
I'm trying to follow the ruby on rails tutorial and impliment the Integration Testing.
I first run the command: bundle exec rspec spec/
And it tells me all but one of my sixteen tests passes. Here is the part where I think the issue is:
require 'spec_helper'
describe "LayoutLinks" do
it "should have the right links on the layout" do
visit root_path
click_link "Help"
response.should have_selector('title', :content => "Help")
click_link "Contact"
response.should have_selector('title', :content => "Contact")
click_link "Home"
response.should have_selector('title', :content => "Home")
click_link "Sign up now!"
response.should have_selector('title', :content => "Sign Up")
click_link "About"
response.should have_selector('title', :content => "About")
end
end
As a result I get the following:
Failure/Error: response.should have_selector('title', :content => "Help")
expected following output to contain a <title>Help</title> tag:
#home.html.erb page's source shown
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Ruby on Rails Tutorial Sample App | Home</title>
#The line above is why the test fails.
#It is loading home.html.erb instead of help.html.erb
.
.
.
# ./spec/requests/layout_links_spec.rb:34:in `block (2 levels) in <top (required)>'
I can move around the order of the tests and it is always the top test that fails. This makes me believe there is something wrong here and not with the actual rails code. I can also go to the demo website and the links work and they go to the correct pages. I have looked at the other issues other people have had with this and I can't seem to find anyone who is having the same issues. How can I go about trouble shooting this?
Update:
noahc:sample_app noahc$ rake routes
users_new GET /users/new(.:format) {:controller=>"users", :action=>"new"}
signup /signup(.:format) {:controller=>"users", :action=>"new"}
contact /contact(.:format) {:controller=>"pages", :action=>"contact"}
about /about(.:format) {:controller=>"pages", :action=>"about"}
help /help(.:format) {:controller=>"pages", :action=>"help"}
/help(.:format) {:controller=>"pages", :action=>"help"}
root / {:controller=>"pages", :action=>"home"}
pages_home GET /pages/home(.:format) {:controller=>"pages", :action=>"home"}
pages_contact GET /pages/contact(.:format) {:controller=>"pages", :action=>"contact"}
pages_about GET /pages/about(.:format) {:controller=>"pages", :action=>"about"}
pages_help GET /pages/help(.:format) {:controller=>"pages", :action=>"help"}
Upvotes: 0
Views: 736
Reputation: 5706
Noah, I would recommend splitting that test up into multiple tests, one for each title that you would like to test. That will make it a little easier for you to pinpoint exactly what's wrong. Something like this:
it "should have a link to 'Help'" do
visit root_path
response.should have_selector('a', :href => help_path, :content => "Help")
click_link "Help"
response.should have_selector('title', :content => 'Help')
end
it "should have a link to 'Contact'" do
visit root_path
response.should have_selector('a', :href => contact_path, :content => "Contact")
click_link "Help"
response.should have_selector('title', :content => 'Contact')
end
etc... This will make it easier to pinpoint exactly what is going on, and where you're experiencing a problem. Also, what did it say was being displayed in the page's source? You cut off the error message before it explained what really happened in your paste snippet... Look inside what the code that is actually being returned says to see what the title is and how/why it is differing from what rspec is expecting.
Upvotes: 1
Reputation: 26979
I don't use rspec, but could be because "Home" != "Ruby on Rails Tutorial Sample App | Home"
The contents do not match at all, so the test fails.
Also, check your help link in your source to be sure it is in fact going where you think it is...
Upvotes: 1