rspec shows fails where routes work OK - what's up? - problem gone away
This is weird. Looking again at my workstation this morning and running rspec spec/ to try to get some example error output to show here, all my tests succeed! I haven't changed any of the sources and I don't think I've changed anything in the config or setup (although I'm new to mac too so many of the tools are a bit like smoke 开发者_运维问答and mirrors to me).
Now I'm in a position where I know something was wrong but don't know what, and I know it's now OK, but I don't know why.
I'm going to assume there was some process that got killed and restarted overnight or when the machine woke up, and hope that I can encourage a similar fix if I get unexplained fails in the future.
What follows is now moot...
Working through a tutorial I have 5 simple routes and 5 tests just prove that the correct page is returned by checking the title in the content. All the routes work perfectly via a browser, but rspec shows 3 fails.
These are my routes...
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
match '/signup', :to => 'users#new'
root :to => 'pages#home'
rspec shows that /contact, /about and /help all get the root page (wrong), but /signup gets the proper page. / gets the home page too.
My tutorial book has no further detail and simply expects the code example to work.
The site generated works OK, it just doesn't test OK. I can continue with the tutorial but I don't want to gt into the habit of ignoring test fails.
Can anyone suggest a next step?
my tests...
require spec_helper
describe "LayoutLinks" do
.
it "should have a contact page at '/contact'" do
get '/contact
response.should have_selector('title', :content => "Contact")
end
.
it "should have a signup page at '/signup'" do
get '/signup'
response.should have_selector('title', :content => "Sign up")
end
end
My controllers...
class UsersController < ApplicationController
def new
@title = "Sign up"
end
end
class PagesController < ApplicationController
def contact
@title = "Contact"
end
def home
@title = "Home"
end
.
.
end
My application.html.erb has
<title><%= @title %></title>
and each view is given its own title by a helper
module ApplicationHelper
def title
base_title = "Ruby on Rails Tutorial Sample App"
if @title.nil?
base_title
else
"#{base_title} | #{@title}"
end
end
end
Are you using spork
? If so, when changing your routes (and some other base configuration), you need to restart it for it to pick up your changes.
精彩评论