Merge pull request #4902 from brint/rubocop_cleanup_tests

Merge pull request 4902
This commit is contained in:
jekyllbot 2016-05-17 07:59:59 -07:00
commit 9e92061eb3
22 changed files with 287 additions and 278 deletions

View File

@ -70,34 +70,13 @@ AllCops:
- features/step_definitions.rb - features/step_definitions.rb
- features/support/formatter.rb - features/support/formatter.rb
- features/support/helpers.rb - features/support/helpers.rb
- test/helper.rb
- test/simplecov_custom_profile.rb
- test/test_ansi.rb
- test/test_cleaner.rb
- test/test_coffeescript.rb
- test/test_collections.rb
- test/test_command.rb
- test/test_commands_serve.rb
- test/test_configuration.rb - test/test_configuration.rb
- test/test_convertible.rb
- test/test_doctor_command.rb
- test/test_document.rb - test/test_document.rb
- test/test_entry_filter.rb - test/test_entry_filter.rb
- test/test_excerpt.rb
- test/test_filters.rb - test/test_filters.rb
- test/test_front_matter_defaults.rb
- test/test_generated_site.rb
- test/test_kramdown.rb - test/test_kramdown.rb
- test/test_layout_reader.rb
- test/test_liquid_extensions.rb
- test/test_liquid_renderer.rb - test/test_liquid_renderer.rb
- test/test_log_adapter.rb
- test/test_new_command.rb
- test/test_page.rb - test/test_page.rb
- test/test_path_sanitization.rb
- test/test_plugin_manager.rb
- test/test_rdiscount.rb
- test/test_redcarpet.rb
- test/test_regenerator.rb - test/test_regenerator.rb
- test/test_related_posts.rb - test/test_related_posts.rb
- test/test_sass.rb - test/test_sass.rb

View File

