Rewrite `with_history` test helper to be more robust
Write mock history to a temp file and load it directly with `fc -R` instead of running each command individually to build up the history.
This commit is contained in:
parent
9ad039443f
commit
e715ffb1ae
|
@ -1,11 +1,6 @@
|
|||
describe 'a multi-line suggestion' do
|
||||
it 'should be displayed on multiple lines' do
|
||||
with_history(-> {
|
||||
session.send_string('echo "')
|
||||
session.send_keys('enter')
|
||||
session.send_string('"')
|
||||
session.send_keys('enter')
|
||||
}) do
|
||||
with_history("echo \"\n\"") do
|
||||
session.send_keys('e')
|
||||
wait_for { session.content }.to eq("echo \"\n\"")
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'pry'
|
||||
require 'rspec/wait'
|
||||
require 'terminal_session'
|
||||
require 'tempfile'
|
||||
|
||||
RSpec.shared_context 'terminal session' do
|
||||
let(:term_opts) { {} }
|
||||
|
@ -21,11 +22,12 @@ RSpec.shared_context 'terminal session' do
|
|||
end
|
||||
|
||||
def with_history(*commands, &block)
|
||||
session.run_command('fc -p')
|
||||
Tempfile.create do |f|
|
||||
f.write(commands.map{|c| c.gsub("\n", "\\\n")}.join("\n"))
|
||||
f.flush
|
||||
|
||||
commands.each do |c|
|
||||
c.respond_to?(:call) ? c.call : session.run_command(c)
|
||||
end
|
||||
session.run_command('fc -p')
|
||||
session.run_command("fc -R #{f.path}")
|
||||
|
||||
session.clear_screen
|
||||
|
||||
|
@ -35,6 +37,7 @@ RSpec.shared_context 'terminal session' do
|
|||
session.run_command('fc -P')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.expect_with :rspec do |expectations|
|
||||
|
|
Loading…
Reference in New Issue