Enable RSpec/HookArgument cop and fix issues

To be consistent about before/after arguments, as `:each` or `:example`
 are same and default scopes, best not to send an argument in those
 scenarios.

Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HookArgument
This commit is contained in:
Bertocq
2018-01-07 02:07:19 +01:00
parent 39b01b6342
commit 1441de5107
25 changed files with 46 additions and 43 deletions

View File

@@ -89,4 +89,7 @@ RSpec/FilePath:
Enabled: true
RSpec/Focus:
Enabled: true
RSpec/HookArgument:
Enabled: true

View File

@@ -16,7 +16,7 @@ describe Admin::Api::StatsController do
end
context 'events present' do
before :each do
before do
time_1 = DateTime.parse("2015-01-01").in_time_zone
time_2 = DateTime.parse("2015-01-02").in_time_zone
time_3 = DateTime.parse("2015-01-03").in_time_zone

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe CommentsController do
describe 'POST create' do
before(:each) do
before do
@process = create(:legislation_process, debate_start_date: Date.current - 3.days, debate_end_date: Date.current + 2.days)
@question = create(:legislation_question, process: @process, title: "Question 1")
@user = create(:user, :level_two)

View File

@@ -3,11 +3,11 @@ require 'rails_helper'
describe DebatesController do
describe 'POST create' do
before(:each) do
before do
InvisibleCaptcha.timestamp_enabled = false
end
after(:each) do
after do
InvisibleCaptcha.timestamp_enabled = true
end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe Legislation::AnnotationsController do
describe 'POST create' do
before(:each) do
before do
@process = create(:legislation_process, allegations_start_date: Date.current - 3.days, allegations_end_date: Date.current + 2.days)
@draft_version = create(:legislation_draft_version, :published, process: @process, title: "Version 1")
@final_version = create(:legislation_draft_version, :published, :final_version, process: @process, title: "Final version")

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe Legislation::AnswersController do
describe 'POST create' do
before(:each) do
before do
@process = create(:legislation_process, debate_start_date: Date.current - 3.days, debate_end_date: Date.current + 2.days)
@question = create(:legislation_question, process: @process, title: "Question 1")
@question_option = create(:legislation_question_option, question: @question, value: "Yes")

View File

@@ -4,7 +4,7 @@ describe Users::RegistrationsController do
describe "POST check_username" do
before(:each) do
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
end

View File

@@ -21,7 +21,7 @@ describe 'Customization Engine' do
expect(test_key).to eq 'Not overriden string with custom locales'
end
after(:each) do
after do
I18n.load_path = default_path
I18n.reload!
end

View File

@@ -134,7 +134,7 @@ feature 'Budget Investments' do
end
context("Orders") do
before(:each) { budget.update(phase: 'selecting') }
before { budget.update(phase: 'selecting') }
scenario "Default order is random" do
per_page = Kaminari.config.default_per_page
@@ -266,7 +266,7 @@ feature 'Budget Investments' do
end
context 'Phase I - Accepting' do
before(:each) { budget.update(phase: 'accepting') }
before { budget.update(phase: 'accepting') }
scenario 'Create with invisible_captcha honeypot field' do
login_as(author)

View File

@@ -116,7 +116,7 @@ feature 'Emails' do
end
context 'Topic comments' do
before(:each) do
before do
@proposal = create(:proposal)
end

View File

@@ -8,7 +8,7 @@ feature 'Legislation Draft Versions' do
end
context "See draft text page" do
before(:each) do
before do
@process = create(:legislation_process)
@draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1",
body: "Body of the first version", status: "published")
@@ -80,7 +80,7 @@ feature 'Legislation Draft Versions' do
end
context "See changes page" do
before(:each) do
before do
@process = create(:legislation_process)
@draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version",
changelog: "Changes for first version", status: "published")

View File

