jekyll_frontmatter_tests 0.0.8 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/jekyll-frontmatter-tests.gemspec +28 -0
- data/lib/jekyll_frontmatter_tests.rb +13 -206
- data/lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_config.rb +13 -0
- data/lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_helper.rb +27 -0
- data/lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_initializer.rb +27 -0
- data/lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_loader.rb +27 -0
- data/lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_processor.rb +38 -0
- data/lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_tester.rb +79 -0
- data/lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_validator.rb +77 -0
- metadata +97 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5c718f92a10c456fc3de9200cb9ee118be1ae6d
|
4
|
+
data.tar.gz: 30a742446ac86710459c13c3134f30dbf73b7bc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b04dc99b1c587aa6f31fa96d519035584742fc8b85d243bd13cbf521066f5c717793c3c331e61f5b7e88eb563de0f15b5dd565622e06d12c4480c5ef431c903
|
7
|
+
data.tar.gz: 009eacfd2f6f535fa7a8402198e52761ad588a8bd3d9143066466bac8bcc3c4f5ef8f17e57ac67c00c1610d2a0ca1403f2423ed24be19baf1757432554860bf5
|
data/Gemfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.description = 'Tests the frontmatter of posts and other collection documents against a schema'
|
3
|
+
s.summary = 'Tests jekyll documents for proper frontmatter'
|
4
|
+
s.name = 'jekyll_frontmatter_tests'
|
5
|
+
s.date = '2015-09-10'
|
6
|
+
s.license = 'CC0'
|
7
|
+
s.authors = ['Greg Boone']
|
8
|
+
s.email = ['gregory.boone@gsa.gov']
|
9
|
+
s.version = '0.0.13'
|
10
|
+
s.files = %w{
|
11
|
+
jekyll-frontmatter-tests.gemspec
|
12
|
+
Gemfile
|
13
|
+
} +
|
14
|
+
Dir.glob("lib/**/*")
|
15
|
+
s.homepage = 'https://rubygems.org/gems/jekyll_frontmatter_tests'
|
16
|
+
s.bindir = 'bin'
|
17
|
+
s.post_install_message = "Happy testing!"
|
18
|
+
s.add_dependency "jekyll", [">= 2.0", "< 4.0"]
|
19
|
+
s.add_development_dependency "bundler", "~> 1.7"
|
20
|
+
s.add_development_dependency "rspec", "~> 3.0"
|
21
|
+
s.add_development_dependency "pry", '~> 0'
|
22
|
+
s.add_development_dependency "capybara", '~> 2.11'
|
23
|
+
s.add_development_dependency "chromedriver-helper", '~> 1.0'
|
24
|
+
s.add_development_dependency "rack-jekyll", '~> 0.5'
|
25
|
+
s.add_development_dependency "rb-readline", '~> 0.5.3'
|
26
|
+
s.add_development_dependency "selenium-webdriver", '~> 3.0'
|
27
|
+
s.add_development_dependency "rubocop", '~> 0.47.1'
|
28
|
+
end
|
@@ -1,207 +1,14 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
if File.exists?(schema)
|
16
|
-
YAML.load_file(schema)
|
17
|
-
else
|
18
|
-
puts "No schema for #{file}"
|
19
|
-
exit 1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Public: processes a collection against a schema
|
24
|
-
#
|
25
|
-
# schmea - the hash-representation of a schema file
|
26
|
-
#
|
27
|
-
# Opens each file in the collection's expected directory and checks the
|
28
|
-
# file's frontmatter for the expected keys and the expected format of the
|
29
|
-
# values.
|
30
|
-
#
|
31
|
-
# Returns true or false depending on the success of the check.
|
32
|
-
def process(schema)
|
33
|
-
dir = File.join(schema['config']['path'])
|
34
|
-
passfail = Array.new
|
35
|
-
Dir.open(dir).each do |f|
|
36
|
-
file = File.open(File.join(dir, f))
|
37
|
-
unless schema['config']['ignore'].include?(f)
|
38
|
-
data = YAML.load_file(file)
|
39
|
-
passfail.push check_keys(data, schema.keys, f)
|
40
|
-
passfail.push check_types(data, schema)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
passfail.keep_if { |p| p == false }
|
44
|
-
if passfail.empty?
|
45
|
-
return true
|
46
|
-
else
|
47
|
-
puts "There were #{passfail.count} errors".red
|
48
|
-
return false
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Public: checks a hash for expected keys
|
53
|
-
#
|
54
|
-
# target - the hash under test
|
55
|
-
# keys - an array of keys the data is expected to have, usually loaded from
|
56
|
-
# a schema file by loadschema()
|
57
|
-
# title - A string representing `data`'s name
|
58
|
-
def check_keys(target, keys, title)
|
59
|
-
keys = keys - ['config']
|
60
|
-
unless target.respond_to?('keys')
|
61
|
-
puts "The file #{title} is missing all frontmatter.".red
|
62
|
-
return false
|
63
|
-
end
|
64
|
-
diff = keys - target.keys
|
65
|
-
if diff.empty?
|
66
|
-
return true
|
67
|
-
else
|
68
|
-
puts "\nThe file #{title} is missing the following keys:".red
|
69
|
-
for k in diff
|
70
|
-
puts " * #{k}".red
|
71
|
-
end
|
72
|
-
return false
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Public: tests all documents that are "posts"
|
77
|
-
#
|
78
|
-
# Loads a schema called _posts.yml and processes all post documents against
|
79
|
-
# it.
|
80
|
-
def test_posts
|
81
|
-
puts 'testing posts'.green
|
82
|
-
yepnope = Array.new.push process(loadschema('_posts.yml'))
|
83
|
-
puts 'Finished testing'.green
|
84
|
-
yepnope
|
85
|
-
end
|
86
|
-
|
87
|
-
# Public: Tests only specific collection documents
|
88
|
-
#
|
89
|
-
# collections - a comma separated string of collection names.
|
90
|
-
#
|
91
|
-
# `collections` is split into an array and each document is loaded and
|
92
|
-
# processed against its respective schema.
|
93
|
-
def test_collections(collections)
|
94
|
-
yepnope = Array.new
|
95
|
-
for c in collections
|
96
|
-
puts "Testing #{c}".green
|
97
|
-
yepnope.push process(loadschema("_#{c}.yml"))
|
98
|
-
puts "Finished testing #{c}".green
|
99
|
-
end
|
100
|
-
yepnope
|
101
|
-
end
|
102
|
-
|
103
|
-
# Public: Tests all collections described by a schema file at
|
104
|
-
# `deploy/tests/scema`
|
105
|
-
def test_everything
|
106
|
-
schema = Dir.open(@schema['path'])
|
107
|
-
yepnope = Array.new
|
108
|
-
schema.each { |s|
|
109
|
-
if s.start_with?('_')
|
110
|
-
puts "Testing #{s}".green
|
111
|
-
yepnope.push process(loadschema(s))
|
112
|
-
puts "Finished testing #{s}".green
|
113
|
-
end
|
114
|
-
}
|
115
|
-
yepnope
|
116
|
-
end
|
117
|
-
|
118
|
-
# Public: Processes options passed throguh the command line, runs
|
119
|
-
# the appropriate tests.
|
120
|
-
#
|
121
|
-
# args - command line arguments (example: jekyll test [ARG])
|
122
|
-
# options - command line options (example: jekyll test -[option] [value])
|
123
|
-
#
|
124
|
-
# Depending on the flag passed (see `init_with_program`), runs the expected # test.
|
125
|
-
#
|
126
|
-
# Example: the following comamnd `jekyll test -p` will pass ``{'posts' =>
|
127
|
-
# true}` as `options`. This will cause `test_frontmatter` to
|
128
|
-
# compare all docs in _posts with the provided schema.
|
129
|
-
#
|
130
|
-
# The test runner pushes the result of each test into a `results` array and # exits `1` if any tests fail or `0` if all is well.
|
131
|
-
def test_frontmatter(args, options)
|
132
|
-
|
133
|
-
puts 'starting tests'
|
134
|
-
if options['posts']
|
135
|
-
results = test_posts
|
136
|
-
elsif options['collections']
|
137
|
-
collections = options['collections'].split(',')
|
138
|
-
results = test_collections(collections)
|
139
|
-
else
|
140
|
-
results = test_everything
|
141
|
-
end
|
142
|
-
unless results.find_index{ |r| r == false }
|
143
|
-
puts 'Tests finished!'
|
144
|
-
exit 0
|
145
|
-
else
|
146
|
-
puts "The test exited with errors, see above."
|
147
|
-
exit 1
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
# Internal: fired when `jekyll test` is run.
|
152
|
-
#
|
153
|
-
# When `jekyll test` runs, `test_frontmatter` is fired with options and args
|
154
|
-
# passed from the command line.
|
155
|
-
def init_with_program(prog)
|
156
|
-
config = Jekyll.configuration
|
157
|
-
unless config.key?('frontmatter_tests')
|
158
|
-
config['frontmatter_tests'] = {'path' => File.join("deploy", "tests", "schema")}
|
159
|
-
end
|
160
|
-
@schema ||= config['frontmatter_tests']
|
161
|
-
prog.command(:test) do |c|
|
162
|
-
c.syntax "test [options]"
|
163
|
-
c.description 'Test your site for frontmatter.'
|
164
|
-
|
165
|
-
c.option 'posts', '-p', 'Target only posts'
|
166
|
-
c.option 'collections', '-c [COLLECTION]', 'Target a specific collection'
|
167
|
-
c.option 'all', '-a', 'Test all collections (Default)'
|
168
|
-
|
169
|
-
c.action do |args, options|
|
170
|
-
if options.empty?
|
171
|
-
options = {"all" => true}
|
172
|
-
end
|
173
|
-
test_frontmatter(args, options)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
# Internal: eventually, validate that the *values* match expected types
|
178
|
-
#
|
179
|
-
# For example, if we expect the `date` key to be in yyyy-mm-dd format, validate
|
180
|
-
# that it's been entered in that format. If we expect authors to be an array,
|
181
|
-
# make sure we're getting an array.
|
182
|
-
def check_types(data, schema)
|
183
|
-
unless data.respond_to?('keys')
|
184
|
-
return false
|
185
|
-
end
|
186
|
-
for s in schema
|
187
|
-
key = s[0]
|
188
|
-
if s[1].class == Hash
|
189
|
-
type = s[1]['type']
|
190
|
-
else
|
191
|
-
type = s[1]
|
192
|
-
end
|
193
|
-
|
194
|
-
if type == "Array" and data[key].class == Array
|
195
|
-
return true
|
196
|
-
elsif type == "String" and data[key].class == String
|
197
|
-
return true
|
198
|
-
elsif type == "Date"
|
199
|
-
return true
|
200
|
-
else
|
201
|
-
puts " * Data is of the wrong type for key #{key}, expected #{type} but was #{data[key].class}\n\n"
|
202
|
-
return false
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
2
|
+
require 'jekyll'
|
3
|
+
|
4
|
+
require_relative 'jekyll_frontmatter_tests/jekyll_frontmatter_tests_config'
|
5
|
+
require_relative 'jekyll_frontmatter_tests/jekyll_frontmatter_tests_initializer'
|
6
|
+
require_relative 'jekyll_frontmatter_tests/jekyll_frontmatter_tests_tester'
|
7
|
+
require_relative 'jekyll_frontmatter_tests/jekyll_frontmatter_tests_loader'
|
8
|
+
require_relative 'jekyll_frontmatter_tests/jekyll_frontmatter_tests_processor'
|
9
|
+
require_relative 'jekyll_frontmatter_tests/jekyll_frontmatter_tests_validator'
|
10
|
+
require_relative 'jekyll_frontmatter_tests/jekyll_frontmatter_tests_helper'
|
11
|
+
|
12
|
+
module Boolean; end
|
13
|
+
class TrueClass; include Boolean; end
|
14
|
+
class FalseClass; include Boolean; end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
|
3
|
+
class FrontmatterTests < Jekyll::Command
|
4
|
+
class << self
|
5
|
+
def schema_config
|
6
|
+
config = Jekyll.configuration
|
7
|
+
unless config.key?('frontmatter_tests')
|
8
|
+
config['frontmatter_tests'] = { 'path' => File.join('deploy', 'tests', 'schema') }
|
9
|
+
end
|
10
|
+
config['frontmatter_tests']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class FrontmatterTests < Jekyll::Command
|
5
|
+
class << self
|
6
|
+
def one_of?(data, schema)
|
7
|
+
if schema.instance_of?(Array) && data.instance_of?(Array)
|
8
|
+
(schema & data).count == data.count
|
9
|
+
elsif schema.include? '.yml'
|
10
|
+
schema_list = YAML.load_file(File.join(Dir.pwd, 'tests', 'schema', schema))
|
11
|
+
(schema_list & data).count == data.count
|
12
|
+
elsif schema.instance_of?(String) && data.instance_of?(Array)
|
13
|
+
false
|
14
|
+
else
|
15
|
+
schema == data
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def required?(key, schema)
|
20
|
+
if schema['config']
|
21
|
+
!schema['config']['optional'].include? key
|
22
|
+
else
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'yaml'
|
3
|
+
require 'jekyll'
|
4
|
+
|
5
|
+
class FrontmatterTests < Jekyll::Command
|
6
|
+
class << self
|
7
|
+
# Internal: fired when `jekyll test` is run.
|
8
|
+
#
|
9
|
+
# When `jekyll test` runs, `test_frontmatter` is fired with options and args
|
10
|
+
# passed from the command line.
|
11
|
+
def init_with_program(prog)
|
12
|
+
prog.command(:test) do |c|
|
13
|
+
c.syntax 'test [options]'
|
14
|
+
c.description 'Test your site for frontmatter.'
|
15
|
+
|
16
|
+
c.option 'posts', '-p', 'Target only posts'
|
17
|
+
c.option 'collections', '-c [COLLECTION]', 'Target a specific collection'
|
18
|
+
c.option 'all', '-a', 'Test all collections (Default)'
|
19
|
+
|
20
|
+
c.action do |args, options|
|
21
|
+
options = { 'all' => true } if options.empty?
|
22
|
+
test_frontmatter(args, options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class FrontmatterTests < Jekyll::Command
|
5
|
+
class << self
|
6
|
+
# Public: Load a schema from file.
|
7
|
+
#
|
8
|
+
# file - a string containing a filename
|
9
|
+
#
|
10
|
+
# Used throughout to load a specific file. In the future the directories
|
11
|
+
# where these schema files are located could be loaded from _config.yml
|
12
|
+
#
|
13
|
+
# Returns a hash loaded from the YAML doc or exits 1 if no schema file
|
14
|
+
# exists.
|
15
|
+
def load_schema(file)
|
16
|
+
# binding.pry
|
17
|
+
schema = File.join(Dir.pwd, schema_config['path'], file)
|
18
|
+
# binding.pry
|
19
|
+
if File.exist?(schema)
|
20
|
+
YAML.load_file(schema)
|
21
|
+
else
|
22
|
+
puts "No schema for #{file}"
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class FrontmatterTests < Jekyll::Command
|
5
|
+
class << self
|
6
|
+
# Public: processes a collection against a schema
|
7
|
+
#
|
8
|
+
# schema - the hash-representation of a schema file
|
9
|
+
#
|
10
|
+
# Opens each file in the collection's expected directory and checks the
|
11
|
+
# file's frontmatter for the expected keys and the expected format of the
|
12
|
+
# values.
|
13
|
+
#
|
14
|
+
# NOTE - As it iterates through files, subdirectories will be ignored
|
15
|
+
#
|
16
|
+
# Returns true or false depending on the success of the check.
|
17
|
+
def process(schema)
|
18
|
+
dir = File.join(schema['config']['path'])
|
19
|
+
passfail = []
|
20
|
+
Dir.open(dir).each do |f|
|
21
|
+
next if File.directory?(File.join(dir, f))
|
22
|
+
file = File.open(File.join(dir, f))
|
23
|
+
next if schema['config']['ignore'].include?(f)
|
24
|
+
data = YAML.load_file(file)
|
25
|
+
|
26
|
+
passfail.push check_keys(data, schema.keys, f)
|
27
|
+
passfail.push check_types(data, schema, File.join(dir, f))
|
28
|
+
end
|
29
|
+
passfail.keep_if { |p| p == false }
|
30
|
+
if passfail.empty?
|
31
|
+
return true
|
32
|
+
else
|
33
|
+
puts "There were #{passfail.count} errors".red
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class FrontmatterTests < Jekyll::Command
|
5
|
+
class << self
|
6
|
+
# Public: Processes options passed throguh the command line, runs
|
7
|
+
# the appropriate tests.
|
8
|
+
#
|
9
|
+
# args - command line arguments (example: jekyll test [ARG])
|
10
|
+
# options - command line options (example: jekyll test -[option] [value])
|
11
|
+
#
|
12
|
+
# Depending on the flag passed (see `init_with_program`), runs the expected # test.
|
13
|
+
#
|
14
|
+
# Example: the following comamnd `jekyll test -p` will pass ``{'posts' =>
|
15
|
+
# true}` as `options`. This will cause `test_frontmatter` to
|
16
|
+
# compare all docs in _posts with the provided schema.
|
17
|
+
#
|
18
|
+
# The test runner pushes the result of each test into a `results` array and # exits `1` if any tests fail or `0` if all is well.
|
19
|
+
def test_frontmatter(_args, options)
|
20
|
+
puts 'starting tests'
|
21
|
+
if options['posts']
|
22
|
+
results = test_posts
|
23
|
+
elsif options['collections']
|
24
|
+
collections = options['collections'].split(',')
|
25
|
+
results = test_collections(collections)
|
26
|
+
else
|
27
|
+
results = test_everything
|
28
|
+
end
|
29
|
+
if results.find_index { |r| r == false }
|
30
|
+
puts 'The test exited with errors, see above.'
|
31
|
+
exit 1
|
32
|
+
else
|
33
|
+
puts 'Tests finished!'
|
34
|
+
exit 0
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Public: tests all documents that are "posts"
|
39
|
+
#
|
40
|
+
# Loads a schema called _posts.yml and processes all post documents against
|
41
|
+
# it.
|
42
|
+
def test_posts
|
43
|
+
puts 'testing posts'.green
|
44
|
+
yepnope = [].push process(load_schema('_posts.yml'))
|
45
|
+
puts 'Finished testing'.green
|
46
|
+
yepnope
|
47
|
+
end
|
48
|
+
|
49
|
+
# Public: Tests only specific collection documents
|
50
|
+
#
|
51
|
+
# collections - a comma separated string of collection names.
|
52
|
+
#
|
53
|
+
# `collections` is split into an array and each document is loaded and
|
54
|
+
# processed against its respective schema.
|
55
|
+
def test_collections(collections)
|
56
|
+
yepnope = []
|
57
|
+
for c in collections
|
58
|
+
puts "Testing #{c}".green
|
59
|
+
yepnope.push process(load_schema("_#{c}.yml"))
|
60
|
+
puts "Finished testing #{c}".green
|
61
|
+
end
|
62
|
+
yepnope
|
63
|
+
end
|
64
|
+
|
65
|
+
# Public: Tests all collections described by a schema file at
|
66
|
+
# `deploy/tests/schema`
|
67
|
+
def test_everything
|
68
|
+
schema = Dir.open(schema_config['path'])
|
69
|
+
yepnope = []
|
70
|
+
schema.each do |s|
|
71
|
+
next unless s.start_with?('_')
|
72
|
+
puts "Testing #{s}".green
|
73
|
+
yepnope.push process(load_schema(s))
|
74
|
+
puts "Finished testing #{s}".green
|
75
|
+
end
|
76
|
+
yepnope
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class FrontmatterTests < Jekyll::Command
|
5
|
+
class << self
|
6
|
+
# Public: checks a hash for expected keys
|
7
|
+
#
|
8
|
+
# target - the hash under test
|
9
|
+
# keys - an array of keys the data is expected to have, usually loaded from
|
10
|
+
# a schema file by loadschema()
|
11
|
+
# title - A string representing `data`'s name
|
12
|
+
def check_keys(target, keys, title)
|
13
|
+
keys -= ['config']
|
14
|
+
unless target.respond_to?('keys')
|
15
|
+
puts "The file #{title} is missing all frontmatter.".red
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
diff = keys - target.keys
|
19
|
+
if diff.empty?
|
20
|
+
return true
|
21
|
+
else
|
22
|
+
puts "\nThe file #{title} is missing the following keys:".red
|
23
|
+
for k in diff
|
24
|
+
puts " * #{k}".red
|
25
|
+
end
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Internal: eventually, validate that the *values* match expected types
|
31
|
+
#
|
32
|
+
# For example, if we expect the `date` key to be in yyyy-mm-dd format, validate
|
33
|
+
# that it's been entered in that format. If we expect authors to be an array,
|
34
|
+
# make sure we're getting an array.
|
35
|
+
def check_types(data, schema, file)
|
36
|
+
return false unless data.respond_to?('keys')
|
37
|
+
schema.each do |s|
|
38
|
+
key = s[0]
|
39
|
+
value = s[1]
|
40
|
+
type = if value.class == Hash
|
41
|
+
value['type']
|
42
|
+
else
|
43
|
+
value
|
44
|
+
end
|
45
|
+
next unless required?(key, schema)
|
46
|
+
if key == 'config'
|
47
|
+
next
|
48
|
+
elsif value.class == Hash
|
49
|
+
if value.keys.include? 'one_of'
|
50
|
+
if !one_of?(data[key], value['one_of'])
|
51
|
+
puts " * '#{data[key]}' was not in the list " \
|
52
|
+
"of expected values in #{file}.".red
|
53
|
+
puts " expected one of the following: #{s[1]['one_of']}\n".red
|
54
|
+
return false
|
55
|
+
else
|
56
|
+
next
|
57
|
+
end
|
58
|
+
else
|
59
|
+
next
|
60
|
+
end
|
61
|
+
elsif type == 'Array' && data[key].class == Array
|
62
|
+
next
|
63
|
+
elsif type == 'Boolean' && data[key].is_a?(Boolean)
|
64
|
+
next
|
65
|
+
elsif type == 'String' && data[key].class == String
|
66
|
+
next
|
67
|
+
elsif type == 'Date'
|
68
|
+
next
|
69
|
+
else
|
70
|
+
puts " * '#{key}' is not a valid key in #{file}. " \
|
71
|
+
"Expected #{type} but was #{data[key].class}\n\n"
|
72
|
+
return false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_frontmatter_tests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Boone
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -72,6 +72,90 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: capybara
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.11'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.11'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: chromedriver-helper
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rack-jekyll
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.5'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0.5'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rb-readline
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.5.3
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.5.3
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: selenium-webdriver
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '3.0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '3.0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: rubocop
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 0.47.1
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 0.47.1
|
75
159
|
description: Tests the frontmatter of posts and other collection documents against
|
76
160
|
a schema
|
77
161
|
email:
|
@@ -80,12 +164,21 @@ executables: []
|
|
80
164
|
extensions: []
|
81
165
|
extra_rdoc_files: []
|
82
166
|
files:
|
167
|
+
- Gemfile
|
168
|
+
- jekyll-frontmatter-tests.gemspec
|
83
169
|
- lib/jekyll_frontmatter_tests.rb
|
170
|
+
- lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_config.rb
|
171
|
+
- lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_helper.rb
|
172
|
+
- lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_initializer.rb
|
173
|
+
- lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_loader.rb
|
174
|
+
- lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_processor.rb
|
175
|
+
- lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_tester.rb
|
176
|
+
- lib/jekyll_frontmatter_tests/jekyll_frontmatter_tests_validator.rb
|
84
177
|
homepage: https://rubygems.org/gems/jekyll_frontmatter_tests
|
85
178
|
licenses:
|
86
179
|
- CC0
|
87
180
|
metadata: {}
|
88
|
-
post_install_message:
|
181
|
+
post_install_message: Happy testing!
|
89
182
|
rdoc_options: []
|
90
183
|
require_paths:
|
91
184
|
- lib
|
@@ -101,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
194
|
version: '0'
|
102
195
|
requirements: []
|
103
196
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
197
|
+
rubygems_version: 2.6.8
|
105
198
|
signing_key:
|
106
199
|
specification_version: 4
|
107
200
|
summary: Tests jekyll documents for proper frontmatter
|