2023-04-18 16:30:29 +02:00
|
|
|
require 'pry'
|
|
|
|
require 'rspec/wait'
|
|
|
|
require 'terminal_session'
|
2024-02-23 09:52:24 +01:00
|
|
|
require 'tempfile'
|
2023-04-18 16:30:29 +02:00
|
|
|
|
|
|
|
RSpec.shared_context 'terminal session' do
|
|
|
|
let(:term_opts) { {} }
|
|
|
|
let(:session) { TerminalSession.new(term_opts) }
|
|
|
|
let(:before_sourcing) { -> {} }
|
|
|
|
let(:after_sourcing) { -> {} }
|
|
|
|
let(:options) { [] }
|
|
|
|
|
|
|
|
around do |example|
|
|
|
|
before_sourcing.call
|
|
|
|
session.run_command(['source zsh-autosuggestions.zsh', *options].join('; '))
|
|
|
|
after_sourcing.call
|
|
|
|
session.clear_screen
|
|
|
|
|
|
|
|
example.run
|
|
|
|
|
|
|
|
session.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_history(*commands, &block)
|
2024-02-23 09:52:24 +01:00
|
|
|
Tempfile.create do |f|
|
|
|
|
f.write(commands.map{|c| c.gsub("\n", "\\\n")}.join("\n"))
|
|
|
|
f.flush
|
2023-04-18 16:30:29 +02:00
|
|
|
|
2024-02-23 09:52:24 +01:00
|
|
|
session.run_command('fc -p')
|
|
|
|
session.run_command("fc -R #{f.path}")
|
2023-04-18 16:30:29 +02:00
|
|
|
|
2024-02-23 09:52:24 +01:00
|
|
|
session.clear_screen
|
2023-04-18 16:30:29 +02:00
|
|
|
|
2024-02-23 09:52:24 +01:00
|
|
|
yield block
|
2023-04-18 16:30:29 +02:00
|
|
|
|
2024-02-23 09:52:24 +01:00
|
|
|
session.send_keys('C-c')
|
|
|
|
session.run_command('fc -P')
|
|
|
|
end
|
2023-04-18 16:30:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.expect_with :rspec do |expectations|
|
|
|
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
|
|
end
|
|
|
|
|
|
|
|
config.mock_with :rspec do |mocks|
|
|
|
|
mocks.verify_partial_doubles = true
|
|
|
|
end
|
|
|
|
|
|
|
|
config.wait_timeout = 2
|
|
|
|
|
|
|
|
config.include_context 'terminal session'
|
|
|
|
end
|