add unit tests for Jekyll::SeoTag

This commit is contained in:
Ben Balter 2017-09-06 12:33:19 -04:00
parent 3805012e9a
commit e31c9e7ca7
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
2 changed files with 51 additions and 1 deletions

View File

@ -45,7 +45,7 @@ module Jekyll
def payload
# site_payload is an instance of UnifiedPayloadDrop. See https://git.io/v5ajm
@payload ||= context.registers[:site].site_payload.merge({
Jekyll::Utils.deep_merge_hashes(context.registers[:site].site_payload, {
"page" => context.registers[:page],
"paginator" => context["paginator"],
"seo_tag" => drop,

View File

@ -0,0 +1,50 @@
RSpec.describe Jekyll::SeoTag do
let(:config) { { "title" => "site title" } }
let(:page_meta) { {} }
let(:page) { make_page(page_meta) }
let(:site) { make_site(config) }
let(:render_context) { make_context(:page => page, :site => site) }
let(:text) { "" }
let(:tag_name) { "github_edit_link" }
let(:tokenizer) { Liquid::Tokenizer.new("") }
let(:parse_context) { Liquid::ParseContext.new }
let(:rendered) { subject.render(render_context) }
let(:payload) { subject.send(:payload) }
subject do
tag = described_class.parse(tag_name, text, tokenizer, parse_context)
tag.instance_variable_set("@context", render_context)
tag
end
before do
Jekyll.logger.log_level = :error
end
it "returns the template" do
expect(described_class.template).to be_a(Liquid::Template)
end
context "payload" do
it "contains the drop" do
expect(payload["seo_tag"]).to be_a(Jekyll::SeoTag::Drop)
end
it "contains the Jekyll drop" do
expect(payload["jekyll"]).to be_a(Jekyll::Drops::JekyllDrop)
end
it "contains the page" do
expect(payload["page"]).to be_a(Jekyll::Page)
end
it "contains the site" do
expect(payload["site"]).to be_a(Jekyll::Drops::SiteDrop)
end
end
it "renders" do
expected = "<!-- Begin Jekyll SEO tag v#{described_class::VERSION} -->"
expect(rendered).to match(expected)
end
end