This commit is contained in:
Mike McQuaid 2017-10-03 17:28:18 +01:00
Родитель 7ce5077100
Коммит a9d13ec137
3 изменённых файлов: 14 добавлений и 12 удалений

Просмотреть файл

@ -7,4 +7,4 @@ Rake::TestTask.new do |t|
t.verbose = false
end
task :default => :test
task default: :test

Просмотреть файл

@ -1,12 +1,12 @@
require "minitest/autorun"
require "yaml"
IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png"].freeze
IMAGE_EXTENSIONS = %w[.jpg .jpeg .png].freeze
VALID_METADATA_KEYS = ["aliases", "created_by", "display_name", "github_url", "logo", "related",
"released", "short_description", "topic", "url", "wikipedia_url"].freeze
VALID_METADATA_KEYS = %w[aliases created_by display_name github_url logo related
released short_description topic url wikipedia_url].freeze
REQUIRED_METADATA_KEYS = ["topic", "short_description"].freeze
REQUIRED_METADATA_KEYS = %w[topic short_description].freeze
def topics_dir
File.expand_path("../topics", File.dirname(__FILE__))
@ -39,8 +39,8 @@ def metadata_for(topic)
parts = File.read(path).split("---", 3)
return unless parts.size >= 2
metadata = begin
YAML.load(parts[1])
begin
YAML.safe_load(parts[1])
rescue Psych::SyntaxError => ex
flunk "invalid YAML: #{ex.message}"
end

Просмотреть файл

@ -16,7 +16,7 @@ describe "topics" do
if path = paths.first
assert_equal topic, File.basename(path, File.extname(path)),
"expected image to be named [topic].[extension]"
"expected image to be named [topic].[extension]"
end
end
@ -38,7 +38,7 @@ describe "topics" do
if File.file?(path)
lines = File.readlines(path)
assert lines.size > 0
assert !lines.empty?
assert_equal "---\n", lines[0], "expected file to start with Jekyll front matter ---"
end_index = lines.slice(1..-1).index("---\n")
@ -50,14 +50,16 @@ describe "topics" do
metadata = metadata_for(topic)
refute_empty metadata, "expected some metadata for topic"
metadata.each do |key, value|
metadata.each_key do |key,|
assert_includes VALID_METADATA_KEYS, key, "unexpected metadata key '#{key}'"
end
REQUIRED_METADATA_KEYS.each do |key|
assert metadata.key?(key), "expected to have '#{key}' defined for topic"
assert metadata[key] && metadata[key].strip.size > 0,
"expected to have a value for '#{key}'"
assert metadata[key]&.strip&.size&.positive?,
"expected to have a value for '#{key}'"
end
end
end
end
end