Declare local variables outside a block

We couldn't declare them inside the block because they would be
considered local variables and its value would be lost when the block
was finished. So we were using instance variables instead.

However, with instance variables we don't get any warnings when we
misspell their names. We can avoid them by declaring the local variables
before the block starts.
This commit is contained in:
Javi Martín
2019-09-29 15:41:17 +02:00
parent 91c21b0982
commit 86366da28c
2 changed files with 21 additions and 13 deletions

View File

@@ -37,28 +37,31 @@ describe "Legislation Proposals" do
let(:per_page) { 12 }
scenario "Each user has a different and consistent random proposals order", :js do
first_user_proposals_order = nil
second_user_proposals_order = nil
in_browser(:one) do
login_as user
visit legislation_process_proposals_path(process)
@first_user_proposals_order = legislation_proposals_order
first_user_proposals_order = legislation_proposals_order
end
in_browser(:two) do
login_as user2
visit legislation_process_proposals_path(process)
@second_user_proposals_order = legislation_proposals_order
second_user_proposals_order = legislation_proposals_order
end
expect(@first_user_proposals_order).not_to eq(@second_user_proposals_order)
expect(first_user_proposals_order).not_to eq(second_user_proposals_order)
in_browser(:one) do
visit legislation_process_proposals_path(process)
expect(legislation_proposals_order).to eq(@first_user_proposals_order)
expect(legislation_proposals_order).to eq(first_user_proposals_order)
end
in_browser(:two) do
visit legislation_process_proposals_path(process)
expect(legislation_proposals_order).to eq(@second_user_proposals_order)
expect(legislation_proposals_order).to eq(second_user_proposals_order)
end
end
end