Skip to content

Commit 1d8715c

Browse files
committed
update library specs
1 parent 7dccdac commit 1d8715c

File tree

12 files changed

+252
-0
lines changed

12 files changed

+252
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- :path: spec/tmp/src/lib/send_completions.sh
3+
:content: |-
4+
# [@bashly-upgrade completions send_completions]
5+
send_completions() {
6+
echo $'#!/usr/bin/env bash'
7+
echo $''
8+
echo $'# This bash completions script was generated by'
9+
echo $'# completely (https://github.com/dannyben/completely)'
10+
echo $'# Modifying it manually is not recommended'
11+
echo $'_download_completions() {'
12+
echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
13+
echo $' local comp_line="${COMP_WORDS[*]:1}"'
14+
echo $''
15+
echo $' case "$comp_line" in'
16+
echo $' \'\'*) COMPREPLY=($(compgen -W "--force --help --version -f -h -v" -- "$cur")) ;;'
17+
echo $' esac'
18+
echo $'}'
19+
echo $''
20+
echo $'complete -F _download_completions download'
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
In order to enable completions in your script, create a command or a flag (for example: !txtgrn!download completions!txtrst! or !txtgrn!download --completions!txtrst!) that calls the !txtgrn!send_completions!txtrst! function.
2+
3+
Your users can then run something like this to enable completions:
4+
5+
!txtpur!$ eval "$(download completions)"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- :path: spec/tmp/completions.bash
3+
:content: |
4+
#!/usr/bin/env bash
5+
6+
# This bash completions script was generated by
7+
# completely (https://github.com/dannyben/completely)
8+
# Modifying it manually is not recommended
9+
_download_completions() {
10+
local cur=${COMP_WORDS[COMP_CWORD]}
11+
local comp_line="${COMP_WORDS[*]:1}"
12+
13+
case "$comp_line" in
14+
''*) COMPREPLY=($(compgen -W "--force --help --version -f -h -v" -- "$cur")) ;;
15+
esac
16+
}
17+
18+
complete -F _download_completions download
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
In order to enable completions, run:
2+
3+
!txtpur!$ source spec/tmp/completions.bash
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- :path: spec/tmp/completions.yml
3+
:content: |
4+
---
5+
download:
6+
- "--force"
7+
- "--help"
8+
- "--version"
9+
- "-f"
10+
- "-h"
11+
- "-v"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file can be converted to a completions script using the !txtgrn!completely!txtrst! gem.

spec/approvals/library/config-keys

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- colors
3+
- config
4+
- yaml
5+
- lib
6+
- strings
7+
- validations
8+
- completions
9+
- completions_script
10+
- completions_yaml

spec/bashly/libraries/base_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'spec_helper'
2+
3+
describe Libraries::Base do
4+
describe '#files' do
5+
it "raises a NotImplementedError" do
6+
expect { subject.files }.to raise_error(NotImplementedError)
7+
end
8+
end
9+
10+
describe '#post_install_message' do
11+
it "returns nil" do
12+
expect(subject.post_install_message).to be_nil
13+
end
14+
end
15+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'spec_helper'
2+
3+
describe Libraries::CompletionsFunction do
4+
subject { described_class.new *args }
5+
let(:args) { nil }
6+
before { reset_tmp_dir copy_from: 'examples/minimal'}
7+
8+
describe '#files' do
9+
it "returns an array with a single hash" do
10+
expect(subject.files.to_yaml).to match_approval('libraries/completions_function/files')
11+
end
12+
13+
context "with an argument" do
14+
let(:args) { ["my_function"] }
15+
16+
it "uses the first argument in the filename of [:path]" do
17+
expect(subject.files.first[:path]).to eq "#{Settings.source_dir}/lib/#{args.first}.sh"
18+
end
19+
20+
it "uses the first argument as the function of [:content]" do
21+
expect(subject.files.first[:content]).to include "my_function()"
22+
expect(subject.files.first[:content]).to include "[@bashly-upgrade completions my_function]"
23+
end
24+
end
25+
end
26+
27+
describe '#post_install_message' do
28+
it "returns a message" do
29+
expect(subject.post_install_message).to match_approval('libraries/completions_function/message')
30+
end
31+
end
32+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'spec_helper'
2+
3+
describe Libraries::CompletionsScript do
4+
subject { described_class.new *args }
5+
let(:args) { nil }
6+
before { reset_tmp_dir copy_from: 'examples/minimal'}
7+
8+
describe '#files' do
9+
it "returns an array with a single hash" do
10+
expect(subject.files.to_yaml).to match_approval('libraries/completions_script/files')
11+
end
12+
13+
context "with an argument" do
14+
let(:args) { ["filename.bash"] }
15+
16+
it "uses the first argument as a filename" do
17+
expect(subject.files.first[:path]).to eq args.first
18+
end
19+
end
20+
end
21+
22+
describe '#post_install_message' do
23+
it "returns a message" do
24+
expect(subject.post_install_message).to match_approval('libraries/completions_script/message')
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)