File: test_theme_reader.rb

package info (click to toggle)
ruby-jekyll-data 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 420 kB
  • sloc: ruby: 909; sh: 95; makefile: 10
file content (95 lines) | stat: -rw-r--r-- 2,859 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
# frozen_string_literal: true

require "helper"

class TestThemeReader < JekyllDataTest
  context "site without data files but with a valid theme" do
    setup do
      @site = fixture_site(
        "source"      => File.join(source_dir, "no_data_files"),
        "destination" => File.join(dest_dir, "no_data_files")
      )
      assert @site.theme
      @theme_data = ThemeDataReader.new(@site).read("_data")
      @site.process
    end
    should "read data files in theme gem" do
      assert_equal @site.data["navigation"]["topnav"],
                   @theme_data["navigation"]["topnav"]
    end

    should "use data from theme gem" do
      assert_equal(
        File.read(File.join(fixture_dir, "no_data_output.html")),
        File.read(@site.in_dest_dir("output.html"))
      )
    end
  end

  context "site with data keys different from a valid theme data hash" do
    setup do
      @site = fixture_site(
        "source"      => File.join(source_dir, "diff_data_keys"),
        "destination" => File.join(dest_dir, "diff_data_keys")
      )
      assert @site.theme
      @theme_data = ThemeDataReader.new(@site).read("_data")
      @site.process
    end
    should "read and use data from other keys in theme gem" do
      assert_equal(
        File.read(File.join(fixture_dir, "different_data_output.html")),
        File.read(@site.in_dest_dir("output.html"))
      )
    end

    should "not override theme data" do
      assert_equal(
        File.read(File.join(fixture_dir, "different_data_output.html")),
        File.read(@site.in_dest_dir("output.html"))
      )
    end
  end

  context "site with same data keys as a valid theme data hash" do
    setup do
      @site = fixture_site(
        "source"      => File.join(source_dir, "same_data_files"),
        "destination" => File.join(dest_dir, "same_data_files")
      )
      assert @site.theme
      @theme_data = ThemeDataReader.new(@site).read("_data")
      @site.process
    end
    should "override theme data" do
      assert_equal(
        File.read(File.join(fixture_dir, "same_data_override.html")),
        File.read(@site.in_dest_dir("override.html"))
      )
    end

    should "also use data from other keys in theme gem" do
      assert_equal(
        File.read(File.join(fixture_dir, "same_data_output.html")),
        File.read(@site.in_dest_dir("override.html"))
      )
    end
  end

  context "theme gem shipped with a '_config.yml'" do
    setup do
      @site = fixture_site(
        "title" => "Config Test"
      )
    end

    should "have its hash appended to site's config hash" do
      assert_contains @site.config, %w(post_excerpts enabled)
    end

    should "have its hash added only where its not already set" do
      refute_equal "Test Theme", @site.config["title"]
      assert_equal "Config Test", @site.config["title"]
    end
  end
end