Add test to ensure that the /assets theme reader doesn't clobber preexisting site files.

This commit is contained in:
Parker Moore 2016-09-20 13:12:34 -07:00
parent b78827cecb
commit 29d8fee4ce
No known key found for this signature in database
GPG Key ID: 193CDEBA72063C58
5 changed files with 23 additions and 6 deletions

View File

@ -0,0 +1,3 @@
---
---
alert "From your theme."

View File

@ -0,0 +1,3 @@
---
---
alert "From your site."

View File

@ -475,7 +475,7 @@ class TestFilters < JekyllUnitTest
g["items"].is_a?(Array),
"The list of grouped items for '' is not an Array."
)
assert_equal 14, g["items"].size
assert_equal 15, g["items"].size
end
end
end

View File

@ -180,6 +180,7 @@ class TestSite < JekyllUnitTest
%#\ +.md
.htaccess
about.html
application.coffee
bar.html
coffeescript.coffee
contacts.html

View File

@ -25,6 +25,7 @@ class TestThemeAssetsReader < JekyllUnitTest
context "with a valid theme" do
should "read all assets" do
@site.reset
ThemeAssetsReader.new(@site).read
assert_file_with_relative_path @site.static_files, "assets/img/logo.png"
assert_file_with_relative_path @site.pages, "assets/style.scss"
@ -38,15 +39,24 @@ class TestThemeAssetsReader < JekyllUnitTest
assert_equal @site.in_dest_dir("assets/style.css"), file.destination(@site.dest)
assert_includes file.output, ".sample {\n color: black; }"
end
should "not overwrite site content with the same relative path" do
@site.reset
@site.read
file = @site.pages.find { |f| f.relative_path == "assets/application.coffee" }
refute_nil file
assert_includes file.content, "alert \"From your site.\""
end
end
context "with a valid theme without an assets dir" do
should "not read any assets" do
allow(Theme).to receive(:realpath_for).with(:sass).and_return(nil)
site = fixture_site("theme" => "test-theme")
allow(site.theme).to receive(:assets_path).and_return(nil)
ThemeAssetsReader.new(site).read
refute_file_with_relative_path @site.static_files, "assets/img/logo.png"
refute_file_with_relative_path @site.pages, "assets/style.scss"
refute_file_with_relative_path site.static_files, "assets/img/logo.png"
refute_file_with_relative_path site.pages, "assets/style.scss"
end
end
@ -54,8 +64,8 @@ class TestThemeAssetsReader < JekyllUnitTest
should "not read any assets" do
site = fixture_site("theme" => nil)
ThemeAssetsReader.new(site).read
refute_file_with_relative_path @site.static_files, "assets/img/logo.png"
refute_file_with_relative_path @site.pages, "assets/style.scss"
refute_file_with_relative_path site.static_files, "assets/img/logo.png"
refute_file_with_relative_path site.pages, "assets/style.scss"
end
end
end