From 9db4fb593c0414d6186129466c1f1e34359f31a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 10 Apr 2021 18:40:09 +0200 Subject: [PATCH] Simplify tests switching to a new window --- spec/system/dashboard/polls_spec.rb | 6 +----- spec/system/dashboard/poster_spec.rb | 4 +--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/spec/system/dashboard/polls_spec.rb b/spec/system/dashboard/polls_spec.rb index 367cc1c08..33647a008 100644 --- a/spec/system/dashboard/polls_spec.rb +++ b/spec/system/dashboard/polls_spec.rb @@ -256,11 +256,7 @@ describe "Polls" do visit proposal_dashboard_polls_path(proposal) - within "div#poll_#{poll.id}" do - click_link "View results" - end - - page.driver.browser.switch_to.window page.driver.browser.window_handles.last do + within_window(window_opened_by { click_link "View results" }) do expect(page).to have_current_path(results_proposal_poll_path(proposal, poll)) end end diff --git a/spec/system/dashboard/poster_spec.rb b/spec/system/dashboard/poster_spec.rb index f63333741..ad591a905 100644 --- a/spec/system/dashboard/poster_spec.rb +++ b/spec/system/dashboard/poster_spec.rb @@ -31,9 +31,7 @@ describe "Poster" do end scenario "PDF contains the proposal details" do - click_link "Download" - - page.driver.browser.switch_to.window page.driver.browser.window_handles.last do + within_window(window_opened_by { click_link "Download" }) do expect(page).to have_content(proposal.title) expect(page).to have_content(proposal.code) end