|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Commands::Install do |
| 4 | + subject { described_class.new } |
| 5 | + |
| 6 | + context 'with --help' do |
| 7 | + it 'shows long usage' do |
| 8 | + expect { subject.execute %w[install --help] }.to output_approval('cli/install/help') |
| 9 | + end |
| 10 | + end |
| 11 | + |
| 12 | + context 'without arguments' do |
| 13 | + it 'shows short usage' do |
| 14 | + expect { subject.execute %w[install] }.to output_approval('cli/install/no-args') |
| 15 | + end |
| 16 | + end |
| 17 | + |
| 18 | + context 'with only the program name argument' do |
| 19 | + context 'when the default script is not found' do |
| 20 | + it 'raises an error' do |
| 21 | + expect { subject.execute %w[install completely-test] }.to raise_approval('cli/install/missing-script') |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + context 'when the default script is found' do |
| 26 | + let(:expected_args) { |
| 27 | + %w[ |
| 28 | + sudo |
| 29 | + cp |
| 30 | + completely.bash |
| 31 | + /usr/share/bash-completion/completions/completely-test |
| 32 | + ] |
| 33 | + } |
| 34 | + |
| 35 | + before do |
| 36 | + reset_tmp_dir |
| 37 | + File.write 'spec/tmp/completely.bash', 'not-important' |
| 38 | + end |
| 39 | + |
| 40 | + it 'copies the script' do |
| 41 | + Dir.chdir 'spec/tmp' do |
| 42 | + expect(subject).to receive(:system).with(*expected_args).and_return true |
| 43 | + expect { subject.execute %W[install completely-test] }.to output_approval('cli/install/install-default') |
| 44 | + end |
| 45 | + end |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + context 'with the program name argument and a script argument' do |
| 50 | + let(:expected_args) { |
| 51 | + %w[ |
| 52 | + sudo |
| 53 | + cp |
| 54 | + README.md |
| 55 | + /usr/share/bash-completion/completions/completely-test |
| 56 | + ] |
| 57 | + } |
| 58 | + |
| 59 | + it 'copies the script' do |
| 60 | + expect(subject).to receive(:system).with(*expected_args).and_return true |
| 61 | + expect { subject.execute %W[install completely-test README.md] }.to output_approval('cli/install/install-specified') |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + context 'when none of the target directories is found' do |
| 66 | + it 'raises an error' do |
| 67 | + expect(subject).to receive(:completions_path).and_return nil |
| 68 | + expect { subject.execute %W[install completely-test README.md] }.to raise_approval('cli/install/no-completion-targets') |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context 'when the target file exists' do |
| 73 | + it 'raises an error' do |
| 74 | + expect(subject).to receive(:target_exist?).and_return true |
| 75 | + expect { subject.execute %W[install completely-test README.md] }.to raise_approval('cli/install/target-exists') |
| 76 | + end |
| 77 | + end |
| 78 | +end |
0 commit comments