自从《水豚》第2.1.0版开始,就有了处理标题的方法.
page.title
page.has_title? "my title"
page.has_no_title? "my not found title"
所以你可以像这样测试标题:
expect(page).to have_title "my_title"
根据github.com/jnicklas/capybara/issues/863,以下内容也适用于水豚2.0:
expect(first('title').native.text).to eq "my title"