Skip to content

Commit 9ed0af2

Browse files
committed
add installer specs
1 parent b1341fa commit 9ed0af2

19 files changed

+205
-119
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
/completely.bash
44
/completely.yaml
55
/coverage
6+
/debug.runfile
67
/dev
78
/doc
89
/Gemfile.lock
910
/gems
11+
/out.sh
12+
/spec/status.txt
1013
/spec/tmp
11-
/debug.runfile
1214
/tmp
13-
out.sh

lib/completely/installer.rb

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@ def target_directories
1515
]
1616
end
1717

18+
def command
19+
result = root_user? ? [] : %w[sudo]
20+
result + %W[cp #{script_path} #{target_path}]
21+
end
22+
23+
def command_string
24+
command.join ' '
25+
end
26+
27+
def target_path
28+
"#{completions_path}/#{program}"
29+
end
30+
1831
def install(force: false)
1932
unless completions_path
2033
raise 'Cannot determine system completions directory'
2134
end
2235

23-
unless File.exist? script_path
36+
unless script_exist?
2437
raise "Cannot find script: m`#{script_path}`"
2538
end
2639

@@ -31,26 +44,17 @@ def install(force: false)
3144
system(*command)
3245
end
3346

34-
def command
35-
result = root? ? [] : %w[sudo]
36-
result + %W[cp #{script_path} #{target_path}]
37-
end
38-
39-
def command_string
40-
command.join ' '
41-
end
42-
43-
def target_path
44-
"#{completions_path}/#{program}"
45-
end
46-
4747
private
4848

4949
def target_exist?
5050
File.exist? target_path
5151
end
5252

53-
def root?
53+
def script_exist?
54+
File.exist? script_path
55+
end
56+
57+
def root_user?
5458
Process.uid.zero?
5559
end
5660

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<RuntimeError: Cannot determine system completions directory>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<RuntimeError: Cannot find script: m`tmp/missing-file`>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<RuntimeError: File exists: m`spec/fixtures/existing-file.txt`>

spec/completely/bin_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'spec_helper'
2-
31
describe 'bin/completely' do
42
subject { CLI.runner }
53

spec/completely/commands/generate_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'spec_helper'
2-
31
describe Commands::Generate do
42
subject { described_class.new }
53

spec/completely/commands/init_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'spec_helper'
2-
31
describe Commands::Init do
42
subject { described_class.new }
53

Lines changed: 80 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,91 @@
1-
require 'spec_helper'
1+
# describe Commands::Install do
2+
# subject { described_class.new }
23

3-
describe Commands::Install do
4-
subject { described_class.new }
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
510

6-
context 'with --help' do
7-
it 'shows long usage' do
8-
expect { subject.execute %w[install --help] }
9-
.to output_approval('cli/install/help').diff(10)
10-
end
11-
end
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
1217

13-
context 'without arguments' do
14-
it 'shows short usage' do
15-
expect { subject.execute %w[install] }
16-
.to output_approval('cli/install/no-args')
17-
end
18-
end
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
1925

20-
context 'with only the program name argument' do
21-
context 'when the default script is not found' do
22-
it 'raises an error' do
23-
expect { subject.execute %w[install completely-test] }
24-
.to raise_approval('cli/install/missing-script').diff(8)
25-
end
26-
end
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
2735

28-
context 'when the default script is found' do
29-
let(:expected_args) do
30-
%w[
31-
sudo
32-
cp
33-
completely.bash
34-
/usr/share/bash-completion/completions/completely-test
35-
]
36-
end
36+
# before do
37+
# reset_tmp_dir
38+
# File.write 'spec/tmp/completely.bash', 'not-important'
39+
# end
3740

38-
before do
39-
reset_tmp_dir
40-
File.write 'spec/tmp/completely.bash', 'not-important'
41-
end
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
4251

43-
it 'copies the script', :focus do
44-
Dir.chdir 'spec/tmp' do
45-
allow(subject).to receive(:system).with(*expected_args).and_return true
46-
subject.execute %w[install completely-test]
47-
expect { subject.execute %w[install completely-test] }
48-
.to output_approval('cli/install/install-default')
49-
end
50-
end
51-
end
52-
end
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
5361

54-
context 'with the program name argument and a script argument' do
55-
let(:expected_args) do
56-
%w[
57-
sudo
58-
cp
59-
README.md
60-
/usr/share/bash-completion/completions/completely-test
61-
]
62-
end
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
6368

64-
it 'copies the script' do
65-
allow(subject).to receive(:system).with(*expected_args).and_return true
66-
expect { subject.execute %w[install completely-test README.md] }
67-
.to output_approval('cli/install/install-specified')
68-
end
69-
end
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
7075

71-
context 'with --dry' do
72-
it 'shows the command' do
73-
expect { subject.execute %w[install completely-test README.md --dry] }
74-
.to output_approval('cli/install/dry')
75-
end
76-
end
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
7783

78-
context 'when none of the target directories is found' do
79-
it 'raises an error' do
80-
allow(subject).to receive(:completions_path).and_return nil
81-
expect { subject.execute %w[install completely-test README.md] }
82-
.to raise_approval('cli/install/no-completion-targets').diff(8)
83-
end
84-
end
85-
86-
context 'when the target file exists' do
87-
it 'raises an error' do
88-
allow(subject).to receive(:target_exist?).and_return true
89-
expect { subject.execute %w[install completely-test README.md] }
90-
.to raise_approval('cli/install/target-exists').diff(8)
91-
end
92-
end
93-
end
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

spec/completely/commands/preview_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'spec_helper'
2-
31
describe Commands::Preview do
42
subject { described_class.new }
53

0 commit comments

Comments
 (0)