From e31c9e7ca7a5a752626104c11ff6107ebfb17538 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Wed, 6 Sep 2017 12:33:19 -0400 Subject: [PATCH] add unit tests for Jekyll::SeoTag --- lib/jekyll-seo-tag.rb | 2 +- spec/jekyll_seo_tag_spec.rb | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 spec/jekyll_seo_tag_spec.rb diff --git a/lib/jekyll-seo-tag.rb b/lib/jekyll-seo-tag.rb index d3a9520..663a491 100644 --- a/lib/jekyll-seo-tag.rb +++ b/lib/jekyll-seo-tag.rb @@ -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, diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb new file mode 100644 index 0000000..087eea8 --- /dev/null +++ b/spec/jekyll_seo_tag_spec.rb @@ -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 = "" + expect(rendered).to match(expected) + end +end