@ -6,7 +6,7 @@ $stdout.puts "# -------------------------------------------------------------"
$VERBOSE = nil $VERBOSE = nil
def jruby? def jruby?
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
end end
if ENV["CI"] if ENV["CI"]
@ -22,23 +22,23 @@ else
end end
require "nokogiri" require "nokogiri"
require 'rubygems' require "rubygems"
require 'ostruct' require "ostruct"
require 'minitest/autorun' require "minitest/autorun"
require 'minitest/reporters' require "minitest/reporters"
require 'minitest/profile' require "minitest/profile"
require 'rspec/mocks' require "rspec/mocks"
require 'jekyll' require "jekyll"
Jekyll.logger = Logger.new(StringIO.new) Jekyll.logger = Logger.new(StringIO.new)
unless jruby? unless jruby?
require 'rdiscount' require "rdiscount"
require 'redcarpet' require "redcarpet"
end end
require 'kramdown' require "kramdown"
require 'shoulda' require "shoulda"
include Jekyll include Jekyll
@ -51,16 +51,12 @@ Minitest::Reporters.use! [
module Minitest::Assertions module Minitest::Assertions
def assert_exist(filename, msg = nil) def assert_exist(filename, msg = nil)
msg = message(msg) { msg = message(msg) { "Expected '#{filename}' to exist" }
"Expected '#{filename}' to exist"
}
assert File.exist?(filename), msg assert File.exist?(filename), msg
end end
def refute_exist(filename, msg = nil) def refute_exist(filename, msg = nil)
msg = message(msg) { msg = message(msg) { "Expected '#{filename}' not to exist" }
"Expected '#{filename}' not to exist"
}
refute File.exist?(filename), msg refute File.exist?(filename), msg
end end
end end
@ -69,8 +65,8 @@ class JekyllUnitTest < Minitest::Test
include ::RSpec::Mocks::ExampleMethods include ::RSpec::Mocks::ExampleMethods
def mocks_expect(*args) def mocks_expect(*args)
RSpec::Mocks::ExampleMethods::ExpectHost.instance_method(:expect).\ RSpec::Mocks::ExampleMethods::ExpectHost.instance_method(:expect)\
bind(self).call(*args) .bind(self).call(*args)
end end
def before_setup def before_setup
@ -105,16 +101,16 @@ class JekyllUnitTest < Minitest::Test
end end
def dest_dir(*subdirs) def dest_dir(*subdirs)
test_dir('dest', *subdirs) test_dir("dest", *subdirs)
end end
def source_dir(*subdirs) def source_dir(*subdirs)
test_dir('source', *subdirs) test_dir("source", *subdirs)
end end
def clear_dest def clear_dest
FileUtils.rm_rf(dest_dir) FileUtils.rm_rf(dest_dir)
FileUtils.rm_rf(source_dir('.jekyll-metadata')) FileUtils.rm_rf(source_dir(".jekyll-metadata"))
end end
def test_dir(*subdirs) def test_dir(*subdirs)
@ -124,7 +120,7 @@ class JekyllUnitTest < Minitest::Test
def directory_with_contents(path) def directory_with_contents(path)
FileUtils.rm_rf(path) FileUtils.rm_rf(path)
FileUtils.mkdir(path) FileUtils.mkdir(path)
File.open("#{path}/index.html", "w"){ |f| f.write("I was previously generated.") } File.open("#{path}/index.html", "w") { |f| f.write("I was previously generated.") }
end end
def with_env(key, value) def with_env(key, value)

View File

@ -1,10 +1,10 @@
require 'simplecov' require "simplecov"
SimpleCov.profiles.define 'gem' do SimpleCov.profiles.define "gem" do
add_filter '/test/' add_filter "/test/"
add_filter '/features/' add_filter "/features/"
add_filter '/autotest/' add_filter "/autotest/"
add_group 'Binaries', '/bin/' add_group "Binaries", "/bin/"
add_group 'Libraries', '/lib/' add_group "Libraries", "/lib/"
end end

View File

@ -6,7 +6,7 @@ class TestAnsi < JekyllUnitTest
@subject = Jekyll::Utils::Ansi @subject = Jekyll::Utils::Ansi
end end
Jekyll::Utils::Ansi::COLORS.each do |color, val| Jekyll::Utils::Ansi::COLORS.each do |color, _val|
should "respond_to? #{color}" do should "respond_to? #{color}" do
assert @subject.respond_to?(color) assert @subject.respond_to?(color)
end end

View File

@ -1,73 +1,73 @@
require 'helper' require "helper"
class TestCleaner < JekyllUnitTest class TestCleaner < JekyllUnitTest
context "directory in keep_files" do context "directory in keep_files" do
setup do setup do
clear_dest clear_dest
FileUtils.mkdir_p(dest_dir('to_keep/child_dir')) FileUtils.mkdir_p(dest_dir("to_keep/child_dir"))
FileUtils.touch(File.join(dest_dir('to_keep'), 'index.html')) FileUtils.touch(File.join(dest_dir("to_keep"), "index.html"))
FileUtils.touch(File.join(dest_dir('to_keep/child_dir'), 'index.html')) FileUtils.touch(File.join(dest_dir("to_keep/child_dir"), "index.html"))
@site = fixture_site @site = fixture_site
@site.keep_files = ['to_keep/child_dir'] @site.keep_files = ["to_keep/child_dir"]
@cleaner = Cleaner.new(@site) @cleaner = Cleaner.new(@site)
@cleaner.cleanup! @cleaner.cleanup!
end end
teardown do teardown do
FileUtils.rm_rf(dest_dir('to_keep')) FileUtils.rm_rf(dest_dir("to_keep"))
end end
should "keep the parent directory" do should "keep the parent directory" do
assert_exist dest_dir('to_keep') assert_exist dest_dir("to_keep")
end end
should "keep the child directory" do should "keep the child directory" do
assert_exist dest_dir('to_keep', 'child_dir') assert_exist dest_dir("to_keep", "child_dir")
end end
should "keep the file in the directory in keep_files" do should "keep the file in the directory in keep_files" do
assert_exist dest_dir('to_keep', 'child_dir', 'index.html') assert_exist dest_dir("to_keep", "child_dir", "index.html")
end end
should "delete the file in the directory not in keep_files" do should "delete the file in the directory not in keep_files" do
refute_exist dest_dir('to_keep', 'index.html') refute_exist dest_dir("to_keep", "index.html")
end end
end end
context "not-nested directory in keep_files and similary named directory not in keep_files" do context "non-nested directory & similarly-named directory *not* in keep_files" do
setup do setup do
clear_dest clear_dest
FileUtils.mkdir_p(dest_dir('.git/child_dir')) FileUtils.mkdir_p(dest_dir(".git/child_dir"))
FileUtils.mkdir_p(dest_dir('username.github.io')) FileUtils.mkdir_p(dest_dir("username.github.io"))
FileUtils.touch(File.join(dest_dir('.git'), 'index.html')) FileUtils.touch(File.join(dest_dir(".git"), "index.html"))
FileUtils.touch(File.join(dest_dir('username.github.io'), 'index.html')) FileUtils.touch(File.join(dest_dir("username.github.io"), "index.html"))
@site = fixture_site @site = fixture_site
@site.keep_files = ['.git'] @site.keep_files = [".git"]
@cleaner = Cleaner.new(@site) @cleaner = Cleaner.new(@site)
@cleaner.cleanup! @cleaner.cleanup!
end end
teardown do teardown do
FileUtils.rm_rf(dest_dir('.git')) FileUtils.rm_rf(dest_dir(".git"))
FileUtils.rm_rf(dest_dir('username.github.io')) FileUtils.rm_rf(dest_dir("username.github.io"))
end end
should "keep the file in the directory in keep_files" do should "keep the file in the directory in keep_files" do
assert File.exist?(File.join(dest_dir('.git'), 'index.html')) assert File.exist?(File.join(dest_dir(".git"), "index.html"))
end end
should "delete the file in the directory not in keep_files" do should "delete the file in the directory not in keep_files" do
assert !File.exist?(File.join(dest_dir('username.github.io'), 'index.html')) assert !File.exist?(File.join(dest_dir("username.github.io"), "index.html"))
end end
should "delete the directory not in keep_files" do should "delete the directory not in keep_files" do
assert !File.exist?(dest_dir('username.github.io')) assert !File.exist?(dest_dir("username.github.io"))
end end
end end
@ -75,8 +75,8 @@ class TestCleaner < JekyllUnitTest
setup do setup do
clear_dest clear_dest
FileUtils.mkdir_p(source_dir('no_files_inside', 'child_dir')) FileUtils.mkdir_p(source_dir("no_files_inside", "child_dir"))
FileUtils.touch(source_dir('no_files_inside', 'child_dir', 'index.html')) FileUtils.touch(source_dir("no_files_inside", "child_dir", "index.html"))
@site = fixture_site @site = fixture_site
@site.process @site.process
@ -86,20 +86,20 @@ class TestCleaner < JekyllUnitTest
end end
teardown do teardown do
FileUtils.rm_rf(source_dir('no_files_inside')) FileUtils.rm_rf(source_dir("no_files_inside"))
FileUtils.rm_rf(dest_dir('no_files_inside')) FileUtils.rm_rf(dest_dir("no_files_inside"))
end end
should "keep the parent directory" do should "keep the parent directory" do
assert_exist dest_dir('no_files_inside') assert_exist dest_dir("no_files_inside")
end end
should "keep the child directory" do should "keep the child directory" do
assert_exist dest_dir('no_files_inside', 'child_dir') assert_exist dest_dir("no_files_inside", "child_dir")
end end
should "keep the file" do should "keep the file" do
assert_exist source_dir('no_files_inside', 'child_dir', 'index.html') assert_exist source_dir("no_files_inside", "child_dir", "index.html")
end end
end end
end end

View File

@ -1,9 +1,9 @@
require 'helper' require "helper"
class TestCoffeeScript < JekyllUnitTest class TestCoffeeScript < JekyllUnitTest
context "converting CoffeeScript" do context "converting CoffeeScript" do
setup do setup do
External.require_with_graceful_fail('jekyll-coffeescript') External.require_with_graceful_fail("jekyll-coffeescript")
@site = fixture_site @site = fixture_site
@site.process @site.process
@test_coffeescript_file = dest_dir("js/coffeescript.js") @test_coffeescript_file = dest_dir("js/coffeescript.js")
@ -37,7 +37,7 @@ JS
end end
should "write a JS file in place" do should "write a JS file in place" do
assert_exist @test_coffeescript_file, "Can't find the converted CoffeeScript file in the dest_dir." assert_exist @test_coffeescript_file
end end
should "produce JS" do should "produce JS" do

View File

@ -1,4 +1,4 @@
require 'helper' require "helper"
class TestCollections < JekyllUnitTest class TestCollections < JekyllUnitTest
context "an evil collection" do context "an evil collection" do
@ -50,7 +50,7 @@ class TestCollections < JekyllUnitTest
end end
should "have a docs attribute" do should "have a docs attribute" do
assert_equal @collection.to_liquid["docs"], Array.new assert_equal @collection.to_liquid["docs"], []
end end
should "have a directory attribute" do should "have a directory attribute" do
@ -68,9 +68,9 @@ class TestCollections < JekyllUnitTest
should "know whether it should be written or not" do should "know whether it should be written or not" do
assert_equal @collection.write?, false assert_equal @collection.write?, false
@collection.metadata['output'] = true @collection.metadata["output"] = true
assert_equal @collection.write?, true assert_equal @collection.write?, true
@collection.metadata.delete 'output' @collection.metadata.delete "output"
end end
end end
@ -80,8 +80,8 @@ class TestCollections < JekyllUnitTest
@site.process @site.process
end end
should "contain only the defaul collections" do should "contain only the default collections" do
refute_equal Hash.new, @site.collections refute_equal @site.collections, {}
refute_nil @site.collections refute_nil @site.collections
end end
end end
@ -113,7 +113,7 @@ class TestCollections < JekyllUnitTest
@collection = @site.collections["methods"] @collection = @site.collections["methods"]
end end
should "create a Hash on Site with the label mapped to the instance of the Collection" do should "create a Hash mapping label to Collection instance" do
assert @site.collections.is_a?(Hash) assert @site.collections.is_a?(Hash)
refute_nil @site.collections["methods"] refute_nil @site.collections["methods"]
assert @site.collections["methods"].is_a? Jekyll::Collection assert @site.collections["methods"].is_a? Jekyll::Collection
@ -123,7 +123,7 @@ class TestCollections < JekyllUnitTest
assert @site.collections["methods"].docs.is_a? Array assert @site.collections["methods"].docs.is_a? Array
@site.collections["methods"].docs.each do |doc| @site.collections["methods"].docs.each do |doc|
assert doc.is_a? Jekyll::Document assert doc.is_a? Jekyll::Document
assert_includes %w[ assert_includes %w(
_methods/configuration.md _methods/configuration.md
_methods/sanitized_path.md _methods/sanitized_path.md
_methods/collection/entries _methods/collection/entries
@ -132,11 +132,11 @@ class TestCollections < JekyllUnitTest
_methods/um_hi.md _methods/um_hi.md
_methods/escape-+\ #%20[].md _methods/escape-+\ #%20[].md
_methods/yaml_with_dots.md _methods/yaml_with_dots.md
], doc.relative_path ), doc.relative_path
end end
end end
should "not include files which start with an underscore in the base collection directory" do should "not include files from base dir which start with an underscore" do
refute_includes @collection.filtered_entries, "_do_not_read_me.md" refute_includes @collection.filtered_entries, "_do_not_read_me.md"
end end
@ -146,7 +146,8 @@ class TestCollections < JekyllUnitTest
should "not include the underscored files in the list of docs" do should "not include the underscored files in the list of docs" do
refute_includes @collection.docs.map(&:relative_path), "_methods/_do_not_read_me.md" refute_includes @collection.docs.map(&:relative_path), "_methods/_do_not_read_me.md"
refute_includes @collection.docs.map(&:relative_path), "_methods/site/_dont_include_me_either.md" refute_includes @collection.docs.map(&:relative_path),
"_methods/site/_dont_include_me_either.md"
end end
end end
@ -165,7 +166,7 @@ class TestCollections < JekyllUnitTest
end end
should "extract the configuration collection information as metadata" do should "extract the configuration collection information as metadata" do
assert_equal @collection.metadata, {"foo" => "bar", "baz" => "whoo"} assert_equal @collection.metadata, { "foo" => "bar", "baz" => "whoo" }
end end
end end
@ -184,7 +185,7 @@ class TestCollections < JekyllUnitTest
refute_includes @collection.filtered_entries, "/um_hi.md" refute_includes @collection.filtered_entries, "/um_hi.md"
end end
should "include the symlinked file in the list of docs as it resolves to inside site.source" do should "include the symlinked file from site.source in the list of docs" do
assert_includes @collection.docs.map(&:relative_path), "_methods/um_hi.md" assert_includes @collection.docs.map(&:relative_path), "_methods/um_hi.md"
end end
end end
@ -215,5 +216,4 @@ class TestCollections < JekyllUnitTest
assert @collection.docs.any? { |d| d.path.include?("all.dots") } assert @collection.docs.any? { |d| d.path.include?("all.dots") }
end end
end end
end end

View File

@ -1,4 +1,4 @@
require 'helper' require "helper"
class TestCommand < JekyllUnitTest class TestCommand < JekyllUnitTest
context "when calling .add_build_options" do context "when calling .add_build_options" do

View File

@ -11,7 +11,8 @@ class TestCommandsServe < JekyllUnitTest
context "with a program" do context "with a program" do
setup do setup do
@merc, @cmd = nil, Jekyll::Commands::Serve @merc = nil
@cmd = Jekyll::Commands::Serve
Mercenary.program(:jekyll) do |p| Mercenary.program(:jekyll) do |p|
@merc = @cmd.init_with_program( @merc = @cmd.init_with_program(
p p
@ -63,7 +64,7 @@ class TestCommandsServe < JekyllUnitTest
should "use user port" do should "use user port" do
# WHAT?!?!1 Over 9000? That's impossible. # WHAT?!?!1 Over 9000? That's impossible.
assert_equal 9001, custom_opts( { "port" => 9001 })[ assert_equal 9001, custom_opts({ "port" => 9001 })[
:Port :Port
] ]
end end
@ -104,10 +105,10 @@ class TestCommandsServe < JekyllUnitTest
allow(File).to receive(:read).and_return("foo") allow(File).to receive(:read).and_return("foo")
result = custom_opts({ result = custom_opts({
"ssl_cert" => "foo", "ssl_cert" => "foo",
"source" => "bar", "source" => "bar",
"enable_ssl" => true, "enable_ssl" => true,
"ssl_key" => "bar" "ssl_key" => "bar"
}) })
assert result[:SSLEnable] assert result[:SSLEnable]

View File

@ -1,30 +1,30 @@
require 'helper' require "helper"
require 'ostruct' require "ostruct"
class TestConvertible < JekyllUnitTest class TestConvertible < JekyllUnitTest
context "yaml front-matter" do context "yaml front-matter" do
setup do setup do
@convertible = OpenStruct.new( @convertible = OpenStruct.new(
"site" => Site.new(Jekyll.configuration( "site" => Site.new(Jekyll.configuration(
"source" => File.expand_path('../fixtures', __FILE__) "source" => File.expand_path("../fixtures", __FILE__)
)) ))
) )
@convertible.extend Jekyll::Convertible @convertible.extend Jekyll::Convertible
@base = File.expand_path('../fixtures', __FILE__) @base = File.expand_path("../fixtures", __FILE__)
end end
should "parse the front-matter correctly" do should "parse the front-matter correctly" do
ret = @convertible.read_yaml(@base, 'front_matter.erb') ret = @convertible.read_yaml(@base, "front_matter.erb")
assert_equal({'test' => 'good'}, ret) assert_equal({ "test" => "good" }, ret)
end end
should "not parse if the front-matter is not at the start of the file" do 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') ret = @convertible.read_yaml(@base, "broken_front_matter1.erb")
assert_equal({}, ret) assert_equal({}, ret)
end end
should "not parse if there is syntax error in front-matter" do should "not parse if there is syntax error in front-matter" do
name = 'broken_front_matter2.erb' name = "broken_front_matter2.erb"
out = capture_stderr do out = capture_stderr do
ret = @convertible.read_yaml(@base, name) ret = @convertible.read_yaml(@base, name)
assert_equal({}, ret) assert_equal({}, ret)
@ -35,15 +35,15 @@ class TestConvertible < JekyllUnitTest
should "not allow ruby objects in yaml" do should "not allow ruby objects in yaml" do
out = capture_stderr do out = capture_stderr do
@convertible.read_yaml(@base, 'exploit_front_matter.erb') @convertible.read_yaml(@base, "exploit_front_matter.erb")
end end
refute_match(/undefined class\/module DoesNotExist/, out) refute_match(%r!undefined class\/module DoesNotExist!, out)
end end
should "not parse if there is encoding error in file" do should "not parse if there is encoding error in file" do
name = 'broken_front_matter3.erb' name = "broken_front_matter3.erb"
out = capture_stderr do out = capture_stderr do
ret = @convertible.read_yaml(@base, name, :encoding => 'utf-8') ret = @convertible.read_yaml(@base, name, :encoding => "utf-8")
assert_equal({}, ret) assert_equal({}, ret)
end end
assert_match(/invalid byte sequence in UTF-8/, out) assert_match(/invalid byte sequence in UTF-8/, out)
@ -51,7 +51,7 @@ class TestConvertible < JekyllUnitTest
end end
should "parse the front-matter but show an error if permalink is empty" do should "parse the front-matter but show an error if permalink is empty" do
name = 'empty_permalink.erb' name = "empty_permalink.erb"
assert_raises(Errors::InvalidPermalinkError) do assert_raises(Errors::InvalidPermalinkError) do
@convertible.read_yaml(@base, name) @convertible.read_yaml(@base, name)
end end
@ -59,7 +59,7 @@ class TestConvertible < JekyllUnitTest
should "parse the front-matter correctly whitout permalink" do should "parse the front-matter correctly whitout permalink" do
out = capture_stderr do out = capture_stderr do
@convertible.read_yaml(@base, 'front_matter.erb') @convertible.read_yaml(@base, "front_matter.erb")
end end
refute_match(/Invalid permalink/, out) refute_match(/Invalid permalink/, out)
end end

View File

@ -1,36 +1,38 @@
require 'helper' require "helper"
require 'jekyll/commands/doctor' require "jekyll/commands/doctor"
class TestDoctorCommand < JekyllUnitTest class TestDoctorCommand < JekyllUnitTest
context 'urls only differ by case' do context "urls only differ by case" do
setup do setup do
clear_dest clear_dest
end end
should 'return success on a valid site/page' do should "return success on a valid site/page" do
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration({
"source" => File.join(source_dir, '/_urls_differ_by_case_valid'), "source" => File.join(source_dir, "/_urls_differ_by_case_valid"),
"destination" => dest_dir "destination" => dest_dir
})) }))
@site.process @site.process
output = capture_stderr do output = capture_stderr do
ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site) ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site)
assert_equal false, ret assert_equal false, ret
end end
assert_equal "", output assert_equal "", output
end end
should 'return warning for pages only differing by case' do should "return warning for pages only differing by case" do
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration({
"source" => File.join(source_dir, '/_urls_differ_by_case_invalid'), "source" => File.join(source_dir, "/_urls_differ_by_case_invalid"),
"destination" => dest_dir "destination" => dest_dir
})) }))
@site.process @site.process
output = capture_stderr do output = capture_stderr do
ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site) ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site)
assert_equal true, ret assert_equal true, ret
end end
assert_includes output, "Warning: The following URLs only differ by case. On a case-insensitive file system one of the URLs will be overwritten by the other: #{dest_dir}/about/index.html, #{dest_dir}/About/index.html" assert_includes output, "Warning: The following URLs only differ by case. "\
"On a case-insensitive file system one of the URLs will be overwritten by the "\
"other: #{dest_dir}/about/index.html, #{dest_dir}/About/index.html"
end end
end end
end end

