Skip to content

Commit 18232cf

Browse files
authored
Merge pull request #24 from DannyBen/add/zsh-spec
Add tests for zsh
2 parents 01701f1 + d27dd98 commit 18232cf

File tree

6 files changed

+94
-3
lines changed

6 files changed

+94
-3
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ jobs:
2222
ruby-version: '${{ matrix.ruby }}'
2323
bundler-cache: true
2424

25+
- name: Install zsh
26+
run: sudo apt install -y zsh
27+
2528
- name: Run tests
2629
run: bundle exec rspec

lib/completely/templates/tester-template.erb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#!/usr/bin/env bash
2+
if [[ -n $ZSH_VERSION ]]; then
3+
autoload -U +X bashcompinit && bashcompinit
4+
autoload -U +X compinit && compinit
5+
fi
6+
7+
# === COMPLETION SCRIPT START ===
8+
29
<%= script || %Q[source "#{absolute_script_path}"] %>
310

4-
# END OF COMPLETION SCRIPT
11+
# === COMPLETION SCRIPT END ===
512

613
COMP_WORDS=( <%= compline %> )
714
COMP_LINE="<%= compline %>"

spec/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Completely Specs
2+
3+
## Running tests
4+
5+
```bash
6+
$ rspec
7+
# or
8+
$ run spec
9+
# or, to run just tests in a given file
10+
$ run spec zsh
11+
# or, to run just specs tagged with :focus
12+
$ run spec :focus
13+
```
14+
15+
You might need to prefix the commands with `bundle exec`, depending on the way
16+
Ruby is installed.
17+
18+
## Interactive Approvals
19+
20+
Some tests may prompt you for an interactive approval of changes. This
21+
functionality is provided by the [rspec_approvals gem][1].
22+
23+
Be sure to only approve changes that are indeed expected.
24+
25+
26+
## ZSH Compatibility Test
27+
28+
ZSH compatibility test is done by running the completely tester script inside a
29+
zsh container. This is all done automatically by `spec/completely/zsh_spec.rb`.
30+
31+
32+
[1]: https://github.com/dannyben/rspec_approvals

spec/approvals/tester/script

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#!/usr/bin/env bash
2+
if [[ -n $ZSH_VERSION ]]; then
3+
autoload -U +X bashcompinit && bashcompinit
4+
autoload -U +X compinit && compinit
5+
fi
6+
7+
# === COMPLETION SCRIPT START ===
8+
29
# some completion script
310

4-
# END OF COMPLETION SCRIPT
11+
# === COMPLETION SCRIPT END ===
512

613
COMP_WORDS=( cli co )
714
COMP_LINE="cli co"

spec/approvals/tester/script_path

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#!/usr/bin/env bash
2+
if [[ -n $ZSH_VERSION ]]; then
3+
autoload -U +X bashcompinit && bashcompinit
4+
autoload -U +X compinit && compinit
5+
fi
6+
7+
# === COMPLETION SCRIPT START ===
8+
29
source "<path removed>"
310

4-
# END OF COMPLETION SCRIPT
11+
# === COMPLETION SCRIPT END ===
512

613
COMP_WORDS=( cli co )
714
COMP_LINE="cli co"

spec/completely/zsh_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require 'spec_helper'
2+
3+
describe "zsh compatibility" do
4+
let(:completions) { Completely::Completions.load 'spec/fixtures/basic.yaml' }
5+
let(:words) { "completely generate " }
6+
let(:tester_script) { completions.tester.tester_script words }
7+
let(:shell) { 'zsh' }
8+
9+
before do
10+
reset_tmp_dir
11+
system "mkdir -p spec/tmp/somedir"
12+
File.write "spec/tmp/test.sh", tester_script
13+
end
14+
15+
subject do
16+
Dir.chdir 'spec/tmp' do
17+
`#{shell} test.sh`.strip
18+
end
19+
end
20+
21+
describe "completions script and test script" do
22+
it "returns completions without erroring" do
23+
expect(subject).to eq "somedir --help --force"
24+
end
25+
26+
context "on bash" do
27+
let(:shell) { 'bash' }
28+
29+
it "returns the same output" do
30+
expect(subject).to eq "somedir --help --force"
31+
end
32+
end
33+
end
34+
35+
end

0 commit comments

Comments
 (0)