GET'home'应该是Michael Hartl教程第4章的正确标题

时间:2013-01-03 01:22:27

标签: ruby-on-rails ruby-on-rails-3 rspec

  

可能重复:
  Rspec test should pass but fails

为什么我收到此错误?

C:\网站\ sample_app> rspec的 〔32米。?[0米?[31mF〔0米?[32米。?[0米?[31mF〔0米?[32米。?[0米?[31mF?[0米

故障:

1)PagesController GET'home'应该有正确的标题      ?[31mFailure /错误:?[0m?[31mresponse.should have_selector(“title”,?[0m]      ?[31mNoMethodError:[0米        ?[31]定义方法has_selector?' for #<ActionController::TestResponse:0x4162ce0>?[0m ?[36m # ./spec/controllers/pages_controller_spec.rb:14:in阻止(3级)'?[0m

2)PagesController GET'contact'应该有正确的标题      ?[31mFailure /错误:?[0m?[31mresponse.should have_selector(“title”,?[0m]      ?[31mNoMethodError:[0米        ?[31]定义方法has_selector?' for #<ActionController::TestResponse:0x3eab898>?[0m ?[36m # ./spec/controllers/pages_controller_spec.rb:27:in阻止(3级)'?[0m

3)PagesController GET'all'应该有正确的标题      ?[31mFailure /错误:?[0m?[31mresponse.should have_selector(“title”,?[0m]      ?[31mNoMethodError:[0米        ?[31]定义方法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??m?[36m #PagesController GET'home'应该有正确的标题?[0m ?[31mrspec ./spec/controllers/pages_controller_spec.rb:25??m?[36m#PagesController GET'contact'应该有正确的标题?[0m ?[31mrspec ./spec/controllers/pages_controller_spec.rb:39?[0m?[36m#PagesController获取'关于'应该有正确的标题?[0m

用种子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'”   它“应该是成功的”   回家'   response.should be_success   端

     

它“应该有正确的标题”   回家'   response.should have_selector(“title”,   :content =&gt; “Ruby on Rails教程示例应用程序|主页”)   结束   端

     

描述“GET'联系'”   它“应该是成功的”   得到'联系'   response.should be_success   端

     

它“应该有正确的标题”   得到'联系'   response.should have_selector(“title”,   :content =&gt;   “Ruby on Rails教程示例应用程序|联系方式”)   结束   端

     

描述“GET”关于“”   它“应该是成功的”   得到'约'   response.should be_success   端

     

它“应该有正确的标题”   得到'约'   response.should have_selector(“title”,   :content =&gt;   “Ruby on Rails教程示例应用程序|关于”)       结束     结束   端

如果您还需要其他内容,请添加并感谢

1 个答案:

答案 0 :(得分:0)

您需要base_title方法返回您要测试的确切字符串。在本例中,“Ruby on Rails Tutorial Sample App”。目前,您将标题设置为“Ruby on Railys tut示例应用程序”。