以下の例では、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仕様の何が問題なのか、私にはまったくわかりません。