Merge pull request #4916 from brint/rubocop_cleaning

Merge pull request 4916
This commit is contained in:
jekyllbot 2016-05-23 13:36:48 -07:00
commit 6eaf2634f2
8 changed files with 81 additions and 73 deletions

View File

@ -62,10 +62,7 @@ AllCops:
- lib/jekyll/tags/post_url.rb - lib/jekyll/tags/post_url.rb
- lib/jekyll/theme.rb - lib/jekyll/theme.rb
- lib/jekyll/url.rb - lib/jekyll/url.rb
- lib/jekyll/utils/ansi.rb
- lib/jekyll/utils/platforms.rb
- lib/jekyll/utils.rb - lib/jekyll/utils.rb
- lib/jekyll/version.rb
- lib/jekyll.rb - lib/jekyll.rb
- features/step_definitions.rb - features/step_definitions.rb
- features/support/formatter.rb - features/support/formatter.rb
@ -78,13 +75,8 @@ AllCops:
- test/test_liquid_renderer.rb - test/test_liquid_renderer.rb
- test/test_page.rb - test/test_page.rb
- test/test_regenerator.rb - test/test_regenerator.rb
- test/test_related_posts.rb
- test/test_sass.rb
- test/test_site.rb - test/test_site.rb
- test/test_static_file.rb
- test/test_tags.rb - test/test_tags.rb
- test/test_theme.rb
- test/test_url.rb
- test/test_utils.rb - test/test_utils.rb
- bin/**/* - bin/**/*
- benchmark/**/* - benchmark/**/*

View File

@ -8,7 +8,7 @@ module Jekyll
extend self extend self
ESCAPE = format("%c", 27) ESCAPE = format("%c", 27)
MATCH = /#{ESCAPE}\[(?:\d+)(?:;\d+)*(j|k|m|s|u|A|B|G)|\e\(B\e\[m/ix.freeze MATCH = /#{ESCAPE}\[(?:\d+)(?:;\d+)*(j|k|m|s|u|A|B|G)|\e\(B\e\[m/ix
COLORS = { COLORS = {
:red => 31, :red => 31,
:green => 32, :green => 32,
@ -18,7 +18,7 @@ module Jekyll
:white => 37, :white => 37,
:blue => 34, :blue => 34,
:cyan => 36 :cyan => 36
} }.freeze
# Strip ANSI from the current string. It also strips cursor stuff, # Strip ANSI from the current string. It also strips cursor stuff,
# well some of it, and it also strips some other stuff that a lot of # well some of it, and it also strips some other stuff that a lot of

View File

@ -1,3 +1,3 @@
module Jekyll module Jekyll
VERSION = '3.2.0.pre.beta1' VERSION = "3.2.0.pre.beta1".freeze
end end

View File

@ -1,4 +1,4 @@
require 'helper' require "helper"
class TestRelatedPosts < JekyllUnitTest class TestRelatedPosts < JekyllUnitTest
context "building related posts without lsi" do context "building related posts without lsi" do
@ -33,26 +33,29 @@ class TestRelatedPosts < JekyllUnitTest
@site.reset @site.reset
@site.read @site.read
require 'classifier-reborn' require "classifier-reborn"
Jekyll::RelatedPosts.lsi = nil Jekyll::RelatedPosts.lsi = nil
end end
should "index Jekyll::Post objects" do should "index Jekyll::Post objects" do
@site.posts.docs = @site.posts.docs.first(1) @site.posts.docs = @site.posts.docs.first(1)
expect_any_instance_of(::ClassifierReborn::LSI).to receive(:add_item).with(kind_of(Jekyll::Document)) expect_any_instance_of(::ClassifierReborn::LSI).to \
receive(:add_item).with(kind_of(Jekyll::Document))
Jekyll::RelatedPosts.new(@site.posts.last).build_index Jekyll::RelatedPosts.new(@site.posts.last).build_index
end end
should "find related Jekyll::Post objects, given a Jekyll::Post object" do should "find related Jekyll::Post objects, given a Jekyll::Post object" do
post = @site.posts.last post = @site.posts.last
allow_any_instance_of(::ClassifierReborn::LSI).to receive(:build_index) allow_any_instance_of(::ClassifierReborn::LSI).to receive(:build_index)
expect_any_instance_of(::ClassifierReborn::LSI).to receive(:find_related).with(post, 11).and_return(@site.posts[-1..-9]) expect_any_instance_of(::ClassifierReborn::LSI).to \
receive(:find_related).with(post, 11).and_return(@site.posts[-1..-9])
Jekyll::RelatedPosts.new(post).build Jekyll::RelatedPosts.new(post).build
end end
should "use lsi for the related posts" do should "use lsi for the related posts" do
allow_any_instance_of(::ClassifierReborn::LSI).to receive(:find_related).and_return(@site.posts[-1..-9]) allow_any_instance_of(::ClassifierReborn::LSI).to \
receive(:find_related).and_return(@site.posts[-1..-9])
allow_any_instance_of(::ClassifierReborn::LSI).to receive(:build_index) allow_any_instance_of(::ClassifierReborn::LSI).to receive(:build_index)
assert_equal @site.posts[-1..-9], Jekyll::RelatedPosts.new(@site.posts.last).build assert_equal @site.posts[-1..-9], Jekyll::RelatedPosts.new(@site.posts.last).build

