Skip to content

Commit 57abb7f

Browse files
committed
Add tests for FrontMatterPropertyExists checking 2
1 parent 563236a commit 57abb7f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
layout: post
3+
title: "Has Description"
4+
description: asdasdas
5+
image: hello.jpg
6+
---
7+
8+
Aw yeah.

spec/jekyll-pre-commit_spec.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
end
3434
end
3535

36-
context "with FrontMatterPropertyExists check only checking that description exists" do
36+
context "with FrontMatterPropertyExists check only checking description" do
3737
pre_commit_config = {"check" => "FrontMatterPropertyExists", "properties" => ["description"]}
3838
let(:site) { build_site({ 'pre-commit' => [pre_commit_config] }) }
3939

@@ -61,6 +61,30 @@
6161
end
6262
end
6363

64+
context "with FrontMatterPropertyExistsCheck checking description and image" do
65+
pre_commit_config = {"check" => "FrontMatterPropertyExists", "properties" => ["description", "image"]}
66+
let(:site) { build_site({ 'pre-commit' => [pre_commit_config] }) }
67+
68+
it "fails if a staged post has a description, but no image" do
69+
result = runner.run(site, ["spec/fixtures/_posts/2017-01-06-has-description.md"])
70+
expect(result[:ok]).to eql(false)
71+
expect(result[:messages]).to match_array(["Has Description was missing a image. "])
72+
end
73+
74+
it "fails if a staged post is missing a description and an image" do
75+
result = runner.run(site, ["spec/fixtures/_posts/2017-01-06-no-description.md"])
76+
expect(result[:ok]).to eql(false)
77+
message = "No Description was missing a description. No Description was missing a image. "
78+
expect(result[:messages]).to match_array([message])
79+
end
80+
81+
it "succeeds if all staged posts have descriptions and images" do
82+
result = runner.run(site, ["spec/fixtures/_posts/2017-01-07-has-description-and-image.md"])
83+
expect(result[:ok]).to eql(true)
84+
expect(result[:messages]).to match_array([])
85+
end
86+
end
87+
6488
context "with description is not duplicate check" do
6589
let(:site) { build_site({'pre-commit' => [{"check" => "DescriptionIsNotDuplicate"}]}) }
6690

0 commit comments

Comments
 (0)