@@ -2,7 +2,7 @@ require 'rails_helper'
feature 'Legislation' do
context 'process debate page' do
before(:each) do
before do
@process = create(:legislation_process, debate_start_date: Date.current - 3.days, debate_end_date: Date.current + 2.days)
create(:legislation_question, process: @process, title: "Question 1")
create(:legislation_question, process: @process, title: "Question 2")

View File

@@ -197,7 +197,7 @@ describe Abilities::Common do
it { should_not be_able_to(:answer, incoming_poll_question_from_other_geozone) }
context "without geozone" do
before(:each) { user.geozone = nil }
before { user.geozone = nil }
it { should_not be_able_to(:answer, poll_question_from_own_geozone) }
it { should be_able_to(:answer, poll_question_from_all_geozones) }
@@ -273,7 +273,7 @@ describe Abilities::Common do
it { should_not be_able_to(:answer, incoming_poll_question_from_other_geozone) }
context "without geozone" do
before(:each) { user.geozone = nil }
before { user.geozone = nil }
it { should_not be_able_to(:answer, poll_question_from_own_geozone) }
it { should be_able_to(:answer, poll_question_from_all_geozones) }
it { should_not be_able_to(:answer, poll_question_from_other_geozone) }

View File

@@ -9,11 +9,11 @@ describe Abilities::Valuator do
let(:non_assigned_investment) { create(:budget_investment) }
let(:assigned_investment) { create(:budget_investment, budget: create(:budget, phase: 'valuating')) }
before(:each) { assigned_investment.valuators << valuator }
before { assigned_investment.valuators << valuator }
let(:finished_assigned_investment) { create(:budget_investment, budget: create(:budget, phase: 'finished')) }
before(:each) { finished_assigned_investment.valuators << valuator }
before { finished_assigned_investment.valuators << valuator }
it { should be_able_to(:read, SpendingProposal) }
it { should be_able_to(:update, SpendingProposal) }

View File

@@ -2,7 +2,7 @@ require 'rails_helper'
describe Ahoy::DataSource do
describe '#build' do
before :each do
before do
time_1 = DateTime.parse("2015-01-01").in_time_zone
time_2 = DateTime.parse("2015-01-02").in_time_zone
time_3 = DateTime.parse("2015-01-03").in_time_zone

View File

@@ -89,8 +89,8 @@ describe Debate do
describe "#editable?" do
let(:debate) { create(:debate) }
before(:each) { Setting["max_votes_for_debate_edit"] = 3 }
after(:each) { Setting["max_votes_for_debate_edit"] = 1000 }
before { Setting["max_votes_for_debate_edit"] = 3 }
after { Setting["max_votes_for_debate_edit"] = 1000 }
it "is true if debate has no votes yet" do
expect(debate.total_votes).to eq(0)
@@ -113,8 +113,8 @@ describe Debate do
describe "#editable_by?" do
let(:debate) { create(:debate) }
before(:each) { Setting["max_votes_for_debate_edit"] = 1 }
after(:each) { Setting["max_votes_for_debate_edit"] = 1000 }
before { Setting["max_votes_for_debate_edit"] = 1 }
after { Setting["max_votes_for_debate_edit"] = 1000 }
it "is true if user is the author and debate is editable" do
expect(debate.editable_by?(debate.author)).to be true
@@ -133,7 +133,7 @@ describe Debate do
describe "#votable_by?" do
let(:debate) { create(:debate) }
before(:each) do
before do
Setting["max_ratio_anon_votes_on_debates"] = 50
end
@@ -169,7 +169,7 @@ describe Debate do
describe "#register_vote" do
let(:debate) { create(:debate) }
before(:each) do
before do
Setting["max_ratio_anon_votes_on_debates"] = 50
end
@@ -198,7 +198,7 @@ describe Debate do
end
describe "from anonymous users when anonymous votes are allowed" do
before(:each) {debate.update(cached_anonymous_votes_total: 42, cached_votes_total: 100)}
before {debate.update(cached_anonymous_votes_total: 42, cached_votes_total: 100)}
it "registers vote" do
user = create(:user)
@@ -212,7 +212,7 @@ describe Debate do
end
describe "from anonymous users when there are too many anonymous votes" do
before(:each) {debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000)}
before {debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000)}
it "does not register vote " do
user = create(:user)

