Skip to content

Commit 94afb0a

Browse files
Copilotahpook
andauthored
Centralize malformed-frontmatter skip in metadata_for
Co-authored-by: ahpook <56753+ahpook@users.noreply.github.com>
1 parent 3ec820a commit 94afb0a

3 files changed

Lines changed: 3 additions & 19 deletions

File tree

test/collections_test.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
end
2727

2828
it "has valid items" do
29-
skip "malformed YAML frontmatter" if frontmatter_malformed?(collections_dir, collection)
30-
3129
invalid_slugs = []
3230

3331
items_for_collection(collection).each do |item|
@@ -40,8 +38,6 @@
4038
end
4139

4240
it "has valid number of items" do
43-
skip "malformed YAML frontmatter" if frontmatter_malformed?(collections_dir, collection)
44-
4541
items = items_for_collection(collection)
4642
assert (1...MAX_COLLECTION_ITEMS_LENGTH + 1).cover?(items.length),
4743
"must have no more than #{MAX_COLLECTION_ITEMS_LENGTH} items " \
@@ -80,8 +76,6 @@
8076
end
8177

8278
it "has expected metadata in Jekyll front matter" do
83-
skip "malformed YAML frontmatter" if frontmatter_malformed?(collections_dir, collection)
84-
8579
metadata = metadata_for(collections_dir, collection)
8680
refute_empty metadata, "expected some metadata for collection"
8781

test/test_helper.rb

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,12 @@ def metadata_for(dir, name)
252252
begin
253253
YAML.safe_load(frontmatter)
254254
rescue Psych::SyntaxError
255-
nil
255+
# Malformed frontmatter is reported by the dedicated YAML syntax test.
256+
# Skip metadata-dependent tests here so that syntax test is the sole failure.
257+
skip "malformed YAML frontmatter in #{File.join(dir, name, 'index.md')}"
256258
end
257259
end
258260

259-
def frontmatter_malformed?(dir, name)
260-
frontmatter = frontmatter_for(dir, name)
261-
return false unless frontmatter
262-
263-
YAML.safe_load(frontmatter)
264-
false
265-
rescue Psych::SyntaxError
266-
true
267-
end
268-
269261
def yaml_syntax_error_for(dir, name)
270262
frontmatter = frontmatter_for(dir, name)
271263
return unless frontmatter

test/topics_test.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@
275275
end
276276

277277
it "has expected metadata in Jekyll front matter" do
278-
skip "malformed YAML frontmatter" if frontmatter_malformed?(topics_dir, topic)
279-
280278
metadata = metadata_for(topics_dir, topic)
281279
refute_empty metadata, "expected some metadata for topic"
282280

0 commit comments

Comments
 (0)