











1+# frozen_string_literal: true
2+3+require "mercenary"
4+require "helper"
5+require "tmpdir"
6+7+class TestCommandsClean < JekyllUnitTest
8+context "cleaning destination" do
9+setup do
10+@merc = nil
11+@cmd = Jekyll::Commands::Clean
12+Mercenary.program(:jekyll) do |p|
13+@merc = @cmd.init_with_program(
14+p
15+)
16+end
17+18+@temp_dir = Dir.mktmpdir("jekyll_clean_test")
19+@destination = File.join(@temp_dir, "_site")
20+Dir.mkdir(@destination) || flunk("Could not make directory #{@destination}")
21+@standard_options = {
22+"port" => 4000,
23+"host" => "localhost",
24+"baseurl" => "",
25+"detach" => false,
26+"source" => @temp_dir,
27+"destination" => @destination,
28+}
29+30+simple_page = <<-HTML.gsub(%r!^\s*!, "")
31+ <!DOCTYPE HTML>
32+ <html lang="en-US">
33+ <head>
34+ <meta charset="UTF-8">
35+ <title>Hello World</title>
36+ </head>
37+ <body>
38+ <p>Hello! I am a simple web page.</p>
39+ </body>
40+ </html>
41+ HTML
42+43+File.write(File.join(@destination, "hello.html"), simple_page)
44+45+@site = instance_double(Jekyll::Site, :jekyll_site)
46+allow(Jekyll::Site).to receive(:new).and_return(@site)
47+end
48+49+teardown do
50+FileUtils.remove_entry_secure(@temp_dir, true)
51+end
52+53+should "call Site#cleanup" do
54+expect(@site).to receive(:cleanup)
55+@merc.execute(:clean, @standard_options)
56+end
57+58+context "with the keep_files option" do
59+setup do
60+@standard_options["keep_files"] = %w(keep)
61+@keep_dir = File.join(@temp_dir, "_site/keep")
62+63+keep_page = <<-HTML.gsub(%r!^\s*!, "")
64+ <!DOCTYPE HTML>
65+ <html lang="en-US">
66+ <head>
67+ <meta charset="UTF-8">
68+ <title>Page to Keep</title>
69+ </head>
70+ <body>
71+ <p>This page is to keep.</p>
72+ </body>
73+ </html>
74+ HTML
75+76+Dir.mkdir(@keep_dir) || flunk("Could not make directory #{@keep_dir}")
77+File.write(File.join(@keep_dir, "keep.html"), keep_page)
78+79+allow(Jekyll::Site).to receive(:new).and_call_original
80+end
81+82+should "keep the specified files and directories" do
83+@merc.execute(:clean, @standard_options)
84+assert_path_exists(File.join(@keep_dir, "keep.html"))
85+end
86+end
87+end
88+end
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。