1

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

4

1 に答える 1

1

さて、私の実験では、単に have_field をテストする代わりに

it { should have_field "user_password" }

フィールドタイプを明示的に設定する必要があります

it { should have_field "user_password", :type => :password }

その後、テストに合格します。(注意してください! type 設定では 'password' ではなく、:password を使用してください)。

パスワードに値がないことを確認する必要がある場合は、通常どおりに実行できます

it { should have_field "user_password", :type => :password, :with => nil }
于 2012-12-31T21:50:54.200 に答える