在下面的示例中,3 个 have_field 规范失败,而 2 个 have_selector 通过。
describe "without js support", js: false do
subject { page }
it { should have_selector "form label[for='user_password']", text: "Password" }
it { should have_selector "form input#user_password[name='user[password]'][type='password'][required]" }
it { should have_field "user_password" } # check by field id
it { should have_field "user[password]" } # check by field name
it { should have_field "Password" } # check by field label
end
在正在测试的模板中,我实际上有(浏览器中禁用了 js 支持):
<label for="user_password" id="label_password">Password</label>
<input id="user_password" name="user[password]" required="required" type="password" />
have_selector 规范按预期通过,但 have_field 没有。为什么?
更有趣的是在我将示例更改为:
describe "with js support", js: true" do
...
比所有 5 个规格都变成绿色。太棒了,但我不知道,我的 nojs 规格有什么问题。