/
configuration_spec.rb
279 lines (228 loc) · 7.96 KB
/
configuration_spec.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# frozen_string_literal: true
require "spec_helper"
describe(GitHubPages::Configuration) do
let(:test_config) do
{
"source" => fixture_dir,
"quiet" => true,
"testing" => "123",
"destination" => tmp_dir,
}
end
let(:configuration) { Jekyll.configuration(test_config) }
let(:site) { Jekyll::Site.new(configuration) }
let(:effective_config) { described_class.effective_config(site.config) }
let(:defaults_for_env) { described_class.defaults_for_env }
before(:each) do
ENV.delete("DISABLE_WHITELIST")
ENV["JEKYLL_ENV"] = "test"
ENV["PAGES_REPO_NWO"] = "github/pages-gem"
end
context "#effective_config" do
it "sets configuration defaults" do
expect(effective_config["kramdown"]["input"]).to eql("GFM")
expect(effective_config["future"]).to eql(false)
end
it "sets default gems" do
expect(effective_config["plugins"]).to include("jekyll-coffeescript")
end
it "lets the user specify additional gems" do
expect(effective_config["plugins"]).to include("jekyll-sitemap")
end
it "honors the user's config" do
expect(effective_config["some_key"]).to eql("some_value")
end
it "sets overrides" do
expect(effective_config["highlighter"]).to eql("rouge")
end
it "overrides user's values" do
expect(effective_config["safe"]).to eql(true)
expect(effective_config["quiet"]).to eql(true)
end
it "passes passthroughs" do
expect(effective_config["quiet"]).to eql(true)
expect(effective_config["source"]).to eql(fixture_dir)
end
it "accepts local configs" do
expect(effective_config["testing"]).to eql("123")
end
it "sets exclude directive" do
expect(effective_config["exclude"]).to include("CNAME")
end
it "retains Jekyll default excludes" do
expect(effective_config["exclude"]).to include(*Jekyll::Configuration::DEFAULTS["exclude"])
end
context "markdown processor" do
context "with no markdown processor set" do
it "defaults to kramdown" do
expect(effective_config["markdown"]).to eql("kramdown")
end
end
context "with GFM set" do
let(:site) do
config = configuration.merge("markdown" => "GFM")
Jekyll::Site.new(config)
end
it "configures CommonMarkGhPages" do
expect(effective_config["markdown"]).to eql("CommonMarkGhPages")
expect(effective_config["commonmark"]).to eql(
"extensions" => %w(table strikethrough autolink tagfilter),
"options" => %w(footnotes)
)
end
end
context "with some other processor set" do
let(:site) do
config = configuration.merge("markdown" => "whatever")
Jekyll::Site.new(config)
end
it "overrides to kramdown" do
expect(effective_config["markdown"]).to eql("kramdown")
end
end
end
context "themes" do
context "with no theme set" do
it "sets the theme" do
expect(site.theme).to_not be_nil
expect(site.theme).to be_a(Jekyll::Theme)
expect(site.theme.name).to eql("jekyll-theme-primer")
end
end
context "with a user-specified theme" do
let(:configuration) do
described_class.effective_config(
Jekyll.configuration(
test_config.merge("theme" => "jekyll-theme-merlot")
)
)
end
it "respects the theme" do
expect(site.theme).to_not be_nil
expect(site.theme).to be_a(Jekyll::Theme)
expect(site.theme.name).to eql("jekyll-theme-merlot")
end
end
context "with user-specified theme to be null" do
let(:site) do
config = configuration.merge("theme" => nil)
Jekyll::Site.new(config)
end
it "respects null" do
expect(site.theme).to be_nil
end
end
it "plugins don't include jekyll remote theme" do
expect(effective_config["plugins"]).to_not include("jekyll-remote-theme")
end
context "with a remote theme" do
let(:test_config) do
{
"source" => fixture_dir,
"quiet" => true,
"testing" => "123",
"destination" => tmp_dir,
"remote_theme" => "foo/bar",
}
end
it "plugins include jekyll remote theme" do
expect(effective_config["plugins"]).to include("jekyll-remote-theme")
end
end
end
context "in development" do
before { ENV["JEKYLL_ENV"] = "development" }
it "doesn't compress sass" do
expect(effective_config["sass"]).to be_nil
expect(defaults_for_env["sass"]).to be_nil
end
end
end
context "#set being called via the hook" do
let(:test_config) do
{
"source" => fixture_dir,
"quiet" => true,
"testing" => "123",
"destination" => tmp_dir,
"future" => true,
}
end
it "sets configuration defaults" do
expect(site.config["kramdown"]["input"]).to eql("GFM")
end
it "sets default gems" do
expect(site.config["plugins"]).to include("jekyll-coffeescript")
end
it "lets the user specify additional gems" do
expect(site.config["plugins"]).to include("jekyll-sitemap")
end
it "honors the user's config" do
expect(site.config["some_key"]).to eql("some_value")
expect(site.config["future"]).to eql(true)
end
it "sets overrides" do
expect(site.config["highlighter"]).to eql("rouge")
end
it "overrides user's values" do
expect(site.config["safe"]).to eql(true)
expect(site.config["quiet"]).to eql(true)
end
it "passes passthroughs" do
expect(site.config["quiet"]).to eql(true)
expect(site.config["source"]).to eql(fixture_dir)
end
it "accepts local configs" do
expect(site.config["testing"]).to eql("123")
end
end
context "plugins" do
context "in development" do
before { ENV["JEKYLL_ENV"] = "development" }
context "without the DISABLE_WHITELIST flag" do
it "doesn't include additional whitelisted plugins" do
expect(site.config["whitelist"]).not_to include("jekyll_test_plugin_malicious")
end
it "knows not to disable the whitelist" do
expect(described_class.disable_whitelist?).to eql(false)
end
end
context "with the DISABLE_WHITELIST flag" do
before { ENV["DISABLE_WHITELIST"] = "1" }
it "includes additional plugins in the whitelist" do
expect(site.config["whitelist"]).to include("jekyll_test_plugin_malicious")
end
it "fires additional non-whitelisted plugins" do
expect { site.process }.to raise_error "ALL YOUR COMPUTER ARE BELONG TO US"
end
it "knows to disable the whitelist" do
expect(described_class.disable_whitelist?).to eql(true)
end
end
end
context "in production" do
before { ENV["JEKYLL_ENV"] = "production" }
context "without the DISABLE_WHITELIST flag" do
it "doesn't include additional whitelisted plugins" do
expect(site.config["whitelist"]).not_to include("jekyll_test_plugin_malicious")
end
it "knows not to disable the whitelist" do
expect(described_class.disable_whitelist?).to eql(false)
end
end
context "with the DISABLE_WHITELIST flag" do
before { ENV["DISABLE_WHITELIST"] = "1" }
it "doesn't include additional whitelisted plugins" do
expect(site.config["whitelist"]).not_to include("jekyll_test_plugin_malicious")
end
it "knows not to disable the whitelist" do
expect(described_class.disable_whitelist?).to eql(false)
end
end
it "compresses sass" do
expect(effective_config["sass"]).to eql("style" => "compressed")
expect(defaults_for_env["sass"]).to eql("style" => "compressed")
end
end
end
end