RSpecテストを作成してテキストフィールドに入力しようとすると、次のエラーが表示されます。RSpecテストを書くときにエラーが発生するCapybara :: ElementNotFound:フィールドが見つからない
1) coordinators/new.html.erb populate page name text entry field filled checks for presence of filled in text field
Failure/Error: fill_in "coordinator_name", with: 'JoeJoe'
Capybara::ElementNotFound:
Unable to find field "coordinator_name"
# ./spec/views/coordinators/new.html.erb_spec.rb:47:in `block (4 levels) in <top (required)>'
ここには、「コーディネーター名」フィールドがある前のテストを含む、私のコードの一部です。 2回目のテストでなぜそれが見つからないのか混乱していますか?
describe 'name text entry field' do
it 'checks for presence of empty text field for name' do
expect(rendered).to have_field('coordinator_name', text: nil)
end
end
describe 'name text entry field filled' do
it 'checks for presence of filled in text field' do
fill_in "coordinator_name", with: 'JoeJoe'
expect(rendered).to have_field('coordinator_name', text: 'JoeJoe')
end
end
解決方法のヒントはありますか?
あなたのテストコードは、have_fieldにhave_fieldオプションを渡していることを示しています - have_fieldは ':text'オプションをとらないので、フィールドの値をテストしようとすると':with'オプションを使いますまた、 'レンダリング'とは何ですか?私はあなたが間違っていることを見ている。 –
@KevinEtoreこれは空のファイルです(HTMLはありません)。しかし、私はsave_and_open_pageを "名前のための空のテキストフィールドの有無の確認"テストにも入れて同じことが起こります( – JSmooth