From d0d1c9972c60d33189c15776af5dafd7407c52ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 28 Sep 2019 01:11:42 +0200 Subject: [PATCH] Remove unused variables following their parent There's a very common pattern in our test, where the setup only has two lines: variable = create(:something) unused_variable = create(:something_else, something: variable) In this case, since there's a blank line below these ones and then we'll get to the body of the test, and the second variable is going to be created based on the first variable, we can remove the useless assignment and the readability is still OK. Another option we almost unanimously discarded was: variable = create(:something) _unused_variable = create(:something_else, something: variable) We don't use it anywhere else, either. One more option we considered but found a bit too much for simple tests: variable = create(:something) do |something| create(:something_else, something: variable) end Then of course we could move the setup to `let` and `before` blocks, but the tests could get over-structured really quickly. --- spec/features/admin/legislation/draft_versions_spec.rb | 2 +- .../admin/poll/questions/answers/answers_spec.rb | 2 +- spec/features/budgets/executions_spec.rb | 3 +-- spec/features/dashboard/dashboard_spec.rb | 2 +- spec/features/notifications_spec.rb | 2 +- spec/features/officing/voters_spec.rb | 10 +++++----- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/spec/features/admin/legislation/draft_versions_spec.rb b/spec/features/admin/legislation/draft_versions_spec.rb index 06808979f..6880dc927 100644 --- a/spec/features/admin/legislation/draft_versions_spec.rb +++ b/spec/features/admin/legislation/draft_versions_spec.rb @@ -69,7 +69,7 @@ describe "Admin legislation draft versions" do context "Update" do scenario "Valid legislation draft version", :js do process = create(:legislation_process, title: "An example legislation process") - draft_version = create(:legislation_draft_version, title: "Version 1", process: process) + create(:legislation_draft_version, title: "Version 1", process: process) visit admin_root_path diff --git a/spec/features/admin/poll/questions/answers/answers_spec.rb b/spec/features/admin/poll/questions/answers/answers_spec.rb index a2d0c78bc..96212cd48 100644 --- a/spec/features/admin/poll/questions/answers/answers_spec.rb +++ b/spec/features/admin/poll/questions/answers/answers_spec.rb @@ -24,7 +24,7 @@ describe "Answers" do scenario "Create second answer and place after the first one" do question = create(:poll_question) - answer = create(:poll_question_answer, title: "First", question: question, given_order: 1) + create(:poll_question_answer, title: "First", question: question, given_order: 1) visit admin_question_path(question) click_link "Add answer" diff --git a/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index a6896885b..c370a43cf 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -291,8 +291,7 @@ describe "Executions" do scenario "Milestone not yet published" do status = create(:milestone_status) - unpublished_milestone = create(:milestone, milestoneable: investment1, - status: status, publication_date: Date.tomorrow) + create(:milestone, milestoneable: investment1, status: status, publication_date: Date.tomorrow) visit budget_executions_path(budget, status: status.id) diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb index 46952266b..6eee343ab 100644 --- a/spec/features/dashboard/dashboard_spec.rb +++ b/spec/features/dashboard/dashboard_spec.rb @@ -133,7 +133,7 @@ describe "Proposal's dashboard" do scenario "Dashboard progress can unexecute proposed action" do action = create(:dashboard_action, :proposed_action, :active) - executed_action = create(:dashboard_executed_action, proposal: proposal, action: action) + create(:dashboard_executed_action, proposal: proposal, action: action) visit progress_proposal_dashboard_path(proposal) expect(page).to have_content(action.title) diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index f9d60ffb3..4dd3a891f 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -39,7 +39,7 @@ describe "Notifications" do scenario "View single notification" do proposal = create(:proposal) - notification = create(:notification, user: user, notifiable: proposal) + create(:notification, user: user, notifiable: proposal) click_notifications_icon diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 167cb8443..e2dc73e1e 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -37,7 +37,7 @@ describe "Voters" do scenario "Cannot vote" do unvotable_poll = create(:poll, :current, geozone_restricted: true, geozones: [create(:geozone, census_code: "02")]) - officer_assignment = create(:poll_officer_assignment, officer: officer, poll: unvotable_poll, booth: booth) + create(:poll_officer_assignment, officer: officer, poll: unvotable_poll, booth: booth) set_officing_booth(booth) visit new_officing_residence_path @@ -87,7 +87,7 @@ describe "Voters" do scenario "Display current polls assigned to a booth" do poll = create(:poll, :current) - officer_assignment = create(:poll_officer_assignment, officer: officer, poll: poll, booth: booth) + create(:poll_officer_assignment, officer: officer, poll: poll, booth: booth) set_officing_booth(booth) visit new_officing_residence_path @@ -99,7 +99,7 @@ describe "Voters" do scenario "Display polls that the user can vote" do votable_poll = create(:poll, :current, geozone_restricted: true, geozones: [Geozone.first]) - officer_assignment = create(:poll_officer_assignment, officer: officer, poll: votable_poll, booth: booth) + create(:poll_officer_assignment, officer: officer, poll: votable_poll, booth: booth) set_officing_booth(booth) visit new_officing_residence_path @@ -111,7 +111,7 @@ describe "Voters" do scenario "Display polls that the user cannot vote" do unvotable_poll = create(:poll, :current, geozone_restricted: true, geozones: [create(:geozone, census_code: "02")]) - officer_assignment = create(:poll_officer_assignment, officer: officer, poll: unvotable_poll, booth: booth) + create(:poll_officer_assignment, officer: officer, poll: unvotable_poll, booth: booth) set_officing_booth(booth) visit new_officing_residence_path @@ -123,7 +123,7 @@ describe "Voters" do scenario "Do not display expired polls" do expired_poll = create(:poll, :expired) - officer_assignment = create(:poll_officer_assignment, officer: officer, poll: expired_poll, booth: booth) + create(:poll_officer_assignment, officer: officer, poll: expired_poll, booth: booth) set_officing_booth(booth) visit new_officing_residence_path