From 0945f046a33175743a224ddeeeabe40118a152a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 27 Sep 2018 17:44:03 +0200 Subject: [PATCH] Avoid using xpath in specs Using xpath is usually harder to read and more fragile. --- .../legislation/proposals/_proposals.html.erb | 4 +-- .../admin/legislation/proposals_spec.rb | 36 +++++++------------ 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/app/views/admin/legislation/proposals/_proposals.html.erb b/app/views/admin/legislation/proposals/_proposals.html.erb index a18d0b623..2f75b4223 100644 --- a/app/views/admin/legislation/proposals/_proposals.html.erb +++ b/app/views/admin/legislation/proposals/_proposals.html.erb @@ -3,7 +3,7 @@ <%= render 'shared/wide_order_selector', i18n_namespace: "admin.legislation.processes.proposals" %> - +
@@ -15,7 +15,7 @@ <% proposals.each do |proposal| %> - + diff --git a/spec/features/admin/legislation/proposals_spec.rb b/spec/features/admin/legislation/proposals_spec.rb index 5be2bf08b..bd8caf0a3 100644 --- a/spec/features/admin/legislation/proposals_spec.rb +++ b/spec/features/admin/legislation/proposals_spec.rb @@ -42,16 +42,10 @@ feature 'Admin legislation processes' do visit admin_legislation_process_proposals_path(process.id) select "Title", from: "order-selector-participation" - within('#proposals_table') do - within(:xpath, "//tbody/tr[1]") do - expect(page).to have_content('aaaa') - end - within(:xpath, "//tbody/tr[2]") do - expect(page).to have_content('bbbb') - end - within(:xpath, "//tbody/tr[3]") do - expect(page).to have_content('cccc') - end + within('#legislation_proposals_list') do + within all('.legislation_proposal')[0] { expect(page).to have_content('aaaa') } + within all('.legislation_proposal')[1] { expect(page).to have_content('bbbb') } + within all('.legislation_proposal')[2] { expect(page).to have_content('cccc') } end end @@ -64,10 +58,10 @@ feature 'Admin legislation processes' do visit admin_legislation_process_proposals_path(process.id) select "Supports", from: "order-selector-participation" - within('#proposals_table') do - within(:xpath, "//tbody/tr[1]") { expect(page).to have_content('30') } - within(:xpath, "//tbody/tr[2]") { expect(page).to have_content('20') } - within(:xpath, "//tbody/tr[3]") { expect(page).to have_content('10') } + within('#legislation_proposals_list') do + within all('.legislation_proposal')[0] { expect(page).to have_content('30') } + within all('.legislation_proposal')[1] { expect(page).to have_content('20') } + within all('.legislation_proposal')[2] { expect(page).to have_content('10') } end end @@ -80,16 +74,10 @@ feature 'Admin legislation processes' do visit admin_legislation_process_proposals_path(process.id, order: :title) select "Id", from: "order-selector-participation" - within('#proposals_table') do - within(:xpath, "//tbody/tr[1]") do - expect(page).to have_content(proposal1.id) - end - within(:xpath, "//tbody/tr[2]") do - expect(page).to have_content(proposal2.id) - end - within(:xpath, "//tbody/tr[3]") do - expect(page).to have_content(proposal3.id) - end + within('#legislation_proposals_list') do + within all('.legislation_proposal')[0] { expect(page).to have_content(proposal1.id) } + within all('.legislation_proposal')[1] { expect(page).to have_content(proposal2.id) } + within all('.legislation_proposal')[2] { expect(page).to have_content(proposal3.id) } end end end
<%= t("admin.legislation.proposals.index.id") %>
<%= proposal.id %> <%= proposal.title %> <%= proposal.cached_votes_up %>