View File

@ -1,22 +1,24 @@
require 'helper' require "helper"
class TestExcerpt < JekyllUnitTest class TestExcerpt < JekyllUnitTest
def setup_post(file) def setup_post(file)
Document.new(@site.in_source_dir(File.join('_posts', file)), { Document.new(@site.in_source_dir(File.join("_posts", file)), {
site: @site, :site => @site,
collection: @site.posts :collection => @site.posts
}).tap(&:read) }).tap(&:read)
end end
def do_render(document) def do_render(document)
@site.layouts = { "default" => Layout.new(@site, source_dir('_layouts'), "simple.html")} @site.layouts = {
"default" => Layout.new(@site, source_dir("_layouts"), "simple.html")
}
document.output = Jekyll::Renderer.new(@site, document, @site.site_payload).run document.output = Jekyll::Renderer.new(@site, document, @site.site_payload).run
end end
context "With extraction disabled" do context "With extraction disabled" do
setup do setup do
clear_dest clear_dest
@site = fixture_site('excerpt_separator' => '') @site = fixture_site("excerpt_separator" => "")
@post = setup_post("2013-07-22-post-excerpt-with-layout.markdown") @post = setup_post("2013-07-22-post-excerpt-with-layout.markdown")
end end
@ -30,11 +32,10 @@ class TestExcerpt < JekyllUnitTest
clear_dest clear_dest
@site = fixture_site @site = fixture_site
@post = setup_post("2013-07-22-post-excerpt-with-layout.markdown") @post = setup_post("2013-07-22-post-excerpt-with-layout.markdown")
@excerpt = @post.data['excerpt'] @excerpt = @post.data["excerpt"]
end end
context "#include(string)" do context "#include(string)" do
setup do setup do
@excerpt.output = "Here is a fake output stub" @excerpt.output = "Here is a fake output stub"
end end
@ -78,19 +79,22 @@ class TestExcerpt < JekyllUnitTest
context "#to_liquid" do context "#to_liquid" do
should "contain the proper page data to mimick the post liquid" do should "contain the proper page data to mimick the post liquid" do
assert_equal "Post Excerpt with Layout", @excerpt.to_liquid["title"] assert_equal "Post Excerpt with Layout", @excerpt.to_liquid["title"]
assert_equal "/bar/baz/z_category/mixedcase/2013/07/22/post-excerpt-with-layout.html", @excerpt.to_liquid["url"] url = "/bar/baz/z_category/mixedcase/2013/07/22/post-excerpt-with-layout.html"
assert_equal url, @excerpt.to_liquid["url"]
assert_equal Time.parse("2013-07-22"), @excerpt.to_liquid["date"] assert_equal Time.parse("2013-07-22"), @excerpt.to_liquid["date"]
assert_equal %w[bar baz z_category MixedCase], @excerpt.to_liquid["categories"] assert_equal %w(bar baz z_category MixedCase), @excerpt.to_liquid["categories"]
assert_equal %w[first second third jekyllrb.com], @excerpt.to_liquid["tags"] assert_equal %w(first second third jekyllrb.com), @excerpt.to_liquid["tags"]
assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown", @excerpt.to_liquid["path"] assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown",
@excerpt.to_liquid["path"]
end end
end end
context "#content" do context "#content" do
context "before render" do context "before render" do
should "be the first paragraph of the page" do should "be the first paragraph of the page" do
assert_equal "First paragraph with [link ref][link].\n\n[link]: http://www.jekyllrb.com/", @excerpt.content expected = "First paragraph with [link ref][link].\n\n[link]: "\
"http://www.jekyllrb.com/"
assert_equal expected, @excerpt.content
end end
should "contain any refs at the bottom of the page" do should "contain any refs at the bottom of the page" do
@ -102,11 +106,13 @@ class TestExcerpt < JekyllUnitTest
setup do setup do
@rendered_post = @post.dup @rendered_post = @post.dup
do_render(@rendered_post) do_render(@rendered_post)
@extracted_excerpt = @rendered_post.data['excerpt'] @extracted_excerpt = @rendered_post.data["excerpt"]
end end
should "be the first paragraph of the page" do should "be the first paragraph of the page" do
assert_equal "<p>First paragraph with <a href=\"http://www.jekyllrb.com/\">link ref</a>.</p>\n\n", @extracted_excerpt.output expected = "<p>First paragraph with <a href=\"http://www.jekyllrb.com/\">link "\
"ref</a>.</p>\n\n"
assert_equal expected, @extracted_excerpt.output
end end
should "link properly" do should "link properly" do
@ -121,7 +127,7 @@ class TestExcerpt < JekyllUnitTest
clear_dest clear_dest
@site = fixture_site @site = fixture_site
@post = setup_post("2008-02-02-published.markdown") @post = setup_post("2008-02-02-published.markdown")
@excerpt = @post.data['excerpt'] @excerpt = @post.data["excerpt"]
end end
should "be generated" do should "be generated" do

