File: spec_helper.rb

package info (click to toggle)
ruby-jekyll-asciidoc 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,536 kB
  • sloc: ruby: 1,802; sh: 36; makefile: 6
file content (99 lines) | stat: -rw-r--r-- 2,653 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
if ENV['COVERAGE'] == 'deep'
  ENV['DEEP_COVER'] = 'true'
  require 'deep_cover'
elsif ENV['COVERAGE'] == 'true'
  require 'deep_cover/builtin_takeover'
  require 'simplecov'
end

require 'jekyll'
require 'fileutils'

Jekyll.logger.log_level = :error

RSpec.configure do |config|
  config.before :suite do
    ::FileUtils.rm_rf output_dir
    if ENV['JEKYLL_VERSION'] == '3.0.0'
      plugins_rx = /([*&])?plugins(:)?/
      plugins_to_gems_sub = '\1gems\2'
      Dir[%(#{fixtures_dir}/**/_config.yml)].each do |filename|
        ::File.write filename, ((::File.read filename).gsub plugins_rx, plugins_to_gems_sub)
      end
    end
  end

  config.after :suite do
    if ENV['JEKYLL_VERSION'] == '3.0.0'
      gems_rx = /([*&])?gems(:)?/
      gems_to_plugins_sub = '\1plugins\2'
      Dir[%(#{fixtures_dir}/**/_config.yml)].each do |filename|
        ::File.write filename, ((::File.read filename).gsub gems_rx, gems_to_plugins_sub)
      end
    else
      Dir[%(#{fixtures_dir}/**/.jekyll-cache)].each {|dirname| FileUtils.rm_rf dirname }
    end
  end

  config.before :each do
    (expect ::File.exist? (source_dir (::File.join name.to_s, '_config.yml'))).to be_truthy
  end

  def use_fixture name, config_path = ''
    let (:name) { name.to_s }
    let (:config_path) { (config_path || '').to_s }
  end

  def fixture_site_params path
    {
      'source' => (source_dir path),
      'destination' => (output_dir path),
      'url' => 'http://example.org',
      config_path && 'config' => (File.join (source_dir path), config_path, '_config.yml'),
    }
  end

  def source_dir path
    ::File.join fixtures_dir, path
  end

  def source_file path
    ::File.join site.config['source'], path
  end

  def fixtures_dir
    ::File.absolute_path 'fixtures', __dir__
  end

  def output_dir path = nil
    base = ::File.absolute_path '../build/test-output', __dir__
    path ? (::File.join base, path) : base
  end

  def output_file path
    ::File.join site.config['destination'], path
  end

  def find_page path
    site.pages.find {|p| p.path == path }
  end

  def find_post path
    path = %(_posts/#{path}) unless path.start_with? '_posts/'
    site.posts.docs.find {|p| p.relative_path == path }
  end

  def find_draft path
    path = %(_drafts/#{path}) unless path.start_with? '_drafts/'
    site.posts.docs.find {|p| p.relative_path == path }
  end

  def find_doc path, collection_name
    path = %(_#{collection_name}/#{path}) unless path.start_with? %(_#{collection_name}/)
    site.collections[collection_name].docs.find {|p| p.relative_path == path }
  end

  def windows?
    /win|ming/ =~ ::RbConfig::CONFIG['host_os']
  end
end