View File

@ -1,4 +1,4 @@
require 'helper' require "helper"
class TestSass < JekyllUnitTest class TestSass < JekyllUnitTest
context "importing partials" do context "importing partials" do
@ -16,11 +16,13 @@ class TestSass < JekyllUnitTest
end end
should "register the SCSS converter" do should "register the SCSS converter" do
assert !!@site.find_converter_instance(Jekyll::Converters::Scss), "SCSS converter implementation should exist." message = "SCSS converter implementation should exist."
assert !!@site.find_converter_instance(Jekyll::Converters::Scss), message
end end
should "register the Sass converter" do should "register the Sass converter" do
assert !!@site.find_converter_instance(Jekyll::Converters::Sass), "Sass converter implementation should exist." message = "Sass converter implementation should exist."
assert !!@site.find_converter_instance(Jekyll::Converters::Sass), message
end end
end end
end end

View File

@ -1,4 +1,4 @@
require 'helper' require "helper"
class TestStaticFile < JekyllUnitTest class TestStaticFile < JekyllUnitTest
def make_dummy_file(filename) def make_dummy_file(filename)
@ -6,7 +6,8 @@ class TestStaticFile < JekyllUnitTest
end end
def modify_dummy_file(filename) def modify_dummy_file(filename)
offset = "some content".size string = "some content"
offset = string.size
File.write(source_dir(filename), "more content", offset) File.write(source_dir(filename), "more content", offset)
end end
@ -18,13 +19,13 @@ class TestStaticFile < JekyllUnitTest
StaticFile.new(@site, base, dir, name) StaticFile.new(@site, base, dir, name)
end end
def setup_static_file_with_collection(base, dir, name, label, metadata) def setup_static_file_with_collection(base, dir, name, metadata)
site = fixture_site('collections' => {label => metadata}) site = fixture_site("collections" => { "foo" => metadata })
StaticFile.new(site, base, dir, name, site.collections[label]) StaticFile.new(site, base, dir, name, site.collections["foo"])
end end
def setup_static_file_with_defaults(base, dir, name, defaults) def setup_static_file_with_defaults(base, dir, name, defaults)
site = fixture_site('defaults' => defaults) site = fixture_site("defaults" => defaults)
StaticFile.new(site, base, dir, name) StaticFile.new(site, base, dir, name)
end end
@ -63,16 +64,23 @@ class TestStaticFile < JekyllUnitTest
should "have a destination relative directory with a collection" do should "have a destination relative directory with a collection" do
static_file = setup_static_file_with_collection( static_file = setup_static_file_with_collection(
"root", "_foo/dir/subdir", "file.html", "foo", {"output" => true}) "root",
"_foo/dir/subdir",
"file.html",
{ "output" => true }
)
assert_equal :foo, static_file.type assert_equal :foo, static_file.type
assert_equal "/foo/dir/subdir/file.html", static_file.url assert_equal "/foo/dir/subdir/file.html", static_file.url
assert_equal "/foo/dir/subdir", static_file.destination_rel_dir assert_equal "/foo/dir/subdir", static_file.destination_rel_dir
end end
should "use its collection's permalink template for the destination relative directory" do should "use its collection's permalink template for destination relative directory" do
static_file = setup_static_file_with_collection( static_file = setup_static_file_with_collection(
"root", "_foo/dir/subdir", "file.html", "foo", "root",
{"output" => true, "permalink" => "/:path/"}) "_foo/dir/subdir",
"file.html",
{ "output" => true, "permalink" => "/:path/" }
)
assert_equal :foo, static_file.type assert_equal :foo, static_file.type
assert_equal "/dir/subdir/file.html", static_file.url assert_equal "/dir/subdir/file.html", static_file.url
assert_equal "/dir/subdir", static_file.destination_rel_dir assert_equal "/dir/subdir", static_file.destination_rel_dir
@ -90,9 +98,13 @@ class TestStaticFile < JekyllUnitTest
"values" => { "published" => false } "values" => { "published" => false }
}] }]
static_file = setup_static_file_with_defaults( static_file = setup_static_file_with_defaults(
"root", "private/dir/subdir", "file.html", defaults) "root",
"private/dir/subdir",
"file.html",
defaults
)
assert(!static_file.write?, assert(!static_file.write?,
"static_file.write? should return false when _config.yml sets " + "static_file.write? should return false when _config.yml sets " \
"`published: false`") "`published: false`")
end end
@ -116,7 +128,7 @@ class TestStaticFile < JekyllUnitTest
assert @static_file.write?, "always true, with current implementation" assert @static_file.write?, "always true, with current implementation"
end end
should "be able to write itself to the desitination direcotry" do should "be able to write itself to the desitination directory" do
assert @static_file.write(dest_dir) assert @static_file.write(dest_dir)
end end
@ -124,7 +136,7 @@ class TestStaticFile < JekyllUnitTest
expected = { expected = {
"extname" => ".txt", "extname" => ".txt",
"modified_time" => @static_file.modified_time, "modified_time" => @static_file.modified_time,
"path" => "/static_file.txt", "path" => "/static_file.txt"
} }
assert_equal expected, @static_file.to_liquid assert_equal expected, @static_file.to_liquid
end end

