test/test_site.rb in gollum-site-0.0.6 vs test/test_site.rb in gollum-site-0.1.0
- old
+ new
@@ -1,24 +1,28 @@
require File.join(File.dirname(__FILE__), *%w[helper])
context "Site" do
setup do
- @wiki = Gollum::Wiki.new(testpath("examples/test_site.git"))
- @site = Gollum::Site.new(@wiki,
- {:output_path => testpath("examples/site")})
- @site.generate("master")
+ 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
- assert_equal(["/Home.html",
- "/Page-One.html",
- "/Page1.html",
- "/Page2.html",
- "/static",
- "/static/static.jpg",
- "/static/static.txt"],
- Dir[@site.output_path + "/**/*"].map { |f| f.sub(@site.output_path, "") })
+ 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(["<html><p>Site test\n",
@@ -35,46 +39,57 @@
test "render page with layout from sub dir" do
page_path = File.join(@site.output_path, "Page2.html")
assert_equal(["<html><body><p>Site test</p></body></html>\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(["<ul><li>page.html</li></ul>\n"], File.open(page_path).readlines)
+ end
+
teardown do
FileUtils.rm_r(@site.output_path)
end
end
-context "Site inherits default layout" do
+context "Preview" do
setup do
- @wiki = Gollum::Wiki.new(testpath("examples/test_site_no_layout.git"))
- @site = Gollum::Site.new(@wiki,
- {:output_path => testpath("examples/site")})
- @site.generate("master")
+ @path = testpath("examples/uncommitted_untracked_changes")
+ # Add untracked file
+ File.open(@path + '/Foo.md', 'w') { |f| f.write("Bar") }
+ # Modify tracked file
+ File.open(@path + '/Home.md', 'w') { |f| f.write("Hello World\nHello World") }
+ @site = Gollum::Site.new(@path, {
+ :output_path => testpath("examples/site"),
+ :version => :working
+ })
+ @site.generate()
end
- test "check that default layout is used" do
- assert File.exists?(File.join(@site.output_path, "css"))
- assert File.exists?(File.join(@site.output_path, "javascript"))
+ test "working site has Home.html and Foo.html" do
+ diff = Dir[@site.output_path + "/**/*"].
+ map { |f| f.sub(@site.output_path, "") } - ["/Home.html",
+ "/Foo.html",
+ "/Bar.html"]
+ assert_equal([], diff)
end
- teardown do
- FileUtils.rm_r(@site.output_path)
+ test "working site Home.html content is uncommitted version" do
+ data = IO.read(::File.join(@site.output_path, "Home.html"))
+ assert_equal("<p>Hello World\nHello World</p>", data)
end
-end
-context "Site does not inherit default layout" do
- setup do
- @wiki = Gollum::Wiki.new(testpath("examples/test_site_no_layout.git"))
- @site = Gollum::Site.new(@wiki,
- {:output_path => testpath("examples/site"),
- :include_default_layout => false})
- @site.generate("master")
+ test "one item can be updated" do
+ File.open(@path + '/Foo.md', 'w') { |f| f.write("Baz") }
+ @site.update_working_item('Foo.md')
+ data = IO.read(::File.join(@site.output_path, "Foo.html"))
+ assert_equal("<p>Baz</p>", data)
end
- test "check that default layout is used" do
- assert !File.exists?(File.join(@site.output_path, "css"))
- assert !File.exists?(File.join(@site.output_path, "javascript"))
- 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)
end
end