Remove instance variables in RSpec

Instance variables might lead to hard-to-detect issues, since using a
nonexistent instance variable will return `nil` instead of raising an
error.
This commit is contained in:
Javi Martín
2019-09-29 14:01:55 +02:00
parent f70e10fe9f
commit 91c21b0982
39 changed files with 639 additions and 667 deletions

View File

@@ -17,37 +17,33 @@ describe "Legislation" do
end
context "process empty" do
before do
@process = create(:legislation_process, :empty, end_date: Date.current - 1.day)
end
let(:process) { create(:legislation_process, :empty, end_date: Date.current - 1.day) }
scenario "warning empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("The process have no phases.")
end
end
context "phases empty" do
before do
@process = create(:legislation_process, end_date: Date.current - 1.day)
end
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
scenario "debates empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase")
expect(page).to have_content("No debates")
expect(page).to have_content("There aren't any questions")
end
scenario "proposals empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase")
expect(page).to have_content("No proposals")
expect(page).to have_content("There are no proposals")
end
scenario "text comments empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase")
expect(page).to have_content("No comments")
expect(page).to have_content("There are no text comments")
@@ -55,31 +51,29 @@ describe "Legislation" do
end
context "process empty" do
before do
@process = create(:legislation_process, :empty, end_date: Date.current - 1.day)
end
let(:process) { create(:legislation_process, :empty, end_date: Date.current - 1.day) }
scenario "warning empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("The process have no phases.")
end
end
context "only debates exist" do
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
before do
user = create(:user, :level_two)
@process = create(:legislation_process, end_date: Date.current - 1.day)
@debate = create(:legislation_question, process: @process, title: "Question 1")
@debate = create(:legislation_question, process: process, title: "Question 1")
create(:comment, user: user, commentable: @debate, body: "Answer 1")
create(:comment, user: user, commentable: @debate, body: "Answer 2")
@debate = create(:legislation_question, process: @process, title: "Question 2")
@debate = create(:legislation_question, process: process, title: "Question 2")
create(:comment, user: user, commentable: @debate, body: "Answer 3")
create(:comment, user: user, commentable: @debate, body: "Answer 4")
end
scenario "show debates list" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase")
expect(page).to have_content("2 debates")
@@ -97,7 +91,7 @@ describe "Legislation" do
expect(page).not_to have_content("Answer 3")
expect(page).not_to have_content("Answer 4")
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
click_link "Question 2"
expect(page).to have_content("Question 2")
expect(page).not_to have_content("Answer 1")
@@ -108,14 +102,14 @@ describe "Legislation" do
end
scenario "proposals empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase")
expect(page).to have_content("No proposals")
expect(page).to have_content("There are no proposals")
end
scenario "text comments empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase")
expect(page).to have_content("No comments")
expect(page).to have_content("There are no text comments")
@@ -123,27 +117,28 @@ describe "Legislation" do
end
context "only proposals exist" do
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
before do
@process = create(:legislation_process, end_date: Date.current - 1.day)
create(:legislation_proposal, legislation_process_id: @process.id,
create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 1", selected: true)
create(:legislation_proposal, legislation_process_id: @process.id,
create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 2", selected: false)
create(:legislation_proposal, legislation_process_id: @process.id,
create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 3", selected: true)
create(:legislation_proposal, legislation_process_id: @process.id,
create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 4", selected: false)
end
scenario "debates empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase")
expect(page).to have_content("No debates")
expect(page).to have_content("There aren't any questions")
end
scenario "proposals empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase")
expect(page).to have_content("2 proposals")
@@ -155,14 +150,14 @@ describe "Legislation" do
click_link "Legislation proposal 1"
expect(page).to have_content("Legislation proposal 1")
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
click_link "Legislation proposal 3"
expect(page).to have_content("Legislation proposal 3")
end
scenario "text comments empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase")
expect(page).to have_content("No comments")
expect(page).to have_content("There are no text comments")
@@ -170,13 +165,14 @@ describe "Legislation" do
end
context "only text comments exist" do
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
before do
user = create(:user, :level_two)
@process = create(:legislation_process, end_date: Date.current - 1.day)
draft_version_1 = create(:legislation_draft_version, process: @process,
draft_version_1 = create(:legislation_draft_version, process: process,
title: "Version 1", body: "Body of the first version",
status: "published")
draft_version_2 = create(:legislation_draft_version, process: @process,
draft_version_2 = create(:legislation_draft_version, process: process,
title: "Version 2", body: "Body of the second version and that's it all of it",
status: "published")
annotation0 = create(:legislation_annotation,
@@ -196,21 +192,21 @@ describe "Legislation" do
end
scenario "debates empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase")
expect(page).to have_content("No debates")
expect(page).to have_content("There aren't any questions")
end
scenario "proposals empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase")
expect(page).to have_content("No proposals")
expect(page).to have_content("There are no proposals")
end
scenario "text comments empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase (version Version 2")
expect(page).to have_content("5 comments")
expect(page).not_to have_content("Comment 0")
@@ -223,7 +219,7 @@ describe "Legislation" do
end
# scenario "excel download" do
# visit resume_legislation_process_path(@process)
# visit resume_legislation_process_path(process)
# click_link "Download"
# page.response_headers['Content-Type'].should eq "application/xlsx"
# end
@@ -234,9 +230,9 @@ describe "Legislation" do
before do
user = create(:user, :level_two)
@process = create(:legislation_process, end_date: Date.current - 1.day)
@debate = create(:legislation_question, process: @process, title: "Question 1")
create(:comment, user: user, commentable: @debate, body: "Answer 1")
create(:comment, user: user, commentable: @debate, body: "Answer 2")
debate = create(:legislation_question, process: @process, title: "Question 1")
create(:comment, user: user, commentable: debate, body: "Answer 1")
create(:comment, user: user, commentable: debate, body: "Answer 2")
end
it "download execl file test" do