aboutsummaryrefslogtreecommitdiff
path: root/spec/spec_helper.rb
blob: 5b3e0ea27af3792a76960f4357c2a8b14e7697c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'vimrunner'
require 'vimrunner/rspec'

Vimrunner::RSpec.configure do |config|
  #  Set to false to use an instance per test (slower, but can be easier
  #  to manage).
  config.reuse_server = false

  # Decide how to start a Vim instance. In this block, an instance should be
  # spawned and set up with anything project-specific.
  config.start_vim do
    vim = Vimrunner.start

    # Load the plugin
    plugin_path = File.expand_path('../..', __FILE__)
    vim.add_plugin(plugin_path, 'plugin/novim_mode.vim')

    # The returned value is the Client available in the tests.
    vim
  end
end

TEST_FILE = 'test_file.txt'.freeze

def write_file_content(string)
  string = normalize_string_indent(string)
  File.open(TEST_FILE, 'w') { |f| f.write(string) }
  vim.edit TEST_FILE
end

def load_file_content
  vim.write
  IO.read(TEST_FILE).strip
end

def type(string)
  string.scan(/<.*?>|./).each do |key|
    if key =~ /<.*>/
      vim.feedkeys "\\#{key}"
    else
      vim.feedkeys key
    end
  end
end