Commit ec5aad68 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch '48898_update_codestyle_for_tests' into 'master'

Update code style for code_owners_spec.rb

See merge request gitlab-org/gitlab!49109
parents 1ebcca51 c81df605
...@@ -19,6 +19,8 @@ RSpec.describe Gitlab::CodeOwners do ...@@ -19,6 +19,8 @@ RSpec.describe Gitlab::CodeOwners do
end end
describe '.for_blob' do describe '.for_blob' do
subject { described_class.for_blob(project, blob) }
let(:branch) { TestEnv::BRANCH_SHA['with-codeowners'] } let(:branch) { TestEnv::BRANCH_SHA['with-codeowners'] }
let(:blob) { project.repository.blob_at(branch, 'docs/CODEOWNERS') } let(:blob) { project.repository.blob_at(branch, 'docs/CODEOWNERS') }
let(:codeowner_lookup_ref) { branch } let(:codeowner_lookup_ref) { branch }
...@@ -29,7 +31,7 @@ RSpec.describe Gitlab::CodeOwners do ...@@ -29,7 +31,7 @@ RSpec.describe Gitlab::CodeOwners do
end end
it 'returns users for a blob' do it 'returns users for a blob' do
expect(described_class.for_blob(project, blob)).to include(code_owner) is_expected.to include(code_owner)
end end
end end
...@@ -39,7 +41,7 @@ RSpec.describe Gitlab::CodeOwners do ...@@ -39,7 +41,7 @@ RSpec.describe Gitlab::CodeOwners do
end end
it 'returns no users' do it 'returns no users' do
expect(described_class.for_blob(project, blob)).to be_empty is_expected.to be_empty
end end
end end
end end
...@@ -100,7 +102,7 @@ RSpec.describe Gitlab::CodeOwners do ...@@ -100,7 +102,7 @@ RSpec.describe Gitlab::CodeOwners do
end end
end end
describe ".fast_path_lookup and .slow_path_lookup" do describe '.fast_path_lookup and .slow_path_lookup' do
let(:codeowner_lookup_ref) { merge_request.target_branch } let(:codeowner_lookup_ref) { merge_request.target_branch }
let(:codeowner_content) { 'files/ruby/feature.rb @owner-1' } let(:codeowner_content) { 'files/ruby/feature.rb @owner-1' }
let(:merge_request) do let(:merge_request) do
...@@ -117,7 +119,7 @@ RSpec.describe Gitlab::CodeOwners do ...@@ -117,7 +119,7 @@ RSpec.describe Gitlab::CodeOwners do
stub_licensed_features(code_owners: true) stub_licensed_features(code_owners: true)
end end
it "return equivalent results" do it 'returns equivalent results' do
fast_results = described_class.entries_for_merge_request(merge_request).first fast_results = described_class.entries_for_merge_request(merge_request).first
expect(merge_request.merge_request_diff).to receive(:overflow?).and_return(true) expect(merge_request.merge_request_diff).to receive(:overflow?).and_return(true)
...@@ -131,6 +133,9 @@ RSpec.describe Gitlab::CodeOwners do ...@@ -131,6 +133,9 @@ RSpec.describe Gitlab::CodeOwners do
end end
describe '.entries_for_merge_request' do describe '.entries_for_merge_request' do
subject(:entries) { described_class.entries_for_merge_request(merge_request, merge_request_diff: merge_request_diff) }
let(:merge_request_diff) { nil }
let(:codeowner_lookup_ref) { merge_request.target_branch } let(:codeowner_lookup_ref) { merge_request.target_branch }
let(:merge_request) do let(:merge_request) do
create( create(
...@@ -145,38 +150,34 @@ RSpec.describe Gitlab::CodeOwners do ...@@ -145,38 +150,34 @@ RSpec.describe Gitlab::CodeOwners do
context 'when the feature is available' do context 'when the feature is available' do
before do before do
stub_licensed_features(code_owners: true) stub_licensed_features(code_owners: true)
allow(merge_request).to receive(:modified_paths).with(past_merge_request_diff: merge_request_diff) { ['docs/CODEOWNERS'] }
end end
it 'returns owners for merge request' do it 'returns owners for merge request' do
expect(merge_request).to receive(:modified_paths).with(past_merge_request_diff: nil).and_return(['docs/CODEOWNERS']) expect(entries.first).to have_attributes(pattern: 'docs/CODEOWNERS', users: [code_owner])
entry = described_class.entries_for_merge_request(merge_request).first
expect(entry.pattern).to eq('docs/CODEOWNERS')
expect(entry.users).to eq([code_owner])
end end
context 'when merge_request_diff is specified' do context 'when merge_request_diff is specified' do
let(:merge_request_diff) { merge_request.merge_request_diff }
it 'returns owners at the specified ref' do it 'returns owners at the specified ref' do
expect(described_class).to receive(:fast_path_lookup).and_call_original expect(described_class).to receive(:fast_path_lookup).and_call_original
expect(merge_request).to receive(:modified_paths).with(past_merge_request_diff: merge_request.merge_request_diff).and_return(['docs/CODEOWNERS'])
entry = described_class.entries_for_merge_request(merge_request, merge_request_diff: merge_request.merge_request_diff).first expect(entries.first).to have_attributes(pattern: 'docs/CODEOWNERS', users: [code_owner])
expect(entry.users).to eq([code_owner])
end end
end end
context 'when the merge request is large (>1_000 files)' do context 'when the merge request is large (>1_000 files)' do
before do before do
expect(merge_request.merge_request_diff).to receive(:overflow?).and_return(true) expect(merge_request.merge_request_diff).to receive(:overflow?) { true }
end end
it 'generates paths via .slow_path_lookup' do it 'generates paths via .slow_path_lookup' do
expect(described_class).not_to receive(:fast_path_lookup) expect(described_class).not_to receive(:fast_path_lookup)
expect(described_class).to receive(:slow_path_lookup).and_call_original expect(described_class).to receive(:slow_path_lookup).and_call_original
described_class.entries_for_merge_request(merge_request) entries
end end
end end
end end
...@@ -189,7 +190,7 @@ RSpec.describe Gitlab::CodeOwners do ...@@ -189,7 +190,7 @@ RSpec.describe Gitlab::CodeOwners do
it 'skips reading codeowners and returns an empty array' do it 'skips reading codeowners and returns an empty array' do
expect(described_class).not_to receive(:loader_for_merge_request) expect(described_class).not_to receive(:loader_for_merge_request)
expect(described_class.entries_for_merge_request(merge_request)).to eq([]) is_expected.to be_empty
end end
end end
end end
......
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