从这里开始:
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 和他的链接,部分解决了:How can I test the page title with Capybara 2.0?
关于ruby-on-rails - 在 rails 中使用 rspec 测试标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28496571/