diff --git a/test/fixtures/test-theme/_sass/style.scss b/test/fixtures/test-theme/_sass/test-theme-black.scss similarity index 100% rename from test/fixtures/test-theme/_sass/style.scss rename to test/fixtures/test-theme/_sass/test-theme-black.scss diff --git a/test/fixtures/test-theme/assets/img/another-logo.png b/test/fixtures/test-theme/assets/img/another-logo.png new file mode 120000 index 00000000..bd36e718 --- /dev/null +++ b/test/fixtures/test-theme/assets/img/another-logo.png @@ -0,0 +1 @@ +logo.png \ No newline at end of file diff --git a/test/fixtures/test-theme/assets/img/logo.png b/test/fixtures/test-theme/assets/img/logo.png new file mode 100644 index 00000000..0d1cbe53 Binary files /dev/null and b/test/fixtures/test-theme/assets/img/logo.png differ diff --git a/test/fixtures/test-theme/assets/style.scss b/test/fixtures/test-theme/assets/style.scss new file mode 100644 index 00000000..408f04f7 --- /dev/null +++ b/test/fixtures/test-theme/assets/style.scss @@ -0,0 +1,3 @@ +--- +--- +@import "test-theme-{{ site.theme-color }}"; diff --git a/test/test_theme.rb b/test/test_theme.rb index a24a4c88..82b4224a 100644 --- a/test/test_theme.rb +++ b/test/test_theme.rb @@ -34,9 +34,9 @@ class TestTheme < JekyllUnitTest end context "path generation" do - [:layouts, :includes, :sass].each do |folder| + [:assets, :_layouts, :_includes, :_sass].each do |folder| 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") end end diff --git a/test/test_theme_assets_reader.rb b/test/test_theme_assets_reader.rb new file mode 100644 index 00000000..d964acf3 --- /dev/null +++ b/test/test_theme_assets_reader.rb @@ -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