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