View File

@ -1,14 +1,14 @@
require 'helper' require "helper"
class TestTheme < JekyllUnitTest class TestTheme < JekyllUnitTest
def setup def setup
@theme = Theme.new('test-theme') @theme = Theme.new("test-theme")
@expected_root = File.expand_path "./fixtures/test-theme", File.dirname(__FILE__) @expected_root = File.expand_path "./fixtures/test-theme", File.dirname(__FILE__)
end end
context "initializing" do context "initializing" do
should "normalize the theme name" do should "normalize the theme name" do
theme = Theme.new(' Test-Theme ') theme = Theme.new(" Test-Theme ")
assert_equal "test-theme", theme.name assert_equal "test-theme", theme.name
end end
@ -28,7 +28,8 @@ class TestTheme < JekyllUnitTest
should "add itself to sass's load path" do should "add itself to sass's load path" do
@theme.configure_sass @theme.configure_sass
assert Sass.load_paths.include?(@theme.sass_path), "Sass load paths should include the theme sass dir" message = "Sass load paths should include the theme sass dir"
assert Sass.load_paths.include?(@theme.sass_path), message
end end
end end

View File

@ -1,8 +1,7 @@
require 'helper' require "helper"
class TestURL < JekyllUnitTest class TestURL < JekyllUnitTest
context "The URL class" do context "The URL class" do
should "throw an exception if neither permalink or template is specified" do should "throw an exception if neither permalink or template is specified" do
assert_raises ArgumentError do assert_raises ArgumentError do
URL.new(:placeholders => {}) URL.new(:placeholders => {})
@ -17,7 +16,7 @@ class TestURL < JekyllUnitTest
end end
should "handle multiple of the same key in the template" do should "handle multiple of the same key in the template" do
assert_equal '/foo/bar/foo/', URL.new( assert_equal "/foo/bar/foo/", URL.new(
:template => "/:x/:y/:x/", :template => "/:x/:y/:x/",
:placeholders => { :x => "foo", :y => "bar" } :placeholders => { :x => "foo", :y => "bar" }
).to_s ).to_s
@ -40,7 +39,7 @@ class TestURL < JekyllUnitTest
end end
should "handle multiple of the same key in the permalink" do should "handle multiple of the same key in the permalink" do
assert_equal '/foo/bar/foo/', URL.new( assert_equal "/foo/bar/foo/", URL.new(
:template => "/baz", :template => "/baz",
:permalink => "/:x/:y/:x/", :permalink => "/:x/:y/:x/",
:placeholders => { :x => "foo", :y => "bar" } :placeholders => { :x => "foo", :y => "bar" }
@ -48,7 +47,7 @@ class TestURL < JekyllUnitTest
end end
should "handle nil values for keys in the template" do should "handle nil values for keys in the template" do
assert_equal '/foo/bar/', URL.new( assert_equal "/foo/bar/", URL.new(
:template => "/:x/:y/:z/", :template => "/:x/:y/:z/",
:placeholders => { :x => "foo", :y => "bar", :z => nil } :placeholders => { :x => "foo", :y => "bar", :z => nil }
).to_s ).to_s
@ -60,17 +59,16 @@ class TestURL < JekyllUnitTest
"methods" => { "methods" => {
"output" => true "output" => true
} }
}, }
}) })
site.read site.read
matching_doc = site.collections["methods"].docs.find do |doc| matching_doc = site.collections["methods"].docs.find do |doc|
doc.relative_path == "_methods/escape-+ #%20[].md" doc.relative_path == "_methods/escape-+ #%20[].md"
end end
assert_equal '/methods/escape-+-20/escape-20.html', URL.new( assert_equal "/methods/escape-+-20/escape-20.html", URL.new(
:template => '/methods/:title/:name:output_ext', :template => "/methods/:title/:name:output_ext",
:placeholders => matching_doc.url_placeholders :placeholders => matching_doc.url_placeholders
).to_s ).to_s
end end
end end
end end