|
61 | 61 | end |
62 | 62 | end |
63 | 63 | end |
| 64 | + |
| 65 | + context 'with --skip-autocorrect' do |
| 66 | + let(:argv) { ['validate', '--skip-autocorrect'] } |
| 67 | + |
| 68 | + it 'passes autocorrect: false' do |
| 69 | + expect(CodeOwnership).to receive(:validate!) do |args| |
| 70 | + expect(args[:autocorrect]).to eq false |
| 71 | + expect(args[:stage_changes]).to eq true |
| 72 | + end |
| 73 | + subject |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + context 'with --skip-stage' do |
| 78 | + let(:argv) { ['validate', '--skip-stage'] } |
| 79 | + |
| 80 | + it 'passes stage_changes: false' do |
| 81 | + expect(CodeOwnership).to receive(:validate!) do |args| |
| 82 | + expect(args[:autocorrect]).to eq true |
| 83 | + expect(args[:stage_changes]).to eq false |
| 84 | + end |
| 85 | + subject |
| 86 | + end |
| 87 | + end |
| 88 | + |
| 89 | + context 'with --help' do |
| 90 | + let(:argv) { ['validate', '--help'] } |
| 91 | + |
| 92 | + it 'shows help and exits' do |
| 93 | + expect(CodeOwnership).not_to receive(:validate!) |
| 94 | + expect(CodeOwnership::Cli).to receive(:puts).at_least(:once) |
| 95 | + expect { subject }.to raise_error(SystemExit) |
| 96 | + end |
| 97 | + end |
64 | 98 | end |
65 | 99 |
|
66 | 100 | context 'for_team' do |
|
82 | 116 | expect(CodeOwnership::Cli).to receive(:puts).with('# Code Ownership Report for `My Team` Team') |
83 | 117 | subject |
84 | 118 | end |
| 119 | + |
| 120 | + context 'with no team provided' do |
| 121 | + let(:argv) { ['for_team'] } |
| 122 | + |
| 123 | + it 'raises argument error' do |
| 124 | + expect { subject }.to raise_error("Please pass in one team. Use `#{described_class::EXECUTABLE} for_team --help` for more info") |
| 125 | + end |
| 126 | + end |
| 127 | + |
| 128 | + context 'with multiple teams provided' do |
| 129 | + let(:argv) { %w[for_team A B] } |
| 130 | + |
| 131 | + it 'raises argument error' do |
| 132 | + expect { subject }.to raise_error("Please pass in one team. Use `#{described_class::EXECUTABLE} for_team --help` for more info") |
| 133 | + end |
| 134 | + end |
| 135 | + |
| 136 | + context 'with --help' do |
| 137 | + let(:argv) { ['for_team', '--help'] } |
| 138 | + |
| 139 | + it 'shows help and exits' do |
| 140 | + expect(CodeOwnership::Cli).to receive(:puts).at_least(:once) |
| 141 | + expect { subject }.to raise_error(SystemExit) |
| 142 | + end |
| 143 | + end |
85 | 144 | end |
86 | 145 |
|
87 | 146 | describe 'for_file' do |
@@ -164,6 +223,28 @@ def initialize |
164 | 223 | end |
165 | 224 | end |
166 | 225 | end |
| 226 | + |
| 227 | + context 'when file is unowned' do |
| 228 | + let(:argv) { ['for_file', 'app/services/unowned.rb'] } |
| 229 | + |
| 230 | + it 'prints Unowned' do |
| 231 | + allow(CodeOwnership).to receive(:for_file).and_return(nil) |
| 232 | + expect(CodeOwnership::Cli).to receive(:puts).with(<<~MSG) |
| 233 | + Team: Unowned |
| 234 | + Team YML: Unowned |
| 235 | + MSG |
| 236 | + subject |
| 237 | + end |
| 238 | + end |
| 239 | + |
| 240 | + context 'with --help' do |
| 241 | + let(:argv) { ['for_file', '--help'] } |
| 242 | + |
| 243 | + it 'shows help and exits' do |
| 244 | + expect(CodeOwnership::Cli).to receive(:puts).at_least(:once) |
| 245 | + expect { subject }.to raise_error(SystemExit) |
| 246 | + end |
| 247 | + end |
167 | 248 | end |
168 | 249 |
|
169 | 250 | describe 'using unknown command' do |
|
0 commit comments