Possible Duplicate:
Rspec test should pass but failsGET「家」應該有邁克爾·哈特爾的教程
爲什麼會出現這種錯誤的正確標題第4章?
C:\ Sites \ sample_app> rspec ?[32m。[0m?[31mF?[0m?[31mF?[0m?[32m。?[0m? [0米
失敗:
1)PagesController GET '家' 應該有正確的標題 [31mFailure /錯誤:?[0分[31mresponse.should have_selector( 「稱號」,[0米 ??? [31mNoMethodError:[0米 [31mundefined方法has_selector?' for #<ActionController::TestResponse:0x4162ce0>?[0m ?[36m # ./spec/controllers/pages_controller_spec.rb:14:in
塊(3級)在接觸'應具有鑽機?「[0米
2)PagesController GET? hm title ?[31mFailure/Error:?[0m?[31mresponse.should have_selector(「title」,?[0m ?[31mNoMethodError:?[0m ?[31medefined method has_selector?' for #<ActionController::TestResponse:0x3eab898>?[0m ?[36m # ./spec/controllers/pages_controller_spec.rb:27:in
block(3 levels)in'?[0m
3)PagesController GET '約' 應該有正確的標題 [31mFailure /錯誤:?[0分[31mresponse.should have_selector( 「稱號」,[0米 [31mNoMethodError:????[0米 ? [31mundefined方法has_selector?' for #<ActionController::TestResponse:0x3f1ccb0>?[0m ?[36m # ./spec/controllers/pages_controller_spec.rb:41:in
塊(3級)在「?[0米
在5.15秒 ?[31m6實例中,3次失敗完成?[0米
點失敗的例子:??
[31mrspec ./spec/controllers/pages_controller_spec.rb:12?[0m [36米#PagesController GET '家' 應該有正確的標題[0米 [31mrspec ./? spec/controllers/pages_controller_spec.rb:25?[0m?[36m#PagesController GET'contact'should be right title?[0m ?[31mrspec ./spec/controllers/pages_controller_spec.rb:39?[0m?[36m #PagesController GET '約' 應該有正確的標題?[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
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 end
如果您需要別的東西只是添加和感謝
還是得到了同樣的錯誤 –
創業板安裝需要在#安裝webrat寶石 創業板安裝 'webrat' > {RAILS_ROOT}/Gemfile中 '引入nokogiri' #: >組:測試做 >寶石 'webrat' > end > in#{RAILS_ROOT} /spec/spec_helper.rb(在文件末尾): >#Webrat配置 > Webrat.configure do | config | > config.mode =:rails 。結束它現在起作用了!我會在7個小時內回答我自己的問題,以幫助其他可能存在問題的人。我不能現在,因爲我的代表 –
是的,與網頁的問題。我應該仔細閱讀錯誤信息。 – DevinR