mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-28 03:01:03 -04:00
This removes the following warnings: - /lib/jekyll/configuration.rb:151: warning: instance variable @default_config_file not initialized - /lib/jekyll/converter.rb:12: warning: instance variable @highlighter_prefix not initialized - /lib/jekyll/converter.rb:24: warning: instance variable @highlighter_suffix not initialized - /lib/jekyll/converters/markdown.rb:9: warning: instance variable @setup not initialized - /lib/jekyll/converters/markdown/kramdown_parser.rb:60: warning: instance variable @highlighter not initialized - /lib/jekyll/frontmatter_defaults.rb:97: warning: shadowing outer local variable - path - /lib/jekyll/plugin.rb:66: warning: instance variable @safe not initialized - /lib/jekyll/regenerator.rb:147: warning: instance variable @disabled not initialized - /test/test_convertible.rb:40: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_filters.rb:154: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_new_command.rb:84: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_site.rb:234: warning: assigned but unused variable - site - /test/test_site.rb:240: warning: assigned but unused variable - site - /test/test_site.rb:522: warning: assigned but unused variable - source - /test/test_tags.rb:153: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:425: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:449: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:496: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:496: warning: instance variable @result not initialized - /test/test_tags.rb:511: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:773: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:773: warning: instance variable @result not initialized - /test/test_tags.rb:788: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_url.rb:66: warning: shadowing outer local variable - doc - /lib/jekyll/url.rb:119:in `escape_path': warning: URI.escape is obsolete
68 lines
2.1 KiB
Ruby
68 lines
2.1 KiB
Ruby
require 'helper'
|
|
require 'ostruct'
|
|
|
|
class TestConvertible < JekyllUnitTest
|
|
context "yaml front-matter" do
|
|
setup do
|
|
@convertible = OpenStruct.new(
|
|
"site" => Site.new(Jekyll.configuration(
|
|
"source" => File.expand_path('../fixtures', __FILE__)
|
|
))
|
|
)
|
|
@convertible.extend Jekyll::Convertible
|
|
@base = File.expand_path('../fixtures', __FILE__)
|
|
end
|
|
|
|
should "parse the front-matter correctly" do
|
|
ret = @convertible.read_yaml(@base, 'front_matter.erb')
|
|
assert_equal({'test' => 'good'}, ret)
|
|
end
|
|
|
|
should "not parse if the front-matter is not at the start of the file" do
|
|
ret = @convertible.read_yaml(@base, 'broken_front_matter1.erb')
|
|
assert_equal({}, ret)
|
|
end
|
|
|
|
should "not parse if there is syntax error in front-matter" do
|
|
name = 'broken_front_matter2.erb'
|
|
out = capture_stderr do
|
|
ret = @convertible.read_yaml(@base, name)
|
|
assert_equal({}, ret)
|
|
end
|
|
assert_match(/YAML Exception|syntax error|Error reading file/, out)
|
|
assert_match(/#{File.join(@base, name)}/, out)
|
|
end
|
|
|
|
should "not allow ruby objects in yaml" do
|
|
out = capture_stderr do
|
|
@convertible.read_yaml(@base, 'exploit_front_matter.erb')
|
|
end
|
|
refute_match(/undefined class\/module DoesNotExist/, out)
|
|
end
|
|
|
|
should "not parse if there is encoding error in file" do
|
|
name = 'broken_front_matter3.erb'
|
|
out = capture_stderr do
|
|
ret = @convertible.read_yaml(@base, name, :encoding => 'utf-8')
|
|
assert_equal({}, ret)
|
|
end
|
|
assert_match(/invalid byte sequence in UTF-8/, out)
|
|
assert_match(/#{File.join(@base, name)}/, out)
|
|
end
|
|
|
|
should "parse the front-matter but show an error if permalink is empty" do
|
|
name = 'empty_permalink.erb'
|
|
assert_raises(Errors::InvalidPermalinkError) do
|
|
@convertible.read_yaml(@base, name)
|
|
end
|
|
end
|
|
|
|
should "parse the front-matter correctly whitout permalink" do
|
|
out = capture_stderr do
|
|
@convertible.read_yaml(@base, 'front_matter.erb')
|
|
end
|
|
refute_match(/Invalid permalink/, out)
|
|
end
|
|
end
|
|
end
|