Commit 0adc3cda authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'let-before-examples-cop' into 'master'

Fix RSpec/LetBeforeExamples cop

See merge request gitlab-org/gitlab!41250
parents 1a9d624a 80ab6b61
......@@ -199,21 +199,6 @@ RSpec/ExpectChange:
RSpec/ExpectInHook:
Enabled: false
# Offense count: 68
# Cop supports --auto-correct.
RSpec/LetBeforeExamples:
Exclude:
- 'spec/lib/banzai/filter/issue_reference_filter_spec.rb'
- 'spec/lib/banzai/filter/user_reference_filter_spec.rb'
- 'spec/lib/gitlab/email/handler/create_issue_handler_spec.rb'
- 'spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb'
- 'spec/lib/gitlab/email/handler/create_note_handler_spec.rb'
- 'spec/models/commit_range_spec.rb'
- 'spec/models/milestone_spec.rb'
- 'spec/models/project_services/packagist_service_spec.rb'
- 'spec/rubocop/cop/migration/update_column_in_batches_spec.rb'
- 'spec/serializers/pipeline_details_entity_spec.rb'
# Offense count: 2188
# Cop supports --auto-correct.
# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers.
......
---
title: Fix RSpec/LetBeforeExamples cop
merge_request: 41250
author: Rajendra Kadam
type: fixed
......@@ -40,10 +40,10 @@ RSpec.describe Banzai::Filter::IssueReferenceFilter do
end
context 'internal reference' do
it_behaves_like 'a reference containing an element node'
let(:reference) { "##{issue.iid}" }
it_behaves_like 'a reference containing an element node'
it 'links to a valid reference' do
doc = reference_filter("Fixed #{reference}")
......@@ -134,11 +134,11 @@ RSpec.describe Banzai::Filter::IssueReferenceFilter do
end
context 'cross-project / cross-namespace complete reference' do
it_behaves_like 'a reference containing an element node'
let(:project2) { create(:project, :public) }
let(:issue) { create(:issue, project: project2) }
let(:reference) { "#{project2.full_path}##{issue.iid}" }
let(:issue) { create(:issue, project: project2) }
let(:project2) { create(:project, :public) }
it_behaves_like 'a reference containing an element node'
it 'ignores valid references when cross-reference project uses external tracker' do
expect_any_instance_of(described_class).to receive(:find_object)
......@@ -182,13 +182,13 @@ RSpec.describe Banzai::Filter::IssueReferenceFilter do
end
context 'cross-project / same-namespace complete reference' do
it_behaves_like 'a reference containing an element node'
let(:namespace) { create(:namespace) }
let(:project) { create(:project, :public, namespace: namespace) }
let(:project2) { create(:project, :public, namespace: namespace) }
let(:issue) { create(:issue, project: project2) }
let(:reference) { "#{project2.full_path}##{issue.iid}" }
let(:issue) { create(:issue, project: project2) }
let(:project2) { create(:project, :public, namespace: namespace) }
let(:project) { create(:project, :public, namespace: namespace) }
let(:namespace) { create(:namespace) }
it_behaves_like 'a reference containing an element node'
it 'ignores valid references when cross-reference project uses external tracker' do
expect_any_instance_of(described_class).to receive(:find_object)
......@@ -232,13 +232,13 @@ RSpec.describe Banzai::Filter::IssueReferenceFilter do
end
context 'cross-project shorthand reference' do
it_behaves_like 'a reference containing an element node'
let(:namespace) { create(:namespace) }
let(:project) { create(:project, :public, namespace: namespace) }
let(:project2) { create(:project, :public, namespace: namespace) }
let(:issue) { create(:issue, project: project2) }
let(:reference) { "#{project2.path}##{issue.iid}" }
let(:issue) { create(:issue, project: project2) }
let(:project2) { create(:project, :public, namespace: namespace) }
let(:project) { create(:project, :public, namespace: namespace) }
let(:namespace) { create(:namespace) }
it_behaves_like 'a reference containing an element node'
it 'ignores valid references when cross-reference project uses external tracker' do
expect_any_instance_of(described_class).to receive(:find_object)
......@@ -282,12 +282,12 @@ RSpec.describe Banzai::Filter::IssueReferenceFilter do
end
context 'cross-project URL reference' do
it_behaves_like 'a reference containing an element node'
let(:namespace) { create(:namespace, name: 'cross-reference') }
let(:project2) { create(:project, :public, namespace: namespace) }
let(:issue) { create(:issue, project: project2) }
let(:reference) { issue_url + "#note_123" }
let(:issue) { create(:issue, project: project2) }
let(:project2) { create(:project, :public, namespace: namespace) }
let(:namespace) { create(:namespace, name: 'cross-reference') }
it_behaves_like 'a reference containing an element node'
it 'links to a valid reference' do
doc = reference_filter("See #{reference}")
......@@ -310,13 +310,13 @@ RSpec.describe Banzai::Filter::IssueReferenceFilter do
end
context 'cross-project reference in link href' do
it_behaves_like 'a reference containing an element node'
let(:namespace) { create(:namespace, name: 'cross-reference') }
let(:project2) { create(:project, :public, namespace: namespace) }
let(:issue) { create(:issue, project: project2) }
let(:reference) { issue.to_reference(project) }
let(:reference_link) { %{<a href="#{reference}">Reference</a>} }
let(:reference) { issue.to_reference(project) }
let(:issue) { create(:issue, project: project2) }
let(:project2) { create(:project, :public, namespace: namespace) }
let(:namespace) { create(:namespace, name: 'cross-reference') }
it_behaves_like 'a reference containing an element node'
it 'links to a valid reference' do
doc = reference_filter("See #{reference_link}")
......@@ -339,13 +339,13 @@ RSpec.describe Banzai::Filter::IssueReferenceFilter do
end
context 'cross-project URL in link href' do
it_behaves_like 'a reference containing an element node'
let(:namespace) { create(:namespace, name: 'cross-reference') }
let(:project2) { create(:project, :public, namespace: namespace) }
let(:issue) { create(:issue, project: project2) }
let(:reference) { "#{issue_url + "#note_123"}" }
let(:reference_link) { %{<a href="#{reference}">Reference</a>} }
let(:reference) { "#{issue_url + "#note_123"}" }
let(:issue) { create(:issue, project: project2) }
let(:project2) { create(:project, :public, namespace: namespace) }
let(:namespace) { create(:namespace, name: 'cross-reference') }
it_behaves_like 'a reference containing an element node'
it 'links to a valid reference' do
doc = reference_filter("See #{reference_link}")
......
......@@ -40,10 +40,10 @@ RSpec.describe Banzai::Filter::UserReferenceFilter do
end
context 'mentioning @all' do
it_behaves_like 'a reference containing an element node'
let(:reference) { User.reference_prefix + 'all' }
it_behaves_like 'a reference containing an element node'
before do
project.add_developer(project.creator)
end
......@@ -78,10 +78,10 @@ RSpec.describe Banzai::Filter::UserReferenceFilter do
end
context 'mentioning a group' do
it_behaves_like 'a reference containing an element node'
let(:group) { create(:group) }
let(:reference) { group.to_reference }
let(:group) { create(:group) }
it_behaves_like 'a reference containing an element node'
it 'links to the Group' do
doc = reference_filter("Hey #{reference}")
......@@ -98,10 +98,10 @@ RSpec.describe Banzai::Filter::UserReferenceFilter do
end
context 'mentioning a nested group' do
it_behaves_like 'a reference containing an element node'
let(:group) { create(:group, :nested) }
let(:reference) { group.to_reference }
let(:group) { create(:group, :nested) }
it_behaves_like 'a reference containing an element node'
it 'links to the nested group' do
doc = reference_filter("Hey #{reference}")
......
......@@ -4,17 +4,6 @@ require 'spec_helper'
RSpec.describe Gitlab::Email::Handler::CreateIssueHandler do
include_context :email_shared_context
it_behaves_like :reply_processing_shared_examples
before do
stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.adventuretime.ooo")
stub_config_setting(host: 'localhost')
end
let(:email_raw) { email_fixture('emails/valid_new_issue.eml') }
let(:namespace) { create(:namespace, path: 'gitlabhq') }
let!(:project) { create(:project, :public, namespace: namespace, path: 'gitlabhq') }
let!(:user) do
create(
:user,
......@@ -23,6 +12,17 @@ RSpec.describe Gitlab::Email::Handler::CreateIssueHandler do
)
end
let!(:project) { create(:project, :public, namespace: namespace, path: 'gitlabhq') }
let(:namespace) { create(:namespace, path: 'gitlabhq') }
let(:email_raw) { email_fixture('emails/valid_new_issue.eml') }
it_behaves_like :reply_processing_shared_examples
before do
stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.adventuretime.ooo")
stub_config_setting(host: 'localhost')
end
context "when email key" do
let(:mail) { Mail::Message.new(email_raw) }
......
......@@ -4,6 +4,18 @@ require 'spec_helper'
RSpec.describe Gitlab::Email::Handler::CreateMergeRequestHandler do
include_context :email_shared_context
let!(:user) do
create(
:user,
email: 'jake@adventuretime.ooo',
incoming_email_token: 'auth_token'
)
end
let!(:project) { create(:project, :public, :repository, namespace: namespace, path: 'gitlabhq') }
let(:namespace) { create(:namespace, path: 'gitlabhq') }
let(:email_raw) { email_fixture('emails/valid_new_merge_request.eml') }
it_behaves_like :reply_processing_shared_examples
before do
......@@ -15,18 +27,6 @@ RSpec.describe Gitlab::Email::Handler::CreateMergeRequestHandler do
TestEnv.clean_test_path
end
let(:email_raw) { email_fixture('emails/valid_new_merge_request.eml') }
let(:namespace) { create(:namespace, path: 'gitlabhq') }
let!(:project) { create(:project, :public, :repository, namespace: namespace, path: 'gitlabhq') }
let!(:user) do
create(
:user,
email: 'jake@adventuretime.ooo',
incoming_email_token: 'auth_token'
)
end
context "when email key" do
let(:mail) { Mail::Message.new(email_raw) }
......
......@@ -4,6 +4,16 @@ require 'spec_helper'
RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
include_context :email_shared_context
let!(:sent_notification) do
SentNotification.record_note(note, user.id, mail_key)
end
let(:noteable) { note.noteable }
let(:note) { create(:diff_note_on_merge_request, project: project) }
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:email_raw) { fixture_file('emails/valid_reply.eml') }
it_behaves_like :reply_processing_shared_examples
before do
......@@ -11,16 +21,6 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
stub_config_setting(host: 'localhost')
end
let(:email_raw) { fixture_file('emails/valid_reply.eml') }
let(:project) { create(:project, :public, :repository) }
let(:user) { create(:user) }
let(:note) { create(:diff_note_on_merge_request, project: project) }
let(:noteable) { note.noteable }
let!(:sent_notification) do
SentNotification.record_note(note, user.id, mail_key)
end
context "when the recipient address doesn't include a mail key" do
let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "") }
......
......@@ -3,25 +3,22 @@
require 'spec_helper'
RSpec.describe CommitRange do
let(:range2) { described_class.new("#{sha_from}..#{sha_to}", project) }
let(:range) { described_class.new("#{sha_from}...#{sha_to}", project) }
let(:full_sha_to) { commit2.id }
let(:full_sha_from) { commit1.id }
let(:sha_to) { commit2.short_id }
let(:sha_from) { commit1.short_id }
let!(:commit2) { project.commit }
let!(:commit1) { project.commit("HEAD~2") }
let!(:project) { create(:project, :public, :repository) }
describe 'modules' do
subject { described_class }
it { is_expected.to include_module(Referable) }
end
let!(:project) { create(:project, :public, :repository) }
let!(:commit1) { project.commit("HEAD~2") }
let!(:commit2) { project.commit }
let(:sha_from) { commit1.short_id }
let(:sha_to) { commit2.short_id }
let(:full_sha_from) { commit1.id }
let(:full_sha_to) { commit2.id }
let(:range) { described_class.new("#{sha_from}...#{sha_to}", project) }
let(:range2) { described_class.new("#{sha_from}..#{sha_to}", project) }
it 'raises ArgumentError when given an invalid range string' do
expect { described_class.new("Foo", project) }.to raise_error(ArgumentError)
end
......
......@@ -3,6 +3,11 @@
require 'spec_helper'
RSpec.describe Milestone do
let(:user) { create(:user) }
let(:issue) { create(:issue, project: project) }
let(:milestone) { create(:milestone, project: project) }
let(:project) { create(:project, :public) }
it_behaves_like 'a timebox', :milestone
describe 'MilestoneStruct#serializable_hash' do
......@@ -47,11 +52,6 @@ RSpec.describe Milestone do
it { is_expected.to have_many(:milestone_releases) }
end
let(:project) { create(:project, :public) }
let(:milestone) { create(:milestone, project: project) }
let(:issue) { create(:issue, project: project) }
let(:user) { create(:user) }
describe '.predefined_id?' do
it 'returns true for a predefined Milestone ID' do
expect(Milestone.predefined_id?(described_class::Upcoming.id)).to be true
......
......@@ -3,20 +3,6 @@
require 'spec_helper'
RSpec.describe PackagistService do
describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
let(:project) { create(:project) }
let(:packagist_server) { 'https://packagist.example.com' }
let(:packagist_username) { 'theUser' }
let(:packagist_token) { 'verySecret' }
let(:packagist_hook_url) do
"#{packagist_server}/api/update-package?username=#{packagist_username}&apiToken=#{packagist_token}"
end
let(:packagist_params) do
{
active: true,
......@@ -29,6 +15,20 @@ RSpec.describe PackagistService do
}
end
let(:packagist_hook_url) do
"#{packagist_server}/api/update-package?username=#{packagist_username}&apiToken=#{packagist_token}"
end
let(:packagist_token) { 'verySecret' }
let(:packagist_username) { 'theUser' }
let(:packagist_server) { 'https://packagist.example.com' }
let(:project) { create(:project) }
describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
describe '#execute' do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
......
......@@ -27,6 +27,8 @@ RSpec.describe RuboCop::Cop::Migration::UpdateColumnInBatches do
FileUtils.rm_rf(tmp_rails_root)
end
let(:spec_filepath) { tmp_rails_root.join('spec', 'migrations', 'my_super_migration_spec.rb') }
context 'outside of a migration' do
it 'does not register any offenses' do
inspect_source(migration_code)
......@@ -35,8 +37,6 @@ RSpec.describe RuboCop::Cop::Migration::UpdateColumnInBatches do
end
end
let(:spec_filepath) { tmp_rails_root.join('spec', 'migrations', 'my_super_migration_spec.rb') }
shared_context 'with a migration file' do
before do
FileUtils.mkdir_p(File.dirname(migration_filepath))
......
......@@ -6,6 +6,10 @@ RSpec.describe PipelineDetailsEntity do
let_it_be(:user) { create(:user) }
let(:request) { double('request') }
let(:entity) do
described_class.represent(pipeline, request: request)
end
it 'inherrits from PipelineEntity' do
expect(described_class).to be < PipelineEntity
end
......@@ -16,10 +20,6 @@ RSpec.describe PipelineDetailsEntity do
allow(request).to receive(:current_user).and_return(user)
end
let(:entity) do
described_class.represent(pipeline, request: request)
end
describe '#as_json' do
subject { entity.as_json }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment