问题描述
一直遵循Michael Hart
在Mac OS X 10.7上使用Rails 3.0的Rails教程
Have been following Rails Tutorial by Michael Hartrails version 3.0 on mac OS X 10.7
$ rspec spec /
$ rspec spec/
......FF
Failures:
1) PagesController GET 'help' should be successful
Failure/Error: get 'help'
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>"help"}
# ./spec/controllers/pages_controller_spec.rb:45:in `block (3 levels) in <top (required)>'
2) PagesController GET 'help' should have the right title
Failure/Error: get 'help'
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>"help"}
# ./spec/controllers/pages_controller_spec.rb:49:in `block (3 levels) in <top (required)>'
Finished in 0.14686 seconds
8 examples, 2 failures
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:44 # PagesController GET 'help' should be successful
rspec ./spec/controllers/pages_controller_spec.rb:48 # PagesController GET 'help' should have the right title
测试看起来像这样:
require 'spec_helper'
describe PagesController do
render_views
describe "GET 'home'" do
it "should be successful" do
get 'home'
response.should be_success
end
it "should have the right title" do
get 'home'
response.should have_selector("title",
:content => "Ruby on Rails Tutorial Sample App | Home")
end
end
describe "GET 'contact'" do
it "should be successful" do
get 'contact'
response.should be_success
end
it "should have the right title" do
get 'contact'
response.should have_selector("title",
:content => "Ruby on Rails Tutorial Sample App | Contact")
end
end
describe "GET 'about'" do
it "should be successful" do
get 'about'
response.should be_success
end
it "should have the right title" do
get 'about'
response.should have_selector("title",
:content => "Ruby on Rails Tutorial Sample App | About")
end
end
describe "GET 'help'" do
it "should be successful" do
get 'help'
response.should be_success
end
it "should have the right title" do
get 'help'
response.should have_selector("title",
:content => "Ruby on Rails Tutorial Sample App | Help")
end
end
end
我在pages_controller.rb
And I have in 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
而在route.rb中,我有
And in routes.rb I have
SampleApp::Application.routes.draw do
get "pages/home"
get "pages/contact"
get "pages/about"
get "pages/help"
end
当然,我也在app / views / pages
中创建了一个help.html.erb页面。奇怪的是,当我运行rails服务器并转到localhost:3000 / pages / help时,我得到了具有正确标题的正确页面,使它看起来好像应该通过测试,但事实并非如此。此外,联系方式,住所和关于测试的信息都通过了,但是当我刚刚添加帮助时,出于某种未知的原因并没有。
And of course I also created a help.html.erb page in app/views/pagesThe strange thing is when I run rails server and go to localhost:3000/pages/help I get the proper page with the proper title, making it appear as if the test should've passed, yet it doesn't. Additionally the contact, home, and about tests pass but when I just now added the help it doesn't for some unknown reason. This is really bugging me out, what is the simple solution I have overlooked that it driving me insane?
推荐答案
下载了您的代码,然后跑:
Downloaded your code and ran:
........
8 examples, 0 failures
Finished in 0.18184 seconds
它正在运行GET'help',所以我认为您正在自动测试中运行它,并且它没有重新加载。可能吗?
It is running the GET 'help', so I think you're running this in autotest and it is not reloading. Possible?
这篇关于Rails pages_controller_spec.rb测试应该不会失败,但是,错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!