|
1 | 1 | RSpec.describe CodeOwnership::Cli do |
2 | 2 | subject { CodeOwnership::Cli.run!(argv) } |
3 | 3 |
|
4 | | - let(:argv) { ['validate'] } |
| 4 | + describe 'validate' do |
| 5 | + let(:argv) { ['validate'] } |
5 | 6 |
|
6 | | - before do |
7 | | - write_file('config/code_ownership.yml', <<~YML) |
8 | | - owned_globs: |
9 | | - - 'app/**/*.rb' |
10 | | - YML |
| 7 | + before do |
| 8 | + write_file('config/code_ownership.yml', <<~YML) |
| 9 | + owned_globs: |
| 10 | + - 'app/**/*.rb' |
| 11 | + YML |
| 12 | + |
| 13 | + write_file('app/services/my_file.rb') |
| 14 | + write_file('frontend/javascripts/my_file.jsx') |
| 15 | + end |
| 16 | + |
| 17 | + context 'when run without arguments' do |
| 18 | + it 'runs validations with the right defaults' do |
| 19 | + expect(CodeOwnership).to receive(:validate!) do |args| # rubocop:disable RSpec/MessageSpies |
| 20 | + expect(args[:autocorrect]).to eq true |
| 21 | + expect(args[:stage_changes]).to eq true |
| 22 | + expect(args[:files]).to match_array(['app/services/my_file.rb']) |
| 23 | + end |
| 24 | + subject |
| 25 | + end |
| 26 | + end |
11 | 27 |
|
12 | | - write_file('app/services/my_file.rb') |
13 | | - write_file('frontend/javascripts/my_file.jsx') |
14 | 28 | end |
15 | 29 |
|
16 | | - context 'when run without arguments' do |
17 | | - it 'runs validations with the right defaults' do |
18 | | - expect(CodeOwnership).to receive(:validate!) do |args| # rubocop:disable RSpec/MessageSpies |
19 | | - expect(args[:autocorrect]).to eq true |
20 | | - expect(args[:stage_changes]).to eq true |
21 | | - expect(args[:files]).to match_array(['app/services/my_file.rb']) |
| 30 | + describe 'for_file' do |
| 31 | + before do |
| 32 | + write_file('config/code_ownership.yml', <<~YML) |
| 33 | + owned_globs: |
| 34 | + - 'app/**/*.rb' |
| 35 | + YML |
| 36 | + |
| 37 | + write_file('app/services/my_file.rb') |
| 38 | + write_file('config/teams/my_team.yml', <<~YML) |
| 39 | + name: My Team |
| 40 | + owned_globs: |
| 41 | + - 'app/**/*.rb' |
| 42 | + YML |
| 43 | + end |
| 44 | + |
| 45 | + context 'when run with no flags' do |
| 46 | + context 'when run with one file' do |
| 47 | + let(:argv) { ['for_file', 'app/services/my_file.rb'] } |
| 48 | + |
| 49 | + it 'outputs the team info in human readable format' do |
| 50 | + expect(CodeOwnership::Cli).to receive(:puts).with(<<~MSG) |
| 51 | + Team: My Team |
| 52 | + Team YML: config/teams/my_team.yml |
| 53 | + MSG |
| 54 | + subject |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + context 'when run with no files' do |
| 59 | + let(:argv) { ['for_file'] } |
| 60 | + |
| 61 | + it 'outputs the team info in human readable format' do |
| 62 | + expect { subject }.to raise_error "Please pass in one file. Use `bin/codeownership for_file --help` for more info" |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + context 'when run with multiple files' do |
| 67 | + let(:argv) { ['for_file', 'app/services/my_file.rb', 'app/services/my_file2.rb'] } |
| 68 | + |
| 69 | + it 'outputs the team info in human readable format' do |
| 70 | + expect { subject }.to raise_error "Please pass in one file. Use `bin/codeownership for_file --help` for more info" |
| 71 | + end |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + context 'when run with --json' do |
| 76 | + let(:argv) { ['for_file', '--json', 'app/services/my_file.rb'] } |
| 77 | + |
| 78 | + context 'when run with one file' do |
| 79 | + it 'outputs JSONified information to the console' do |
| 80 | + json = { |
| 81 | + team_name: 'My Team', |
| 82 | + team_yml: 'config/teams/my_team.yml' |
| 83 | + } |
| 84 | + expect(CodeOwnership::Cli).to receive(:puts).with(json.to_json) |
| 85 | + subject |
| 86 | + end |
| 87 | + end |
| 88 | + |
| 89 | + context 'when run with no files' do |
| 90 | + let(:argv) { ['for_file', '--json'] } |
| 91 | + |
| 92 | + it 'outputs the team info in human readable format' do |
| 93 | + expect { subject }.to raise_error "Please pass in one file. Use `bin/codeownership for_file --help` for more info" |
| 94 | + end |
| 95 | + end |
| 96 | + |
| 97 | + context 'when run with multiple files' do |
| 98 | + let(:argv) { ['for_file', 'app/services/my_file.rb', 'app/services/my_file2.rb'] } |
| 99 | + |
| 100 | + it 'outputs the team info in human readable format' do |
| 101 | + expect { subject }.to raise_error "Please pass in one file. Use `bin/codeownership for_file --help` for more info" |
| 102 | + end |
22 | 103 | end |
23 | | - subject |
24 | 104 | end |
25 | 105 | end |
26 | 106 | end |
0 commit comments