From ed47d7468ff11310eb91587428c1cefa28ae0bf7 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Wed, 8 Nov 2017 08:25:20 -0600 Subject: [PATCH] Move all config into yaml file --- test/frontmatter.yml | 70 +++++++++++++++++++++++++------------------- test/lint_test.rb | 19 +++++------- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/test/frontmatter.yml b/test/frontmatter.yml index 0b20977..05c8cd5 100644 --- a/test/frontmatter.yml +++ b/test/frontmatter.yml @@ -1,41 +1,51 @@ # Each piece of content has YAML front matter with these properties: -title: - type: String - required: true +banned_words: + - GitHub App # They're all GitHub Apps + - bot # TODO: link to docs about why bot is not preferred + - automatically # They're all automatic + - probot # Now you're just name dropping -description: - type: String - required: true +exceptions: + bot: ["sentiment-bot"] -slug: - type: String - required: true +fields: + title: + type: String + required: true -screenshots: - type: Array - required: true + description: + type: String + required: true -authors: - type: Array - required: true + slug: + type: String + required: true -repository: - type: String - required: true + screenshots: + type: Array + required: true -host: - type: String - required: true + authors: + type: Array + required: true -# All these fields are generated by `scripts/sync-data` -stars: - type: Numeric + repository: + type: String + required: true -installations: - type: Numeric + host: + type: String + required: true -organizations: - type: Array + # All these fields are generated by `scripts/sync-data` + stars: + type: Numeric -updated: - type: String + installations: + type: Numeric + + organizations: + type: Array + + updated: + type: String diff --git a/test/lint_test.rb b/test/lint_test.rb index 242823a..be2093d 100644 --- a/test/lint_test.rb +++ b/test/lint_test.rb @@ -4,30 +4,27 @@ require "minitest/autorun" require "net/http" describe "lint test" do - BANNED_WORDS = Regexp.new('\b(' + [ - "GitHub App", # They're all GitHub Apps - "bot", # TODO: link to docs about why bot is not preferred - "automatically", # They're all automatic - "probot", # Now you're just name dropping - ].join('|') + ')\b', Regexp::IGNORECASE | Regexp::MULTILINE) + FRONTMATTER = SafeYAML.load_file("test/frontmatter.yml") + + BANNED_WORDS = Regexp.new('\b(' + + FRONTMATTER["banned_words"].join('|') + + ')\b', Regexp::IGNORECASE | Regexp::MULTILINE) EXCEPTIONS = { "bot" => ["sentiment-bot"] } - FIELDS = SafeYAML.load_file("test/frontmatter.yml") - Dir.glob("_apps/*.md").each do |path| describe path do # Load frontmatter data = SafeYAML.load_file(path) it "does not have extraneous fields" do - extra_fields = data.keys - FIELDS.keys + extra_fields = data.keys - FRONTMATTER["fields"].keys assert extra_fields.empty?, "Unexpected metadata: #{extra_fields.inspect}" end - FIELDS.each do |name, attrs| + FRONTMATTER["fields"].each do |name, attrs| if attrs["required"] it "${name} is required" do assert data.key?(name), "#{name} is required" @@ -49,7 +46,7 @@ describe "lint test" do it "does not use banned words" do %w(title description slug).each do |field| match = data[field].match(BANNED_WORDS) - if match && !Array(EXCEPTIONS[match[1].downcase]).include?(data["slug"]) + if match && !Array(FRONTMATTER["exceptions"][match[1].downcase]).include?(data["slug"]) assert !match, "`#{match[1]}` should not be used in #{field}" end end