已经由迈克尔·哈特 以下的Rails教程Mac OS X上轨3.0版本10.7Rails pages_controller_spec.rb测试不应该失败,但是,错误?
$ rspec的投机/
......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
而且我有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
而在routes.rb中我有
SampleApp::Application.routes.draw do
get "pages/home"
get "pages/contact"
get "pages/about"
get "pages/help"
end
当然,我也创造了在应用程序/视图/ 奇怪的是,当我运行轨道服务器并转到本地主机页面help.html.erb页:3000/pages/help我用合适的标题获得适当的页面,使其看起来好像测试应该已经通过,但事实并非如此。此外,联系人,家庭和关于测试通过,但当我刚刚添加的帮助它不是因为某些未知的原因。这真的让我感到困扰,我忽略了这个简单的解决方案,它让我疯了吗?
出于某种原因,我help.html.erb文件是275个字节,而我的约,接触和家庭.html.erb页面都是2KB,尽管他们几乎是准确的每个字符的数量相同。这肯定与help.html.erb在测试时不起作用有关。此外,帮助的文档类型是TextMate文档,而其他文档只是说“文档”。奇怪..? – Laser 2012-01-18 20:38:05
我认为你在正确的轨道上 - 代码中没有任何东西看起来会失败。我会尝试删除并重新创建help.html.erb文件。 – 2012-01-18 20:39:50
感谢您的想法,不幸的是它没有帮助。特别奇怪的是,它给我一个错误,耙路线是矛盾的,因为在这里解释:http://stackoverflow.com/questions/8917201/my-computer-hates-me – Laser 2012-01-18 20:55:36