File: spec_helper.rb

package info (click to toggle)
ruby-jekyll-last-modified-at 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 216 kB
  • sloc: ruby: 335; makefile: 4; sh: 3
file content (72 lines) | stat: -rw-r--r-- 1,861 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
# frozen_string_literal: true

require "spork"
require "rspec"

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However,
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.

  require "jekyll"
  require "liquid"

  include Jekyll
end

Spork.each_run do
  # This code will be run each time you run your specs.
  require File.expand_path("lib/jekyll-last-modified-at.rb")
end

RSpec.configure do |config|
  config.expect_with(:rspec) do |c|
    c.syntax = :expect
  end

  config.before(:all) do
    Jekyll.logger.log_level = :error

    # original_stderr = $stderr
    # original_stdout = $stdout

    @fixtures_path = Pathname.new(__FILE__).parent.join("fixtures")
    @dest = @fixtures_path.join("_site")
    @posts_src = File.join(@fixtures_path, "_posts")
    @layouts_src = File.join(@fixtures_path, "_layouts")

    $stderr = File.new(File.join(File.dirname(__FILE__), "dev", "err.txt"), "w")
    $stdout = File.new(File.join(File.dirname(__FILE__), "dev", "out.txt"), "w")

    @site = Jekyll::Site.new(Jekyll.configuration(
      "source" => @fixtures_path.to_s,
      "destination" => @dest.to_s,
    ))

    @dest.rmtree if @dest.exist?
    @site.process
  end

  def post_path(file)
    File.join(@posts_src, file)
  end

  def duplicate_post(source, destination)
    File.open(post_path(destination), "w") do |f|
      f.puts(File.read(post_path(source)))
    end
  end

  def setup_post(file)
    Document.new(
      @site.in_source_dir(File.join("_posts", file)),
      site: @site,
      collection: @site.posts,
    ).tap(&:read)
  end

  def do_render(post, layout)
    @site.layouts = { layout.sub(".html", "") => Layout.new(@site, @layouts_src, layout) }
    post.output = Renderer.new(@site, post, @site.site_payload).run
  end
end