可能重复:
Rspec 测试应该通过但失败
为什么我会收到此错误?
C:\Sites\sample_app>rspec ?[32m.?[0m?[31mF?[0m?[32m.?[0m?[31mF?[0m?[32m.?[0m?[31mF?[0m
失败:
1) PagesController GET 'home' 应该有正确的标题 ?[31mFailure/Error:?[0m ?[31mresponse.should have_selector("title",?[0m ?[31mNoMethodError:?[0m ?[31mundefined 方法has_selector?' for #<ActionController::TestResponse:0x4162ce0>?[0m
?[36m # ./spec/controllers/pages_controller_spec.rb:14:in
块(3级) ) 在 '?[0m
2) PagesController GET 'contact' 应该有正确的标题 ?[31mFailure/Error:?[0m ?[31mresponse.should have_selector("title",?[0m ?[31mNoMethodError:?[0m ?[31mundefined 方法has_selector?' for #<ActionController::TestResponse:0x3eab898>?[0m
?[36m # ./spec/controllers/pages_controller_spec.rb:27:in
块(3级) ) 在 '?[0m
3) PagesController GET 'about' 应该有正确的标题 ?[31mFailure/Error:?[0m ?[31mresponse.should have_selector("title",?[0m ?[31mNoMethodError:?[0m ?[31mundefined 方法has_selector?' for #<ActionController::TestResponse:0x3f1ccb0>?[0m
?[36m # ./spec/controllers/pages_controller_spec.rb:41:in
块 (3 个级别) ) 在 '?[0m
5.15秒完成?[31m6个例子,3次失败?[0m
失败的例子:
?[31mrspec ./spec/controllers/pages_controller_spec.rb:12?[0m ?[36m# PagesController GET 'home' 应该有正确的标题?[0m ?[31mrspec ./spec/controllers/pages_controller_spec.rb:25?[ 0m ?[36m# PagesController GET 'contact' 应该有正确的标题?[0m ?[31mrspec ./spec/controllers/pages_controller_spec.rb:39?[0m ?[36m# PagesController GET 'about' 应该有正确的标题? [0米
用种子 501 随机化
Application_helper.rb
模块 ApplicationHelper
# Retrun a title on a per-page basic.
def title
base_title = "Ruby on Railys tut sample app"
if @title.nil?
base_title
else
"#{base_title} | #{@title}"
end
end
结尾
Pages_controller_spec.rb
需要'spec_helper'
描述 PagesController 做 render_views
描述“GET'home'”做它“应该成功”做得到'home'response.should be_success end
它“应该有正确的标题”确实得到 'home' response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Home") end end
描述“GET 'contact'”做它“应该成功”做得到'contact' response.should be_success end
它“应该有正确的标题”确实得到 'contact' response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Contact") end end
描述“获取'关于'”做它“应该成功”做得到'关于'响应。应该是_成功结束
它“应该有正确的标题”确实得到“关于”响应。应该有_selector(“标题”,:content =>“Ruby on Rails教程示例应用程序|关于”)结束结束结束
如果您需要其他内容,请添加并感谢