summaryrefslogtreecommitdiff
path: root/home-config/zsh/zsh-autosuggestions/spec/spec_helper.rb
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-09-04 23:21:01 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-09-04 23:21:01 -0400
commitdb49f683129771d95828b01594c69431a717e8e8 (patch)
treed2cb1c0b865e4d81ce81f9a3176b8ad93a864950 /home-config/zsh/zsh-autosuggestions/spec/spec_helper.rb
downloaddotfiles-guix-db49f683129771d95828b01594c69431a717e8e8.tar.gz
dotfiles-guix-db49f683129771d95828b01594c69431a717e8e8.tar.bz2
dotfiles-guix-db49f683129771d95828b01594c69431a717e8e8.zip
guix
Diffstat (limited to '')
-rw-r--r--home-config/zsh/zsh-autosuggestions/spec/spec_helper.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/home-config/zsh/zsh-autosuggestions/spec/spec_helper.rb b/home-config/zsh/zsh-autosuggestions/spec/spec_helper.rb
new file mode 100644
index 0000000..dc1abb0
--- /dev/null
+++ b/home-config/zsh/zsh-autosuggestions/spec/spec_helper.rb
@@ -0,0 +1,54 @@
+require 'pry'
+require 'rspec/wait'
+require 'terminal_session'
+require 'tempfile'
+
+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)
+ Tempfile.create do |f|
+ f.write(commands.map{|c| c.gsub("\n", "\\\n")}.join("\n"))
+ f.flush
+
+ 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
+ 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