[英]Test title with rspec in rails
從這個開始:
it "doit avoir le bon titre" do
get 'home'
response.should have_selector("title", :content => "Simple App du Tutoriel Ruby on Rails | Accueil")
end
我最終以為是因為我所使用的教程與所使用的教程不在同一版本的rspec或rails上:
it "doit avoir le bon titre" do
get 'home'
expect(response).to have_selector("title", :text => "Simple App du Tutoriel Ruby on Rails | Accueil")
end
現在它告訴我
Failure/Error: expect(response).to have_selector("title", :text => "Simple App du Tutoriel Ruby on Rails | Accueil")
expected to find css "title" with text "Simple App du Tutoriel Ruby on Rails | Accueil" but there were no matches
當我只想驗證標題時,為什么要談論CSS? 考慮到我想做第一批代碼示例,我做對了嗎?
顯然不是因為我有錯誤,而是我在做什么錯?
謝謝。
正確的語法是:
it "doit avoir le bon titre" do
get :home
expect(response.body).to have_title('Simple App du Tutoriel Ruby on Rails | Accueil')
end
感謝Siekfried及其鏈接,部分解決了問題: 如何使用 Capybara 2.0測試頁面標題?
您是否嘗試過:
it "doit avoir le bon titre" do
get :home
expect(response.body).to include('<title>My Title</title>')
end
end
??
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.