View File

@ -1,14 +1,13 @@
require 'helper' require "helper"
class TestFrontMatterDefaults < JekyllUnitTest class TestFrontMatterDefaults < JekyllUnitTest
context "A site with full front matter defaults" do context "A site with full front matter defaults" do
setup do setup do
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration({
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"path" => "contacts", "path" => "contacts",
"type" => "page" "type" => "page"
}, },
@ -33,8 +32,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration({
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"path" => "index.html" "path" => "index.html"
}, },
"values" => { "values" => {
@ -59,8 +58,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration({
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"path" => "win" "path" => "win"
}, },
"values" => { "values" => {
@ -69,7 +68,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
}] }]
})) }))
@site.process @site.process
@affected = @site.posts.docs.find { |page| page.relative_path =~ /win\// } @affected = @site.posts.docs.find { |page| page.relative_path =~ %r!win\/! }
@not_affected = @site.pages.find { |page| page.relative_path == "about.html" } @not_affected = @site.pages.find { |page| page.relative_path == "about.html" }
end end
@ -84,8 +83,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration({
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"type" => "page" "type" => "page"
}, },
"values" => { "values" => {
@ -100,7 +99,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
should "affect only the specified type and all paths" do should "affect only the specified type and all paths" do
assert_equal @affected.reject { |page| page.data["key"] == "val" }, [] assert_equal @affected.reject { |page| page.data["key"] == "val" }, []
assert_equal @not_affected.reject { |page| page.data["key"] == "val" }, @not_affected assert_equal @not_affected.reject { |page| page.data["key"] == "val" },
@not_affected
end end
end end
@ -109,8 +109,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration({
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"type" => "pages" "type" => "pages"
}, },
"values" => { "values" => {
@ -125,7 +125,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
should "affect only the specified type and all paths" do should "affect only the specified type and all paths" do
assert_equal @affected.reject { |page| page.data["key"] == "val" }, [] assert_equal @affected.reject { |page| page.data["key"] == "val" }, []
assert_equal @not_affected.reject { |page| page.data["key"] == "val" }, @not_affected assert_equal @not_affected.reject { |page| page.data["key"] == "val" },
@not_affected
end end
end end
@ -134,8 +135,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration({
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
}, },
"values" => { "values" => {
"key" => "val" "key" => "val"
@ -158,7 +159,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration({
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"defaults" => [{ "defaults" => [{
"values" => { "values" => {
"key" => "val" "key" => "val"
} }
@ -180,7 +181,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration({
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"defaults" => [{ "defaults" => [{
"values" => { "values" => {
"date" => "2015-01-01 00:00:01" "date" => "2015-01-01 00:00:01"
} }
@ -199,5 +200,4 @@ class TestFrontMatterDefaults < JekyllUnitTest
assert @site.posts.find { |page| page.data["date"] == date } assert @site.posts.find { |page| page.data["date"] == date }
end end
end end
end end

View File

@ -1,14 +1,15 @@
require 'helper' require "helper"
class TestGeneratedSite < JekyllUnitTest class TestGeneratedSite < JekyllUnitTest
context "generated sites" do context "generated sites" do
setup do setup do
clear_dest clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir}) config = Jekyll::Configuration::DEFAULTS.merge({ "source" => source_dir,
"destination" => dest_dir })
@site = fixture_site(config) @site = fixture_site(config)
@site.process @site.process
@index = File.read(dest_dir('index.html')) @index = File.read(dest_dir("index.html"))
end end
should "ensure post count is as expected" do should "ensure post count is as expected" do
@ -24,29 +25,29 @@ class TestGeneratedSite < JekyllUnitTest
end end
should "hide unpublished posts" do should "hide unpublished posts" do
published = Dir[dest_dir('publish_test/2008/02/02/*.html')].map {|f| File.basename(f)} published = Dir[dest_dir("publish_test/2008/02/02/*.html")].map \
{ |f| File.basename(f) }
assert_equal 1, published.size assert_equal 1, published.size
assert_equal "published.html", published.first assert_equal "published.html", published.first
end end
should "hide unpublished page" do should "hide unpublished page" do
refute_exist dest_dir('/unpublished.html') refute_exist dest_dir("/unpublished.html")
end end
should "not copy _posts directory" do should "not copy _posts directory" do
refute_exist dest_dir('_posts') refute_exist dest_dir("_posts")
end end
should "process a page with a folder permalink properly" do should "process a page with a folder permalink properly" do
about = @site.pages.find {|page| page.name == 'about.html' } about = @site.pages.find { |page| page.name == "about.html" }
assert_equal dest_dir('about', 'index.html'), about.destination(dest_dir) assert_equal dest_dir("about", "index.html"), about.destination(dest_dir)
assert_exist dest_dir('about', 'index.html') assert_exist dest_dir("about", "index.html")
end end
should "process other static files and generate correct permalinks" do should "process other static files and generate correct permalinks" do
assert_exist dest_dir('contacts.html') assert_exist dest_dir("contacts.html")
assert_exist dest_dir('dynamic_file.php') assert_exist dest_dir("dynamic_file.php")
end end
should "print a nice list of static files" do should "print a nice list of static files" do
@ -57,17 +58,19 @@ class TestGeneratedSite < JekyllUnitTest
- /products.yml last edited at #{time_regexp} with extname .yml - /products.yml last edited at #{time_regexp} with extname .yml
- /symlink-test/symlinked-dir/screen.css last edited at #{time_regexp} with extname .css - /symlink-test/symlinked-dir/screen.css last edited at #{time_regexp} with extname .css
OUTPUT OUTPUT
assert_match expected_output, File.read(dest_dir('static_files.html')) assert_match expected_output, File.read(dest_dir("static_files.html"))
end end
end end
context "generating limited posts" do context "generating limited posts" do
setup do setup do
clear_dest clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 5}) config = Jekyll::Configuration::DEFAULTS.merge({ "source" => source_dir,
"destination" => dest_dir,
"limit_posts" => 5 })
@site = fixture_site(config) @site = fixture_site(config)
@site.process @site.process
@index = File.read(dest_dir('index.html')) @index = File.read(dest_dir("index.html"))
end end
should "generate only the specified number of posts" do should "generate only the specified number of posts" do
@ -78,9 +81,9 @@ OUTPUT
assert_raises ArgumentError do assert_raises ArgumentError do
clear_dest clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({ config = Jekyll::Configuration::DEFAULTS.merge({
'source' => source_dir, "source" => source_dir,
'destination' => dest_dir, "destination" => dest_dir,
'limit_posts' => -1 "limit_posts" => -1
}) })
@site = fixture_site(config) @site = fixture_site(config)
end end
@ -89,9 +92,9 @@ OUTPUT
should "acceptable limit post is 0" do should "acceptable limit post is 0" do
clear_dest clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({ config = Jekyll::Configuration::DEFAULTS.merge({
'source' => source_dir, "source" => source_dir,
'destination' => dest_dir, "destination" => dest_dir,
'limit_posts' => 0 "limit_posts" => 0
}) })
assert Site.new(config), "Couldn't create a site with the given limit_posts." assert Site.new(config), "Couldn't create a site with the given limit_posts."

View File

@ -1,9 +1,10 @@
require 'helper' require "helper"
class TestLayoutReader < JekyllUnitTest class TestLayoutReader < JekyllUnitTest
context "reading layouts" do context "reading layouts" do
setup do setup do
config = Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir}) config = Jekyll::Configuration::DEFAULTS.merge({ "source" => source_dir,
"destination" => dest_dir })
@site = fixture_site(config) @site = fixture_site(config)
end end

View File

@ -1,12 +1,11 @@
require 'helper' require "helper"
class TestLiquidExtensions < JekyllUnitTest class TestLiquidExtensions < JekyllUnitTest
context "looking up a variable in a Liquid context" do context "looking up a variable in a Liquid context" do
class SayHi < Liquid::Tag class SayHi < Liquid::Tag
include Jekyll::LiquidExtensions include Jekyll::LiquidExtensions
def initialize(tag_name, markup, tokens) def initialize(_tag_name, markup, _tokens)
@markup = markup.strip @markup = markup.strip
end end
@ -14,18 +13,18 @@ class TestLiquidExtensions < JekyllUnitTest
"hi #{lookup_variable(context, @markup)}" "hi #{lookup_variable(context, @markup)}"
end end
end end
Liquid::Template.register_tag('say_hi', SayHi) Liquid::Template.register_tag("say_hi", SayHi)
setup do setup do
@template = Liquid::Template.parse("{% say_hi page.name %}") # Parses and compiles the template # Parses and compiles the template
@template = Liquid::Template.parse("{% say_hi page.name %}")
end end
should "extract the var properly" do should "extract the var properly" do
assert_equal @template.render({'page' => {'name' => 'tobi'}}), 'hi tobi' assert_equal @template.render({ "page" => { "name" => "tobi" } }), "hi tobi"
end end
should "return the variable name if the value isn't there" do should "return the variable name if the value isn't there" do
assert_equal @template.render({'page' => {'title' => 'tobi'}}), 'hi page.name' assert_equal @template.render({ "page" => { "title" => "tobi" } }), "hi page.name"
end end
end end
end end

View File

@ -1,12 +1,15 @@
require 'helper' require "helper"
class TestLogAdapter < JekyllUnitTest class TestLogAdapter < JekyllUnitTest
class LoggerDouble class LoggerDouble
attr_accessor :level attr_accessor :level
def debug(*); end def debug(*); end
def info(*); end def info(*); end
def warn(*); end def warn(*); end
def error(*); end def error(*); end
end end
@ -58,8 +61,9 @@ class TestLogAdapter < JekyllUnitTest
should "call #debug on writer return true" do should "call #debug on writer return true" do
writer = LoggerDouble.new writer = LoggerDouble.new
logger = Jekyll::LogAdapter.new(writer) logger = Jekyll::LogAdapter.new(writer)
allow(writer).to receive(:debug).with('topic '.rjust(20) + 'log message').and_return(true) allow(writer).to receive(:debug)
assert logger.debug('topic', 'log message') .with("topic ".rjust(20) + "log message").and_return(true)
assert logger.debug("topic", "log message")
end end
end end
@ -67,8 +71,9 @@ class TestLogAdapter < JekyllUnitTest
should "call #info on writer return true" do should "call #info on writer return true" do
writer = LoggerDouble.new writer = LoggerDouble.new
logger = Jekyll::LogAdapter.new(writer) logger = Jekyll::LogAdapter.new(writer)
allow(writer).to receive(:info).with('topic '.rjust(20) + 'log message').and_return(true) allow(writer).to receive(:info)
assert logger.info('topic', 'log message') .with("topic ".rjust(20) + "log message").and_return(true)
assert logger.info("topic", "log message")
end end
end end
@ -76,8 +81,9 @@ class TestLogAdapter < JekyllUnitTest
should "call #warn on writer return true" do should "call #warn on writer return true" do
writer = LoggerDouble.new writer = LoggerDouble.new
logger = Jekyll::LogAdapter.new(writer) logger = Jekyll::LogAdapter.new(writer)
allow(writer).to receive(:warn).with('topic '.rjust(20) + 'log message').and_return(true) allow(writer).to receive(:warn)
assert logger.warn('topic', 'log message') .with("topic ".rjust(20) + "log message").and_return(true)
assert logger.warn("topic", "log message")
end end
end end
@ -85,16 +91,17 @@ class TestLogAdapter < JekyllUnitTest
should "call #error on writer return true" do should "call #error on writer return true" do
writer = LoggerDouble.new writer = LoggerDouble.new
logger = Jekyll::LogAdapter.new(writer) logger = Jekyll::LogAdapter.new(writer)
allow(writer).to receive(:error).with('topic '.rjust(20) + 'log message').and_return(true) allow(writer).to receive(:error)
assert logger.error('topic', 'log message') .with("topic ".rjust(20) + "log message").and_return(true)
assert logger.error("topic", "log message")
end end
end end
context "#abort_with" do context "#abort_with" do
should "call #error and abort" do should "call #error and abort" do
logger = Jekyll::LogAdapter.new(LoggerDouble.new) logger = Jekyll::LogAdapter.new(LoggerDouble.new)
allow(logger).to receive(:error).with('topic', 'log message').and_return(true) allow(logger).to receive(:error).with("topic", "log message").and_return(true)
assert_raises(SystemExit) { logger.abort_with('topic', 'log message') } assert_raises(SystemExit) { logger.abort_with("topic", "log message") }
end end
end end
@ -105,7 +112,7 @@ class TestLogAdapter < JekyllUnitTest
should "store each log value in the array" do should "store each log value in the array" do
logger = Jekyll::LogAdapter.new(LoggerDouble.new) logger = Jekyll::LogAdapter.new(LoggerDouble.new)
values = %w{one two three four} values = %w(one two three four)
logger.debug(values[0]) logger.debug(values[0])
logger.info(values[1]) logger.info(values[1])
logger.warn(values[2]) logger.warn(values[2])

View File

@ -1,10 +1,10 @@
require 'helper' require "helper"
require 'jekyll/commands/new' require "jekyll/commands/new"
class TestNewCommand < JekyllUnitTest class TestNewCommand < JekyllUnitTest
def dir_contents(path) def dir_contents(path)
Dir["#{path}/**/*"].each do |file| Dir["#{path}/**/*"].each do |file|
file.gsub! path, '' file.gsub! path, ""
end end
end end
@ -12,9 +12,9 @@ class TestNewCommand < JekyllUnitTest
File.expand_path("../lib/site_template", File.dirname(__FILE__)) File.expand_path("../lib/site_template", File.dirname(__FILE__))
end end
context 'when args contains a path' do context "when args contains a path" do
setup do setup do
@path = 'new-site' @path = "new-site"
@args = [@path] @args = [@path]
@full_path = File.expand_path(@path, Dir.pwd) @full_path = File.expand_path(@path, Dir.pwd)
end end
@ -23,7 +23,7 @@ class TestNewCommand < JekyllUnitTest
FileUtils.rm_r @full_path FileUtils.rm_r @full_path
end end
should 'create a new directory' do should "create a new directory" do
refute_exist @full_path refute_exist @full_path
Jekyll::Commands::New.process(@args) Jekyll::Commands::New.process(@args)
assert_exist @full_path assert_exist @full_path
@ -34,43 +34,43 @@ class TestNewCommand < JekyllUnitTest
refute_exist @full_path refute_exist @full_path
capture_stdout { Jekyll::Commands::New.process(@args) } capture_stdout { Jekyll::Commands::New.process(@args) }
assert_exist gemfile assert_exist gemfile
assert_match /gem "jekyll", "#{Jekyll::VERSION}"/, File.read(gemfile) assert_match(/gem "jekyll", "#{Jekyll::VERSION}"/, File.read(gemfile))
assert_match /gem "github-pages"/, File.read(gemfile) assert_match(/gem "github-pages"/, File.read(gemfile))
end end
should 'display a success message' do should "display a success message" do
Jekyll::Commands::New.process(@args) Jekyll::Commands::New.process(@args)
output = Jekyll.logger.messages.last output = Jekyll.logger.messages.last
success_message = "New jekyll site installed in #{@full_path}." success_message = "New jekyll site installed in #{@full_path}."
assert_includes output, success_message assert_includes output, success_message
end end
should 'copy the static files in site template to the new directory' do should "copy the static files in site template to the new directory" do
static_template_files = dir_contents(site_template).reject do |f| static_template_files = dir_contents(site_template).reject do |f|
File.extname(f) == '.erb' File.extname(f) == ".erb"
end end
static_template_files << "/Gemfile" static_template_files << "/Gemfile"
capture_stdout { Jekyll::Commands::New.process(@args) } capture_stdout { Jekyll::Commands::New.process(@args) }
new_site_files = dir_contents(@full_path).reject do |f| new_site_files = dir_contents(@full_path).reject do |f|
File.extname(f) == '.markdown' File.extname(f) == ".markdown"
end end
assert_same_elements static_template_files, new_site_files assert_same_elements static_template_files, new_site_files
end end
should 'process any ERB files' do should "process any ERB files" do
erb_template_files = dir_contents(site_template).select do |f| erb_template_files = dir_contents(site_template).select do |f|
File.extname(f) == '.erb' File.extname(f) == ".erb"
end end
stubbed_date = '2013-01-01' stubbed_date = "2013-01-01"
allow_any_instance_of(Time).to receive(:strftime) { stubbed_date } allow_any_instance_of(Time).to receive(:strftime) { stubbed_date }
erb_template_files.each do |f| erb_template_files.each do |f|
f.chomp! '.erb' f.chomp! ".erb"
f.gsub! '0000-00-00', stubbed_date f.gsub! "0000-00-00", stubbed_date
end end
capture_stdout { Jekyll::Commands::New.process(@args) } capture_stdout { Jekyll::Commands::New.process(@args) }
@ -82,22 +82,22 @@ class TestNewCommand < JekyllUnitTest
assert_same_elements erb_template_files, new_site_files assert_same_elements erb_template_files, new_site_files
end end
should 'create blank project' do should "create blank project" do
blank_contents = %w(/_drafts /_layouts /_posts /index.html) blank_contents = %w(/_drafts /_layouts /_posts /index.html)
capture_stdout { Jekyll::Commands::New.process(@args, '--blank') } capture_stdout { Jekyll::Commands::New.process(@args, "--blank") }
assert_same_elements blank_contents, dir_contents(@full_path) assert_same_elements blank_contents, dir_contents(@full_path)
end end
should 'force created folder' do should "force created folder" do
capture_stdout { Jekyll::Commands::New.process(@args) } capture_stdout { Jekyll::Commands::New.process(@args) }
output = capture_stdout { Jekyll::Commands::New.process(@args, '--force') } output = capture_stdout { Jekyll::Commands::New.process(@args, "--force") }
assert_match(/New jekyll site installed in/, output) assert_match(/New jekyll site installed in/, output)
end end
end end
context 'when multiple args are given' do context "when multiple args are given" do
setup do setup do
@site_name_with_spaces = 'new site name' @site_name_with_spaces = "new site name"
@multiple_args = @site_name_with_spaces.split @multiple_args = @site_name_with_spaces.split
end end
@ -105,23 +105,23 @@ class TestNewCommand < JekyllUnitTest
FileUtils.rm_r File.expand_path(@site_name_with_spaces, Dir.pwd) FileUtils.rm_r File.expand_path(@site_name_with_spaces, Dir.pwd)
end end
should 'create a new directory' do should "create a new directory" do
refute_exist @site_name_with_spaces refute_exist @site_name_with_spaces
capture_stdout { Jekyll::Commands::New.process(@multiple_args) } capture_stdout { Jekyll::Commands::New.process(@multiple_args) }
assert_exist @site_name_with_spaces assert_exist @site_name_with_spaces
end end
end end
context 'when no args are given' do context "when no args are given" do
setup do setup do
@empty_args = [] @empty_args = []
end end
should 'raise an ArgumentError' do should "raise an ArgumentError" do
exception = assert_raises ArgumentError do exception = assert_raises ArgumentError do
Jekyll::Commands::New.process(@empty_args) Jekyll::Commands::New.process(@empty_args)
end end
assert_equal 'You must specify a path.', exception.message assert_equal "You must specify a path.", exception.message
end end
end end
end end

View File

@ -1,4 +1,4 @@
require 'helper' require "helper"
class TestPathSanitization < JekyllUnitTest class TestPathSanitization < JekyllUnitTest
context "on Windows with absolute source" do context "on Windows with absolute source" do
@ -8,20 +8,24 @@ class TestPathSanitization < JekyllUnitTest
allow(Dir).to receive(:pwd).and_return("C:/Users/xmr/Desktop/mpc-hc.org") allow(Dir).to receive(:pwd).and_return("C:/Users/xmr/Desktop/mpc-hc.org")
end end
should "strip drive name from path" do should "strip drive name from path" do
assert_equal "C:/Users/xmr/Desktop/mpc-hc.org/_site", Jekyll.sanitized_path(@source, @dest) assert_equal "C:/Users/xmr/Desktop/mpc-hc.org/_site",
Jekyll.sanitized_path(@source, @dest)
end end
should "strip just the initial drive name" do should "strip just the initial drive name" do
assert_equal "/tmp/foobar/jail/..c:/..c:/..c:/etc/passwd", Jekyll.sanitized_path("/tmp/foobar/jail", "..c:/..c:/..c:/etc/passwd") assert_equal "/tmp/foobar/jail/..c:/..c:/..c:/etc/passwd",
Jekyll.sanitized_path("/tmp/foobar/jail", "..c:/..c:/..c:/etc/passwd")
end end
end end
should "escape tilde" do should "escape tilde" do
assert_equal source_dir("~hi.txt"), Jekyll.sanitized_path(source_dir, "~hi.txt") assert_equal source_dir("~hi.txt"), Jekyll.sanitized_path(source_dir, "~hi.txt")
assert_equal source_dir("files", "~hi.txt"), Jekyll.sanitized_path(source_dir, "files/../files/~hi.txt") assert_equal source_dir("files", "~hi.txt"),
Jekyll.sanitized_path(source_dir, "files/../files/~hi.txt")
end end
should "remove path traversals" do should "remove path traversals" do
assert_equal source_dir("files", "hi.txt"), Jekyll.sanitized_path(source_dir, "f./../../../../../../files/hi.txt") assert_equal source_dir("files", "hi.txt"),
Jekyll.sanitized_path(source_dir, "f./../../../../../../files/hi.txt")
end end
end end

View File

@ -1,4 +1,4 @@
require 'helper' require "helper"
class TestPluginManager < JekyllUnitTest class TestPluginManager < JekyllUnitTest
def with_no_gemfile def with_no_gemfile
@ -10,14 +10,16 @@ class TestPluginManager < JekyllUnitTest
def test_requiring_from_bundler def test_requiring_from_bundler
with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do
assert Jekyll::PluginManager.require_from_bundler, 'require_from_bundler should return true.' assert Jekyll::PluginManager.require_from_bundler,
assert ENV["JEKYLL_NO_BUNDLER_REQUIRE"], 'Gemfile plugins were not required.' "require_from_bundler should return true."
assert ENV["JEKYLL_NO_BUNDLER_REQUIRE"], "Gemfile plugins were not required."
end end
end end
def test_blocking_requiring_from_bundler def test_blocking_requiring_from_bundler
with_env("JEKYLL_NO_BUNDLER_REQUIRE", "true") do with_env("JEKYLL_NO_BUNDLER_REQUIRE", "true") do
assert_equal false, Jekyll::PluginManager.require_from_bundler, "Gemfile plugins were required but shouldn't have been" assert_equal false, Jekyll::PluginManager.require_from_bundler,
"Gemfile plugins were required but shouldn't have been"
assert ENV["JEKYLL_NO_BUNDLER_REQUIRE"] assert ENV["JEKYLL_NO_BUNDLER_REQUIRE"]
end end
end end
@ -25,7 +27,8 @@ class TestPluginManager < JekyllUnitTest
def test_no_gemfile def test_no_gemfile
with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do
with_no_gemfile do with_no_gemfile do
assert_equal false, Jekyll::PluginManager.require_from_bundler, "Gemfile plugins were required but shouldn't have been" assert_equal false, Jekyll::PluginManager.require_from_bundler,
"Gemfile plugins were required but shouldn't have been"
assert_nil ENV["JEKYLL_NO_BUNDLER_REQUIRE"] assert_nil ENV["JEKYLL_NO_BUNDLER_REQUIRE"]
end end
end end

View File

@ -1,7 +1,6 @@
require 'helper' require "helper"
class TestRdiscount < JekyllUnitTest class TestRdiscount < JekyllUnitTest
context "rdiscount" do context "rdiscount" do
setup do setup do
if jruby? if jruby?
@ -11,12 +10,10 @@ class TestRdiscount < JekyllUnitTest
end end
config = { config = {
'markdown' => 'rdiscount', "markdown" => "rdiscount",
'rdiscount' => { "rdiscount" => {
'toc_token' => '{:toc}', "toc_token" => "{:toc}",
'extensions' => [ "extensions" => %w(smart generate_toc)
'smart', 'generate_toc'
],
} }
} }
@ -45,7 +42,8 @@ class TestRdiscount < JekyllUnitTest
</p> </p>
TOC TOC
assert_equal toc.strip, @markdown.convert("# Header 1\n\n## Header 2\n\n{:toc}").strip assert_equal toc.strip,
@markdown.convert("# Header 1\n\n## Header 2\n\n{:toc}").strip
end end
end end
end end

View File

@ -1,4 +1,4 @@
require 'helper' require "helper"
class TestRedcarpet < JekyllUnitTest class TestRedcarpet < JekyllUnitTest
context "redcarpet" do context "redcarpet" do
@ -10,11 +10,9 @@ class TestRedcarpet < JekyllUnitTest
end end
@config = { @config = {
'markdown' => 'redcarpet', "markdown" => "redcarpet",
'redcarpet' => { "redcarpet" => {
'extensions' => [ "extensions" => %w(smart strikethrough filter_html)
'smart', 'strikethrough', 'filter_html'
]
} }
} }
@ -22,7 +20,7 @@ class TestRedcarpet < JekyllUnitTest
end end
should "pass redcarpet options" do should "pass redcarpet options" do
assert_equal "<h1>Some Header</h1>", @markdown.convert('# Some Header #').strip assert_equal "<h1>Some Header</h1>", @markdown.convert("# Some Header #").strip
end end
should "pass redcarpet SmartyPants options" do should "pass redcarpet SmartyPants options" do
@ -30,58 +28,70 @@ class TestRedcarpet < JekyllUnitTest
end end
should "pass redcarpet extensions" do should "pass redcarpet extensions" do
assert_equal "<p><del>deleted</del></p>", @markdown.convert('~~deleted~~').strip assert_equal "<p><del>deleted</del></p>", @markdown.convert("~~deleted~~").strip
end end
should "pass redcarpet render options" do should "pass redcarpet render options" do
assert_equal "<p><strong>bad code not here</strong>: i am bad</p>", @markdown.convert('**bad code not here**: <script>i am bad</script>').strip assert_equal "<p><strong>bad code not here</strong>: i am bad</p>",
@markdown.convert("**bad code not here**: <script>i am bad</script>").strip
end end
context "with pygments enabled" do context "with pygments enabled" do
setup do setup do
@markdown = Converters::Markdown.new @config.merge({ 'highlighter' => 'pygments' }) @markdown = Converters::Markdown.new @config.merge(
{ "highlighter" => "pygments" }
)
end end
should "render fenced code blocks with syntax highlighting" do should "render fenced code blocks with syntax highlighting" do
assert_equal "<div class=\"highlight\"><pre><code class=\"language-ruby\" data-lang=\"ruby\"><span class=\"nb\">puts</span> <span class=\"s2\">&quot;Hello world&quot;</span>\n</code></pre></div>", @markdown.convert( assert_equal "<div class=\"highlight\"><pre><code class=\"language-ruby\" "\
<<-EOS "data-lang=\"ruby\"><span class=\"nb\">puts</span> <span "\
"class=\"s2\">&quot;Hello world&quot;</span>\n</code></pre></div>",
@markdown.convert(
<<-EOS
```ruby ```ruby
puts "Hello world" puts "Hello world"
``` ```
EOS EOS
).strip ).strip
end end
end end
context "with rouge enabled" do context "with rouge enabled" do
setup do setup do
@markdown = Converters::Markdown.new @config.merge({ 'highlighter' => 'rouge' }) @markdown = Converters::Markdown.new @config.merge({ "highlighter" => "rouge" })
end end
should "render fenced code blocks with syntax highlighting" do should "render fenced code blocks with syntax highlighting" do
assert_equal "<div class=\"highlight\"><pre><code class=\"language-ruby\" data-lang=\"ruby\"><span class=\"nb\">puts</span> <span class=\"s2\">\"Hello world\"</span>\n</code></pre></div>", @markdown.convert( assert_equal "<div class=\"highlight\"><pre><code class=\"language-ruby\" "\
<<-EOS "data-lang=\"ruby\"><span class=\"nb\">puts</span> <span "\
"class=\"s2\">\"Hello world\"</span>\n</code></pre></div>",
@markdown.convert(
<<-EOS
```ruby ```ruby
puts "Hello world" puts "Hello world"
``` ```
EOS EOS
).strip ).strip
end end
end end
context "without any highlighter" do context "without any highlighter" do
setup do setup do
@markdown = Converters::Markdown.new @config.merge({ 'highlighter' => nil }) @markdown = Converters::Markdown.new @config.merge({ "highlighter" => nil })
end end
should "render fenced code blocks without syntax highlighting" do should "render fenced code blocks without syntax highlighting" do
assert_equal "<figure class=\"highlight\"><pre><code class=\"language-ruby\" data-lang=\"ruby\">puts &quot;Hello world&quot;\n</code></pre></figure>", @markdown.convert( assert_equal "<figure class=\"highlight\"><pre><code class=\"language-ruby\" "\
<<-EOS "data-lang=\"ruby\">puts &quot;Hello world&quot;\n</code></pre>"\
"</figure>",
@markdown.convert(
<<-EOS
```ruby ```ruby
puts "Hello world" puts "Hello world"
``` ```
EOS EOS
).strip ).strip
end end
end end
end end