File: spec_helper.rb

package info (click to toggle)
vim-addon-manager 0.5.10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 312 kB
  • sloc: ruby: 970; makefile: 15; sh: 7
file content (67 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'vim/addon_manager'
require 'vim/addon_manager/registry'
require 'tmpdir'

begin
  require 'pry'
rescue LoadError
end

FAKE_REGISTRY = File.join(File.dirname(__FILE__), 'data/registry')
FAKE_SCRIPTS  = File.join(File.dirname(__FILE__), 'data/scripts')

module VimAddonManagerSpecHelper

  class Target
    attr :path
    def initialize(path)
      @path = path
    end
    alias :to_s :path
    def has_file?(file)
      File.exists?(File.join(path, file))
    end
    def has_symlink?(file)
      File.symlink?(File.join(path, file))
    end
    def rm(file)
      FileUtils.rm(File.join(path, file))
    end
  end

  def tmpdir
    @tmpdir ||= Dir.mktmpdir
  end

  def target_dir
    @target_dir ||= Target.new(tmpdir)
  end

  def registry
    @registry ||= Vim::AddonManager::Registry.new(FAKE_REGISTRY, FAKE_SCRIPTS)
  end

  def addon(name)
    registry[name]
  end

  def addons(*addon_names)
    addon_names.map { |name| registry[name] }
  end

  def addon_manager
    @addon_manager ||= Vim::AddonManager.new(target_dir.path)
  end

  def override_file
    @override_file ||= Vim::AddonManager.override_file(target_dir.path)
  end

end

require 'rspec'
RSpec.configure do |config|
  config.before { Vim::AddonManager.logger.quiet! }
  config.after { FileUtils.rm_rf(tmpdir) }
  config.include VimAddonManagerSpecHelper
end