2016-09-08 15:33:03 +00:00
|
|
|
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
|
|
|
require "jekyll"
|
|
|
|
require "jekyll-seo-tag"
|
2017-04-04 13:50:57 +00:00
|
|
|
require "html-proofer"
|
2017-04-11 22:49:57 +00:00
|
|
|
require "uri"
|
|
|
|
require "net/http"
|
2015-10-31 18:05:19 +00:00
|
|
|
|
2016-09-08 15:33:03 +00:00
|
|
|
ENV["JEKYLL_LOG_LEVEL"] = "error"
|
2015-10-31 18:05:19 +00:00
|
|
|
|
2017-04-11 22:49:57 +00:00
|
|
|
RSpec::Matchers.define :be_valid_json_ld do |_expected|
|
|
|
|
match do |actual|
|
|
|
|
validate_json_ld(actual)["errors"].empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
failure_message do |actual|
|
|
|
|
validate_json_ld(actual)["errors"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_json_ld(html)
|
|
|
|
params = { "html" => html }
|
|
|
|
url = URI.parse("https://search.google.com/structured-data/testing-tool/validate")
|
|
|
|
response = Net::HTTP.post_form(url, params)
|
|
|
|
JSON.parse(response.body.split("\n")[1])
|
|
|
|
rescue
|
|
|
|
puts "Unable to validate JSON"
|
|
|
|
{ "errors" => [] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-31 18:05:19 +00:00
|
|
|
def dest_dir
|
2016-09-08 15:33:03 +00:00
|
|
|
File.expand_path("../tmp/dest", File.dirname(__FILE__))
|
2015-10-31 18:05:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def source_dir
|
2016-09-08 15:33:03 +00:00
|
|
|
File.expand_path("./fixtures", File.dirname(__FILE__))
|
2015-10-31 18:05:19 +00:00
|
|
|
end
|
2015-10-25 21:21:46 +00:00
|
|
|
|
|
|
|
CONFIG_DEFAULTS = {
|
2016-09-08 15:33:03 +00:00
|
|
|
"source" => source_dir,
|
|
|
|
"destination" => dest_dir,
|
2017-01-30 01:53:19 +00:00
|
|
|
"gems" => ["jekyll-seo-tag"],
|
2016-02-09 23:48:24 +00:00
|
|
|
}.freeze
|
2015-10-25 21:21:46 +00:00
|
|
|
|
2016-02-20 20:49:55 +00:00
|
|
|
def make_page(options = {})
|
2016-09-08 15:33:03 +00:00
|
|
|
page = Jekyll::Page.new site, CONFIG_DEFAULTS["source"], "", "page.md"
|
2015-10-25 21:21:46 +00:00
|
|
|
page.data = options
|
|
|
|
page
|
|
|
|
end
|
|
|
|
|
2016-02-20 20:49:55 +00:00
|
|
|
def make_post(options = {})
|
2016-10-06 20:47:49 +00:00
|
|
|
filename = File.expand_path("_posts/2015-01-01-post.md", CONFIG_DEFAULTS["source"])
|
2016-09-08 15:33:03 +00:00
|
|
|
config = { :site => site, :collection => site.collections["posts"] }
|
2016-02-03 04:02:08 +00:00
|
|
|
page = Jekyll::Document.new filename, config
|
|
|
|
page.merge_data!(options)
|
2015-10-25 21:21:46 +00:00
|
|
|
page
|
|
|
|
end
|
|
|
|
|
2016-02-20 20:49:55 +00:00
|
|
|
def make_site(options = {})
|
2015-10-25 21:21:46 +00:00
|
|
|
config = Jekyll.configuration CONFIG_DEFAULTS.merge(options)
|
|
|
|
Jekyll::Site.new(config)
|
|
|
|
end
|
|
|
|
|
2016-05-27 22:04:56 +00:00
|
|
|
def make_context(registers = {}, environments = {})
|
2016-08-11 15:35:31 +00:00
|
|
|
Liquid::Context.new(environments, {}, { :site => site, :page => page }.merge(registers))
|
2015-10-25 21:21:46 +00:00
|
|
|
end
|