|
5 | 5 | expect(CodeOwnership::VERSION).not_to be nil
|
6 | 6 | end
|
7 | 7 |
|
8 |
| - describe '.for_file' do |
9 |
| - subject { CodeOwnership.for_file(file_path) } |
10 |
| - context 'rust codeowners' do |
11 |
| - context 'when config is not found' do |
12 |
| - let(:file_path) { 'app/javascript/[test]/test.js' } |
13 |
| - it 'raises an error' do |
14 |
| - expect { subject }.to raise_error(RuntimeError, /Can't open config file:/) |
| 8 | + describe '.team_names_for_files' do |
| 9 | + subject { CodeOwnership.team_names_for_files(files) } |
| 10 | + let(:files) { ['app/services/my_file.rb'] } |
| 11 | + |
| 12 | + context 'when config is not found' do |
| 13 | + let(:files) { ['app/javascript/[test]/test.js'] } |
| 14 | + it 'raises an error' do |
| 15 | + expect { subject }.to raise_error(RuntimeError, /Can't open config file:/) |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + context 'with non-empty application' do |
| 20 | + before do |
| 21 | + create_non_empty_application |
| 22 | + # codeowners-rs is matching files against the codeowners file |
| 23 | + ::RustCodeOwners.generate_and_validate(false) |
| 24 | + end |
| 25 | + |
| 26 | + context 'when no ownership is found' do |
| 27 | + let(:files) { ['app/madeup/file.rb'] } |
| 28 | + it 'properly assigns ownership' do |
| 29 | + expect(subject).to eq({ 'app/madeup/file.rb' => nil }) |
15 | 30 | end
|
16 | 31 | end
|
17 | 32 |
|
18 |
| - context 'with non-empty application' do |
| 33 | + context 'when file path starts with ./' do |
| 34 | + let(:files) { ['./app/javascript/[test]/test.js'] } |
| 35 | + it 'properly assigns ownership' do |
| 36 | + expect(subject).to eq({ './app/javascript/[test]/test.js' => nil }) |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + context 'when ownership is found' do |
| 41 | + let(:files) { ['packs/my_pack/owned_file.rb'] } |
| 42 | + it 'returns the correct team' do |
| 43 | + expect(subject).to eq({ 'packs/my_pack/owned_file.rb' => CodeTeams.find('Bar') }) |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + context 'when ownership is found but team is not found' do |
| 48 | + let(:file_path) { ['packs/my_pack/owned_file.rb'] } |
19 | 49 | before do
|
20 |
| - create_non_empty_application |
| 50 | + allow(RustCodeOwners).to receive(:team_names_for_files).and_return({ file_path.first => {team_name: 'Made Up Team'} }) |
| 51 | + end |
| 52 | + |
| 53 | + it 'returns nil' do |
| 54 | + expect(subject).to eq({ 'packs/my_pack/owned_file.rb' => nil }) |
21 | 55 | end
|
| 56 | + end |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + describe '.for_file' do |
| 61 | + subject { CodeOwnership.for_file(file_path) } |
| 62 | + context 'when config is not found' do |
| 63 | + let(:file_path) { 'app/javascript/[test]/test.js' } |
| 64 | + it 'raises an error' do |
| 65 | + expect { subject }.to raise_error(RuntimeError, /Can't open config file:/) |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + context 'with non-empty application' do |
| 70 | + before do |
| 71 | + create_non_empty_application |
| 72 | + end |
22 | 73 |
|
23 |
| - context 'when no ownership is found' do |
24 |
| - let(:file_path) { 'app/madeup/file.rb' } |
25 |
| - it 'properly assigns ownership' do |
26 |
| - expect(subject).to be_nil |
27 |
| - end |
| 74 | + context 'when no ownership is found' do |
| 75 | + let(:file_path) { 'app/madeup/file.rb' } |
| 76 | + it 'properly assigns ownership' do |
| 77 | + expect(subject).to be_nil |
28 | 78 | end
|
| 79 | + end |
29 | 80 |
|
30 |
| - context 'when file path starts with ./' do |
31 |
| - let(:file_path) { './app/javascript/[test]/test.js' } |
32 |
| - it 'properly assigns ownership' do |
33 |
| - expect(subject).to be_nil |
34 |
| - end |
| 81 | + context 'when file path starts with ./' do |
| 82 | + let(:file_path) { './app/javascript/[test]/test.js' } |
| 83 | + it 'properly assigns ownership' do |
| 84 | + expect(subject).to be_nil |
35 | 85 | end
|
| 86 | + end |
36 | 87 |
|
37 |
| - context 'when ownership is found' do |
38 |
| - let(:file_path) { 'packs/my_pack/owned_file.rb' } |
39 |
| - it 'returns the correct team' do |
40 |
| - expect(subject).to eq CodeTeams.find('Bar') |
41 |
| - end |
| 88 | + context 'when ownership is found' do |
| 89 | + let(:file_path) { 'packs/my_pack/owned_file.rb' } |
| 90 | + it 'returns the correct team' do |
| 91 | + expect(subject).to eq CodeTeams.find('Bar') |
42 | 92 | end
|
| 93 | + end |
43 | 94 |
|
44 |
| - context 'when ownership is found but team is not found' do |
45 |
| - let(:file_path) { 'packs/my_pack/owned_file.rb' } |
46 |
| - before do |
47 |
| - allow(RustCodeOwners).to receive(:for_file).and_return({ team_name: 'Made Up Team' }) |
48 |
| - end |
| 95 | + context 'when ownership is found but team is not found' do |
| 96 | + let(:file_path) { 'packs/my_pack/owned_file.rb' } |
| 97 | + before do |
| 98 | + allow(RustCodeOwners).to receive(:for_file).and_return({ team_name: 'Made Up Team' }) |
| 99 | + end |
49 | 100 |
|
50 |
| - it 'raises an error' do |
51 |
| - expect { subject }.to raise_error(StandardError, /Could not find team with name: `Made Up Team`. Make sure the team is one of/) |
52 |
| - end |
| 101 | + it 'raises an error' do |
| 102 | + expect { subject }.to raise_error(StandardError, /Could not find team with name: `Made Up Team`. Make sure the team is one of/) |
53 | 103 | end
|
54 | 104 | end
|
55 | 105 | end
|
|
215 | 265 |
|
216 | 266 | describe '.version' do
|
217 | 267 | it 'returns the version' do
|
218 |
| - expect(described_class.version).to eq ["code_ownership version: #{CodeOwnership::VERSION}", "codeowners-rs version: #{::RustCodeOwners.version}"] |
| 268 | + expect(described_class.version).to eq ["code_ownership version: #{CodeOwnership::VERSION}", "codeowners-rs version: #{RustCodeOwners.version}"] |
219 | 269 | end
|
220 | 270 | end
|
221 | 271 | end
|
0 commit comments