ensure to_h doesnt cause things to explode

This commit is contained in:
Ben Balter 2017-04-07 16:51:37 -04:00
parent 7885669ee6
commit 0fd1bdcdfc
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
2 changed files with 15 additions and 3 deletions

View File

@ -2,8 +2,12 @@ module Jekyll
class SeoTag
class Drop < Jekyll::Drops::Drop
TITLE_SEPARATOR = " | ".freeze
include Jekyll::Filters
include Liquid::StandardFilters
INCLUDES = [Jekyll::Filters, Liquid::StandardFilters].freeze
INCLUDES.each do |klass|
include klass
klass.instance_methods.each { |method| private method }
end
def initialize(text, context)
@obj = {}
@ -190,7 +194,7 @@ module Jekyll
def format_string(string)
methods = %i[markdownify strip_html normalize_whitespace escape_once]
methods.each do |method|
string = public_send(method, string)
string = send(method, string)
end
string unless string.empty?

View File

@ -7,6 +7,14 @@ RSpec.describe Jekyll::SeoTag::Drop do
let(:text) { "" }
subject { described_class.new(text, context) }
# Drop includes liquid filters which expect arguments
# By default, in drops, `to_h` will call each public method with no arugments
# Here, that would cause the filters to explode. This test ensures that all
# public methods don't explode when called without arguments. Don't explode.
it "doesn't blow up on to_h" do
expect { subject.to_h }.to_not raise_error
end
it "returns the version" do
expect(subject.version).to eql(Jekyll::SeoTag::VERSION)
end