Skip to content

Commit 02d3ab5

Browse files
committed
complete test coverage
1 parent 9ed0af2 commit 02d3ab5

File tree

9 files changed

+48
-100
lines changed

9 files changed

+48
-100
lines changed

lib/completely/commands/install.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Install < Base
2121

2222
def run
2323
if args['--dry']
24-
installer.command_string
24+
puts installer.command_string
2525
return
2626
end
2727

spec/approvals/cli/install/dry

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sudo cp README.md /usr/share/bash-completion/completions/completely-test
1+
sudo cp completely.bash /usr/share/bash-completion/completions/completely-test

spec/approvals/cli/install/install

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Saved some-target-path
2+
You may need to restart your session to test it

spec/approvals/cli/install/install-default

Lines changed: 0 additions & 2 deletions
This file was deleted.

spec/approvals/cli/install/install-specified

Lines changed: 0 additions & 2 deletions
This file was deleted.

spec/approvals/cli/install/missing-script

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/approvals/cli/install/no-completion-targets

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/approvals/cli/install/target-exists

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 44 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,45 @@
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
345

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

Comments
 (0)