diff --git a/spec/multi_line_spec.rb b/spec/multi_line_spec.rb index 4ff2ae1..364780a 100644 --- a/spec/multi_line_spec.rb +++ b/spec/multi_line_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cb149ef..dc1abb0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ require 'pry' require 'rspec/wait' require 'terminal_session' +require 'tempfile' RSpec.shared_context 'terminal session' do let(:term_opts) { {} } @@ -21,18 +22,20 @@ 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) + session.run_command('fc -p') + session.run_command("fc -R #{f.path}") + + session.clear_screen + + yield block + + session.send_keys('C-c') + session.run_command('fc -P') end - - session.clear_screen - - yield block - - session.send_keys('C-c') - session.run_command('fc -P') end end