[英]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.