test/howl_test.rb in howl-0.1.0 vs test/howl_test.rb in howl-0.2.0

- old
+ new

@@ -1,10 +1,10 @@ require 'teststrap' include Howl context "Site" do - setup { Site.new(fixture_path) } + setup { @site = Site.new(fixture_path) } should("find all pages") { topic.pages == Dir[fixture_path("pages/*")].map { |path| Page.new(path, topic) } } @@ -12,44 +12,72 @@ topic.write_to_disk topic.pages.map { |page| File.exist?(page.output_path) }.all? } -end -context "Page" do - setup { @site = Site.new(fixture_path) } + should("write out all posts") { + topic.write_to_disk + topic.posts.map { |post| + Dir[topic.path("site/posts") + "**/*"].map { |path| File.basename(path) }.include?(post.path.basename.to_s) + }.all? + } - context "simple.html" do - setup { Page.new(fixture_path("pages/simple.html"), @site) } + context "Page" do + context "simple.html" do + setup { Page.new(fixture_path("pages/simple.html"), @site) } - asserts(:data).equals({"title" => "This is a simple page"}) - asserts("#content") { topic.content.strip }.equals "<h1>{{title}}</h1>" - asserts("#rendered") { topic.render.strip }.equals "<h1>This is a simple page</h1>" + asserts("#content") { topic.content.strip }.equals "<h1>{{title}}</h1>" + asserts("#view is correct") { + topic.view == View.new(:site => topic.site, :title => "This is a simple page") + } + asserts("#rendered") { topic.render.strip }.equals "<h1>This is a simple page</h1>" - should("be able to find its output path") { - topic.output_path == (topic.site.path "site/simple.html") - } - end + should("be able to find its output path") { + topic.output_path == (topic.site.path "site/simple.html") + } + end - context "no_yaml.html" do - setup { Page.new(fixture_path("pages/no_yaml.html"), @site) } + context "no_yaml.html" do + setup { Page.new(fixture_path("pages/no_yaml.html"), @site) } - asserts(:data).equals({}) - asserts("#content") { topic.content.strip }.equals "This page has no YAML front-matter." - asserts("#rendered") { topic.render.strip }.equals "This page has no YAML front-matter." - end + asserts("#content") { topic.content.strip }.equals "This page has no YAML front-matter." + asserts("#view is correct") { + topic.view == View.new(:site => topic.site) + } + asserts("#rendered") { topic.render.strip }.equals "This page has no YAML front-matter." + end - context "has_template.html" do - setup { Page.new(fixture_path("pages/has_template.html"), @site) } + context "has_template.html" do + setup { Page.new(fixture_path("pages/has_template.html"), @site) } - asserts("#rendered") { topic.render.clean }.equals %Q[ + asserts("#rendered") { topic.render.clean }.equals %Q[ <html> <head><title>This page has a template</title></head> <h1>This page has a template</h1> <div> Hello world! </div> </html> - ].clean + ].clean + end end + + context "Post" do + setup { Post.new(fixture_path("posts/first_post.html"), @site) } + + asserts("date is equal to date from front matter") { + topic.date == Time.parse("2010/09/04") + } + + asserts(:output_path).equals { + topic.site.path("site/posts/2010/09/04") + "first_post.html" + } + + context "without a date" do + setup { Post.new(fixture_path("posts/no_date.html"), @site) } + + asserts("date is equal to file's mtime") { topic.date == File.mtime(topic.path) } + end + end end +