Add `after_sourcing` hook for tests
Is executed immediately after sourcing the plugin
This commit is contained in:
parent
a78ea16c50
commit
f0f1332e6b
|
@ -3,7 +3,11 @@ describe 'a suggestion for a given prefix' do
|
||||||
let(:foobar_strategy) { '_zsh_autosuggest_strategy_foobar() { [[ "foobar baz" = $1* ]] && suggestion="foobar baz" }' }
|
let(:foobar_strategy) { '_zsh_autosuggest_strategy_foobar() { [[ "foobar baz" = $1* ]] && suggestion="foobar baz" }' }
|
||||||
let(:foobaz_strategy) { '_zsh_autosuggest_strategy_foobaz() { [[ "foobaz bar" = $1* ]] && suggestion="foobaz bar" }' }
|
let(:foobaz_strategy) { '_zsh_autosuggest_strategy_foobaz() { [[ "foobaz bar" = $1* ]] && suggestion="foobaz bar" }' }
|
||||||
|
|
||||||
let(:options) { [ history_strategy ] }
|
let(:after_sourcing) do
|
||||||
|
-> do
|
||||||
|
session.run_command(history_strategy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'by default is determined by calling the `history` strategy function' do
|
it 'by default is determined by calling the `history` strategy function' do
|
||||||
session.send_string('h')
|
session.send_string('h')
|
||||||
|
@ -11,11 +15,14 @@ describe 'a suggestion for a given prefix' do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when ZSH_AUTOSUGGEST_STRATEGY is set to an array' do
|
context 'when ZSH_AUTOSUGGEST_STRATEGY is set to an array' do
|
||||||
let(:options) { [
|
let(:after_sourcing) do
|
||||||
foobar_strategy,
|
-> do
|
||||||
foobaz_strategy,
|
session.
|
||||||
'ZSH_AUTOSUGGEST_STRATEGY=(foobar foobaz)'
|
run_command(foobar_strategy).
|
||||||
] }
|
run_command(foobaz_strategy).
|
||||||
|
run_command('ZSH_AUTOSUGGEST_STRATEGY=(foobar foobaz)')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'is determined by the first strategy function to return a suggestion' do
|
it 'is determined by the first strategy function to return a suggestion' do
|
||||||
session.send_string('foo')
|
session.send_string('foo')
|
||||||
|
@ -27,11 +34,14 @@ describe 'a suggestion for a given prefix' do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when ZSH_AUTOSUGGEST_STRATEGY is set to a string' do
|
context 'when ZSH_AUTOSUGGEST_STRATEGY is set to a string' do
|
||||||
let(:options) { [
|
let(:after_sourcing) do
|
||||||
foobar_strategy,
|
-> do
|
||||||
foobaz_strategy,
|
session.
|
||||||
'ZSH_AUTOSUGGEST_STRATEGY="foobar foobaz"'
|
run_command(foobar_strategy).
|
||||||
] }
|
run_command(foobaz_strategy).
|
||||||
|
run_command('ZSH_AUTOSUGGEST_STRATEGY="foobar foobaz"')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'is determined by the first strategy function to return a suggestion' do
|
it 'is determined by the first strategy function to return a suggestion' do
|
||||||
session.send_string('foo')
|
session.send_string('foo')
|
||||||
|
@ -42,3 +52,4 @@ describe 'a suggestion for a given prefix' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,14 @@ RSpec.shared_context 'terminal session' do
|
||||||
let(:term_opts) { {} }
|
let(:term_opts) { {} }
|
||||||
let(:session) { TerminalSession.new(term_opts) }
|
let(:session) { TerminalSession.new(term_opts) }
|
||||||
let(:before_sourcing) { -> {} }
|
let(:before_sourcing) { -> {} }
|
||||||
|
let(:after_sourcing) { -> {} }
|
||||||
let(:options) { [] }
|
let(:options) { [] }
|
||||||
|
|
||||||
around do |example|
|
around do |example|
|
||||||
before_sourcing.call
|
before_sourcing.call
|
||||||
|
|
||||||
session.run_command((['source zsh-autosuggestions.zsh'] + options).join('; '))
|
session.run_command((['source zsh-autosuggestions.zsh'] + options).join('; '))
|
||||||
|
after_sourcing.call
|
||||||
session.clear_screen
|
session.clear_screen
|
||||||
|
|
||||||
example.run
|
example.run
|
||||||
|
|
Loading…
Reference in New Issue