Skip to content

Commit

Permalink
Add lint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Aug 9, 2016
1 parent b961c95 commit 0bd0888
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source "https://rubygems.org"

gem "github-pages"
gem "rake"
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ GEM
sawyer (~> 0.7.0, >= 0.5.3)
pkg-config (1.1.7)
public_suffix (1.5.3)
rake (11.2.2)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
Expand All @@ -125,6 +126,7 @@ PLATFORMS

DEPENDENCIES
github-pages
rake

BUNDLED WITH
1.12.5
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "rake/testtask"
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList["test/*_test.rb"]
t.warning = false
t.verbose = false
end

task :default => :test
4 changes: 3 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ baseurl: "/open-source-handbook"

exclude:
- docs
- Gemfile*
- Rakefile
- README.md
- script
- Gemfile*
- test

collections:
content:
Expand Down
10 changes: 10 additions & 0 deletions _data/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Each piece of content has YAML front matter with these properties:

title:
required: true

next:
type: String

previous:
type: String
29 changes: 29 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "minitest/autorun"
require "jekyll"

module Helper
class << self
attr_accessor :config, :site
end
end

def source
File.expand_path('../', File.dirname(__FILE__))
end

def config
Helper.config ||= Jekyll.configuration("source" => source)
end

def content
site.collections['content'].docs.map { |doc| doc.to_liquid }
end

def site
Helper.site ||= begin
site = Jekyll::Site.new(config)
site.reset
site.read
site
end
end
36 changes: 36 additions & 0 deletions test/lint_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require_relative "./helper"

describe "lint test" do

content.each do |page|

describe page["path"] do

describe "frontmatter" do

before do
# Load raw metadata to skip defaults
@data = SafeYAML.load_file(page["path"])
end

it "contains supported fields" do
extra_fields = @data.keys - site.data["fields"].keys
assert extra_fields.empty?, "Unexpected metadata in #{page["path"]}: #{extra_fields.inspect}"
end

site.data["fields"].each do |name, attrs|
it "#{name} is required" do
assert @data.key?(name), "#{name} is required"
end if attrs["required"]

it "#{name} should be of type #{attrs["type"]}" do
assert_kind_of Kernel.const_get(attrs["type"]), @data[name] if @data[name]
end if attrs["type"]

it "#{name} has valid attributes" do
end
end
end
end
end
end

0 comments on commit 0bd0888

Please sign in to comment.