From 36e2610919f174a16e42d1734d49dfe4bcb60a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 26 Mar 2021 15:21:37 +0100 Subject: [PATCH] Use have_link to check for links in tests Using `have_selector` Capybara might detect `` tags which are not links because they don't have an `href` attribute. Besides, with `have_selector` Capybara only detects visible text, which means it won't detect links which are icons with tooltips. --- spec/system/admin/dashboard/actions_spec.rb | 2 +- spec/system/admin/poll/questions_spec.rb | 24 ++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/system/admin/dashboard/actions_spec.rb b/spec/system/admin/dashboard/actions_spec.rb index 71d73415e..4e7a8e78a 100644 --- a/spec/system/admin/dashboard/actions_spec.rb +++ b/spec/system/admin/dashboard/actions_spec.rb @@ -21,7 +21,7 @@ describe "Admin dashboard actions", :admin do expect(page).to have_content("Email") expect(page).to have_content("Poster") - expect(page).to have_selector("a", text: "Edit", count: 3) + expect(page).to have_link "Edit", count: 3 end end diff --git a/spec/system/admin/poll/questions_spec.rb b/spec/system/admin/poll/questions_spec.rb index d71b0fd95..3432f221f 100644 --- a/spec/system/admin/poll/questions_spec.rb +++ b/spec/system/admin/poll/questions_spec.rb @@ -15,30 +15,30 @@ describe "Admin poll questions", :admin do within("#poll_question_#{question1.id}") do expect(page).to have_content(question1.title) - expect(page).to have_content("Edit answers") - expect(page).to have_content("Edit") - expect(page).to have_content("Delete") + expect(page).to have_link "Edit answers" + expect(page).to have_link "Edit" + expect(page).to have_link "Delete" end visit admin_poll_path(poll2) expect(page).to have_content(poll2.name) within("#poll_question_#{question2.id}") do - expect(page).to have_content(question2.title) - expect(page).to have_content("Edit answers") - expect(page).to have_content("Edit") - expect(page).to have_content("Delete") + expect(page).to have_content question2.title + expect(page).to have_link "Edit answers" + expect(page).to have_link "Edit" + expect(page).to have_link "Delete" end visit admin_poll_path(poll3) expect(page).to have_content(poll3.name) within("#poll_question_#{question3.id}") do - expect(page).to have_content(question3.title) - expect(page).to have_link("(See proposal)", href: proposal_path(question3.proposal)) - expect(page).to have_content("Edit answers") - expect(page).to have_content("Edit") - expect(page).to have_content("Delete") + expect(page).to have_content question3.title + expect(page).to have_link "(See proposal)", href: proposal_path(question3.proposal) + expect(page).to have_link "Edit answers" + expect(page).to have_link "Edit" + expect(page).to have_link "Delete" end end