require File.join(File.dirname(__FILE__), *%w[helper]) context "Site" do setup do path = testpath("examples/test_site.git") @site = Gollum::Site.new(path,{ :output_path => testpath("examples/site"), :version => "master" }) @site.generate() end test "generate static site" do diff = Dir[@site.output_path + "/**/*"]. map { |f| f.sub(@site.output_path, "") } - ["/Home.html", "/Page-One.html", "/Page1.html", "/Page2.html", "/page.html", "/static", "/static/static.jpg", "/static/static.txt"] assert_equal([], diff) end test "render page with layout and link" do home_path = File.join(@site.output_path, "Home.html") assert_equal(["
Site test\n", "Page1#test\n", "Page with anchor
\n"], File.open(home_path).readlines) end test "render page with layout from parent dir" do page_path = File.join(@site.output_path, "Page1.html") assert_equal(["Site test
\n"], File.open(page_path).readlines) end test "render page with layout from sub dir" do page_path = File.join(@site.output_path, "Page2.html") assert_equal(["Site test
\n"], File.open(page_path).readlines) end test "page.path is available on template" do page_path = File.join(@site.output_path, "page.html") assert_equal(["Hello World\nHello World
", data) end teardown do # Remove untracked file FileUtils.rm(@path + '/Foo.md') # Reset tracked file File.open(@path + '/Home.md', 'w') { |f| f.write("Hello World\n") } FileUtils.rm_r(@site.output_path) FileUtils.rm_r(@path + '/.git') end end context "Ignorefile" do setup do @path = testpath("examples/test_ignorefile.git") @repo = Grit::Repo.init(@path) File.open(@path + '/.gollumignore', 'w') { |f| f.write("Ignore*.*") } File.open(@path + '/Home.md', 'w') { |f| f.write("Home file.") } File.open(@path + '/IgnoreRepo.md', 'w') { |f| f.write("Ignore this repo file.") } @repo.add(@path) @repo.commit_all("Initial commit.") # Add untracked working files File.open(@path + '/IgnoreWorking.md', 'w') { |f| f.write("Ignore this working file.") } File.open(@path + '/UseWorking.md', 'w') { |f| f.write("Use me.") } @site = Gollum::Site.new(@path, { :output_path => testpath("examples/site"), :version => :working }) @site.generate() end test "working site has no ignored files" do diff = Dir[@site.output_path + "/**/*"]. map { |f| f.sub(@site.output_path, "") } assert_equal(["/Home.html", "/UseWorking.html"], diff) end teardown do FileUtils.rm_r(@site.output_path) FileUtils.rm_r(@path) end end context "Sanitization" do setup do @path = Dir.mktmpdir('gollumsite') @repo = Grit::Repo.init(@path) @repo.add("#{@path}") @repo.commit_all("Initial commit") # protocols File.open(@path + '/Home.md', 'w') { |f| f.write("Hello World") } # elements File.open(@path + '/Foo.md', 'w') { |f| f.write("