2017-01-28 05:06:16 +08:00
|
|
|
require 'pry'
|
2017-01-20 13:33:17 +08:00
|
|
|
require 'rspec/wait'
|
2017-01-20 13:33:31 +08:00
|
|
|
require 'terminal_session'
|
2020-05-06 21:23:55 +08:00
|
|
|
require 'tempfile'
|
2017-01-20 13:33:17 +08:00
|
|
|
|
2017-02-17 10:18:03 +08:00
|
|
|
RSpec.shared_context 'terminal session' do
|
|
|
|
let(:term_opts) { {} }
|
|
|
|
let(:session) { TerminalSession.new(term_opts) }
|
|
|
|
let(:before_sourcing) { -> {} }
|
2018-11-11 04:56:31 +08:00
|
|
|
let(:after_sourcing) { -> {} }
|
2017-02-17 10:18:03 +08:00
|
|
|
let(:options) { [] }
|
|
|
|
|
|
|
|
around do |example|
|
|
|
|
before_sourcing.call
|
2019-04-16 02:46:21 +08:00
|
|
|
session.run_command(['source zsh-autosuggestions.zsh', *options].join('; '))
|
2018-11-11 04:56:31 +08:00
|
|
|
after_sourcing.call
|
2017-02-17 10:18:03 +08:00
|
|
|
session.clear_screen
|
|
|
|
|
|
|
|
example.run
|
|
|
|
|
|
|
|
session.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_history(*commands, &block)
|
2020-05-06 21:23:55 +08:00
|
|
|
Tempfile.create do |f|
|
|
|
|
f.write(commands.map{|c| c.gsub("\n", "\\\n")}.join("\n"))
|
|
|
|
f.flush
|
2017-02-17 10:18:03 +08:00
|
|
|
|
2020-05-06 21:23:55 +08:00
|
|
|
session.run_command('fc -p')
|
|
|
|
session.run_command("fc -R #{f.path}")
|
2017-02-17 10:18:03 +08:00
|
|
|
|
2020-05-06 21:23:55 +08:00
|
|
|
session.clear_screen
|
2017-02-17 10:18:03 +08:00
|
|
|
|
2020-05-06 21:23:55 +08:00
|
|
|
yield block
|
2017-02-17 10:18:03 +08:00
|
|
|
|
2020-05-06 21:23:55 +08:00
|
|
|
session.send_keys('C-c')
|
|
|
|
session.run_command('fc -P')
|
|
|
|
end
|
2017-02-17 10:18:03 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-20 13:33:17 +08:00
|
|
|
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
|
2017-02-17 10:18:03 +08:00
|
|
|
|
|
|
|
config.include_context 'terminal session'
|
2017-01-20 13:33:17 +08:00
|
|
|
end
|