Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ jobs:
ruby-version: '${{ matrix.ruby }}'
bundler-cache: true

- name: Install zsh
run: sudo apt install -y zsh

- name: Run tests
run: bundle exec rspec
9 changes: 8 additions & 1 deletion lib/completely/templates/tester-template.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/usr/bin/env bash
if [[ -n $ZSH_VERSION ]]; then
autoload -U +X bashcompinit && bashcompinit
autoload -U +X compinit && compinit
fi

# === COMPLETION SCRIPT START ===

<%= script || %Q[source "#{absolute_script_path}"] %>

# END OF COMPLETION SCRIPT
# === COMPLETION SCRIPT END ===

COMP_WORDS=( <%= compline %> )
COMP_LINE="<%= compline %>"
Expand Down
32 changes: 32 additions & 0 deletions spec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Completely Specs

## Running tests

```bash
$ rspec
# or
$ run spec
# or, to run just tests in a given file
$ run spec zsh
# or, to run just specs tagged with :focus
$ run spec :focus
```

You might need to prefix the commands with `bundle exec`, depending on the way
Ruby is installed.

## Interactive Approvals

Some tests may prompt you for an interactive approval of changes. This
functionality is provided by the [rspec_approvals gem][1].

Be sure to only approve changes that are indeed expected.


## ZSH Compatibility Test

ZSH compatibility test is done by running the completely tester script inside a
zsh container. This is all done automatically by `spec/completely/zsh_spec.rb`.


[1]: https://github.com/dannyben/rspec_approvals
9 changes: 8 additions & 1 deletion spec/approvals/tester/script
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/usr/bin/env bash
if [[ -n $ZSH_VERSION ]]; then
autoload -U +X bashcompinit && bashcompinit
autoload -U +X compinit && compinit
fi

# === COMPLETION SCRIPT START ===

# some completion script

# END OF COMPLETION SCRIPT
# === COMPLETION SCRIPT END ===

COMP_WORDS=( cli co )
COMP_LINE="cli co"
Expand Down
9 changes: 8 additions & 1 deletion spec/approvals/tester/script_path
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/usr/bin/env bash
if [[ -n $ZSH_VERSION ]]; then
autoload -U +X bashcompinit && bashcompinit
autoload -U +X compinit && compinit
fi

# === COMPLETION SCRIPT START ===

source "<path removed>"

# END OF COMPLETION SCRIPT
# === COMPLETION SCRIPT END ===

COMP_WORDS=( cli co )
COMP_LINE="cli co"
Expand Down
35 changes: 35 additions & 0 deletions spec/completely/zsh_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

describe "zsh compatibility" do
let(:completions) { Completely::Completions.load 'spec/fixtures/basic.yaml' }
let(:words) { "completely generate " }
let(:tester_script) { completions.tester.tester_script words }
let(:shell) { 'zsh' }

before do
reset_tmp_dir
system "mkdir -p spec/tmp/somedir"
File.write "spec/tmp/test.sh", tester_script
end

subject do
Dir.chdir 'spec/tmp' do
`#{shell} test.sh`.strip
end
end

describe "completions script and test script" do
it "returns completions without erroring" do
expect(subject).to eq "somedir --help --force"
end

context "on bash" do
let(:shell) { 'bash' }

it "returns the same output" do
expect(subject).to eq "somedir --help --force"
end
end
end

end