Add tests for assets directory support.
This commit is contained in:
parent
cf26bf5db0
commit
6d7f305e7c
|
@ -0,0 +1 @@
|
||||||
|
logo.png
|
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
---
|
||||||
|
@import "test-theme-{{ site.theme-color }}";
|
|
@ -34,9 +34,9 @@ class TestTheme < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
context "path generation" do
|
context "path generation" do
|
||||||
[:layouts, :includes, :sass].each do |folder|
|
[:assets, :_layouts, :_includes, :_sass].each do |folder|
|
||||||
should "know the #{folder} path" do
|
should "know the #{folder} path" do
|
||||||
expected = File.expand_path("_#{folder}", @expected_root)
|
expected = File.expand_path(folder.to_s, @expected_root)
|
||||||
assert_equal expected, @theme.public_send("#{folder}_path")
|
assert_equal expected, @theme.public_send("#{folder}_path")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
require "helper"
|
||||||
|
|
||||||
|
class TestThemeAssetsReader < JekyllUnitTest
|
||||||
|
def setup
|
||||||
|
@site = fixture_site(
|
||||||
|
"theme" => "test-theme",
|
||||||
|
"theme-color" => "black"
|
||||||
|
)
|
||||||
|
assert @site.theme
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_file_with_relative_path(haystack, relative_path)
|
||||||
|
assert haystack.any? { |f|
|
||||||
|
f.relative_path == relative_path
|
||||||
|
}, "Site should read in the #{relative_path} file, but it was not found in #{haystack.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def refute_file_with_relative_path(haystack, relative_path)
|
||||||
|
refute haystack.any? { |f|
|
||||||
|
f.relative_path == relative_path
|
||||||
|
}, "Site should not have read in the #{relative_path} file, but it was found in #{haystack.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a valid theme" do
|
||||||
|
should "read all assets" do
|
||||||
|
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"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "convert pages" do
|
||||||
|
@site.process
|
||||||
|
|
||||||
|
file = @site.pages.find { |f| f.relative_path == "assets/style.scss" }
|
||||||
|
refute_nil file
|
||||||
|
assert_equal @site.in_dest_dir("assets/style.css"), file.destination(@site.dest)
|
||||||
|
assert_includes file.output, ".sample {\n color: black; }"
|
||||||
|
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")
|
||||||
|
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"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with no theme" do
|
||||||
|
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"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue