Skip to content

Commit fcf0172

Browse files
committed
add specs
1 parent 764fb36 commit fcf0172

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

lib/completely/commands/generate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Completely
44
module Commands
55
class Generate < Base
6-
help 'Generate the bash completion script'
6+
help 'Generate the bash completion script to file or stdout'
77

88
usage 'completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]'
99
usage 'completely generate (-h|--help)'

lib/completely/commands/preview.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Completely
44
module Commands
55
class Preview < Base
6-
help 'Generate the bash completion script to STDOUT'
6+
help 'Generate the bash completion script to stdout'
77

88
usage 'completely preview [CONFIG_PATH --function NAME]'
99
usage 'completely preview (-h|--help)'

spec/approvals/cli/commands

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Completely - Bash Completions Generator
22

33
Commands:
44
init Create a new sample YAML configuration file
5-
preview Generate the bash completion script to STDOUT
6-
generate Generate the bash completion script
5+
preview Generate the bash completion script to stdout
6+
generate Generate the bash completion script to file or stdout
77
test Test completions
88
install Install a bash completion script
99
uninstall Uninstall a bash completion script
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Saved spec/tmp/stdin-to-file.bash

spec/approvals/cli/generate/help

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Generate the bash completion script
1+
Generate the bash completion script to file or stdout
22

33
Usage:
44
completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]

spec/approvals/cli/preview/help

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Generate the bash completion script to STDOUT
1+
Generate the bash completion script to stdout
22

33
Usage:
44
completely preview [CONFIG_PATH --function NAME]

spec/completely/commands/generate_spec.rb

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
describe Commands::Generate do
22
subject { described_class.new }
33

4-
before { system 'cp lib/completely/templates/sample.yaml completely.yaml' }
5-
after { system 'rm -f completely.yaml' }
4+
before do
5+
reset_tmp_dir
6+
system 'cp lib/completely/templates/sample.yaml completely.yaml'
7+
end
8+
9+
after do
10+
system 'rm -f completely.yaml'
11+
end
612

713
context 'with --help' do
814
it 'shows long usage' do
@@ -81,6 +87,28 @@
8187
end
8288
end
8389

90+
context 'with stdin and stdout' do
91+
it 'reads config from stdin and writes to stdout' do
92+
allow($stdin).to receive(:tty?).and_return false
93+
allow($stdin).to receive(:read).and_return File.read('completely.yaml')
94+
95+
expect { subject.execute %w[generate -] }
96+
.to output_approval('cli/generated-script')
97+
end
98+
end
99+
100+
context 'with stdin and output path' do
101+
let(:outfile) { 'spec/tmp/stdin-to-file.bash' }
102+
103+
it 'reads config from stdin and writes to file' do
104+
allow($stdin).to receive(:tty?).and_return false
105+
allow($stdin).to receive(:read).and_return File.read('completely.yaml')
106+
107+
expect { subject.execute %W[generate - #{outfile}] }.to output_approval('cli/generate/custom-path-stdin')
108+
expect(File.read outfile).to match_approval('cli/generated-script')
109+
end
110+
end
111+
84112
context 'with --function NAME' do
85113
after { system 'rm -f completely.bash' }
86114

0 commit comments

Comments
 (0)