-
Notifications
You must be signed in to change notification settings - Fork 630
/
Copy pathtest_plugin_news.rb
124 lines (93 loc) · 2.5 KB
/
test_plugin_news.rb
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# frozen_string_literal: true
require "helper"
require "jekyll"
require_relative "../_plugins/news"
describe NewsArchivePlugin do
before do
chdir_tempdir
content = <<~CONFIG
CONFIG
create_file("source/_config.yml", content)
content = <<~LOCALES
month_names:
- January
- February
news:
recent_news: Recent News
yearly_archive_title: "%Y Archives"
monthly_archive_title: "%B %Y Archives"
yearly_archive_link: "%Y Archives"
monthly_archive_link: "%B %Y"
LOCALES
create_file("source/_data/locales/en.yml", content)
content = <<~LAYOUT
---
layout: default
---
NEWS LAYOUT
{% for post in page.posts %}
{{ post.title }}
{% endfor %}
LAYOUT
create_file("source/_layouts/news.html", content)
content = <<~LAYOUT
---
layout: default
---
NEWS ARCHIVE YEAR LAYOUT
{% for post in page.posts %}
{{ post.title }}
{% endfor %}
LAYOUT
create_file("source/_layouts/news_archive_year.html", content)
content = <<~LAYOUT
---
layout: default
---
NEWS ARCHIVE MONTH LAYOUT
{% for post in page.posts %}
{{ post.title }}
{% endfor %}
LAYOUT
create_file("source/_layouts/news_archive_month.html", content)
content = <<~POST
---
title: "Post Jan 2020"
author: "stomar"
date: 2020-01-01 12:00:00 +0000
lang: en
---
Content
POST
create_file("source/en/news/_posts/2020-01-01-post.md", content)
config = Jekyll.configuration(
source: "source",
destination: "_site",
quiet: true
)
site = Jekyll::Site.new(config)
file_wont_exist("_site")
site.process
end
after do
teardown_tempdir
end
it "should create news page" do
file_must_exist("_site/en/news/index.html")
end
it "should use the correct layout for news page" do
_(File.read("_site/en/news/index.html")).must_match "NEWS LAYOUT"
end
it "should create news/2020 page" do
file_must_exist("_site/en/news/2020/index.html")
end
it "should use the correct layout for news/2020 page" do
_(File.read("_site/en/news/2020/index.html")).must_match "YEAR LAYOUT"
end
it "should create news/2020/01 page" do
file_must_exist("_site/en/news/2020/index.html")
end
it "should use the correct layout for news/2020/01 page" do
_(File.read("_site/en/news/2020/01/index.html")).must_match "MONTH LAYOUT"
end
end