View File

@@ -30,7 +30,7 @@ describe DirectMessage do
describe "maximum number of direct messages per day" do
context "when set" do
before(:each) do
before do
Setting[:direct_message_max_per_day] = 3
end
@@ -61,7 +61,7 @@ describe DirectMessage do
end
context "when unset" do
before(:each) do
before do
Setting[:direct_message_max_per_day] = nil
end

View File

@@ -30,7 +30,7 @@ describe Flag do
end
describe 'when the flag already exists' do
before(:each) { described_class.flag(user, comment) }
before { described_class.flag(user, comment) }
it 'removes an existing flag' do
expect { described_class.unflag(user, comment) }.to change{ described_class.count }.by(-1)

View File

@@ -69,7 +69,7 @@ describe Legislation::Process do
end
describe "filter scopes" do
before(:each) do
before do
@process_1 = create(:legislation_process, start_date: Date.current - 2.days, end_date: Date.current + 1.day)
@process_2 = create(:legislation_process, start_date: Date.current + 1.day, end_date: Date.current + 3.days)
@process_3 = create(:legislation_process, start_date: Date.current - 4.days, end_date: Date.current - 3.days)

View File

@@ -46,7 +46,7 @@ describe ProposalNotification do
describe "minimum interval between notifications" do
before(:each) do
before do
Setting[:proposal_notification_minimum_interval_in_days] = 3
end

View File

@@ -163,8 +163,8 @@ describe Proposal do
describe "#editable?" do
let(:proposal) { create(:proposal) }
before(:each) {Setting["max_votes_for_proposal_edit"] = 5}
after(:each) {Setting["max_votes_for_proposal_edit"] = 1000}
before {Setting["max_votes_for_proposal_edit"] = 5}
after {Setting["max_votes_for_proposal_edit"] = 1000}
it "is true if proposal has no votes yet" do
expect(proposal.total_votes).to eq(0)

View File

@@ -176,7 +176,7 @@ describe User do
end
describe 'when it is an organization' do
before(:each) { create(:organization, user: subject) }
before { create(:organization, user: subject) }
it "is true when the user is an organization" do
expect(subject.organization?).to be true
@@ -194,7 +194,7 @@ describe User do
end
describe 'when it is an organization' do
before(:each) { create(:organization, user: subject) }
before { create(:organization, user: subject) }
it "is false when the user is not a verified organization" do
expect(subject).to_not be_verified_organization
@@ -208,7 +208,7 @@ describe User do
end
describe "organization_attributes" do
before(:each) { subject.organization_attributes = {name: 'org', responsible_name: 'julia'} }
before { subject.organization_attributes = {name: 'org', responsible_name: 'julia'} }
it "triggers the creation of an associated organization" do
expect(subject.organization).to be

View File

@@ -19,7 +19,7 @@ ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
config.after :each do
config.after do
Warden.test_reset!
end
end

View File

@@ -4,11 +4,11 @@ shared_examples "map validations" do
describe "validations" do
before(:each) do
before do
Setting["feature.map"] = true
end
after(:each) do
after do
Setting["feature.map"] = nil
end

View File

@@ -38,7 +38,7 @@ RSpec.configure do |config|
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do |example|
config.before do |example|
DatabaseCleaner.strategy = :transaction
I18n.locale = :en
load Rails.root.join('db', 'seeds.rb').to_s
@@ -57,11 +57,11 @@ RSpec.configure do |config|
end
end
config.before(:each) do
config.before do
DatabaseCleaner.start
end
config.append_after(:each) do
config.append_after do
DatabaseCleaner.clean
end