test/toto_test.rb in toto-0.4.5 vs test/toto_test.rb in toto-0.4.6

- old
+ new

@@ -40,10 +40,12 @@ asserts("returns a 200") { topic.status }.equals 200 asserts("body is not empty") { not topic.body.empty? } asserts("content type is set properly") { topic.content_type }.equals "text/html" should("include a couple of article") { topic.body }.includes_elements("#articles li", 3) should("include an archive") { topic.body }.includes_elements("#archives li", 2) + asserts("Etag header present") { topic.headers.include? "ETag" } + asserts("Etag header has a value") { not topic.headers["ETag"].empty? } end end context "GET /about" do setup { @toto.get('/about') } @@ -76,13 +78,18 @@ context "through /archive" do setup { @toto.get('/archive') } end end - context "GET to an unknown route" do - setup { @toto.get('/unknown') } + context "GET to an unknown route with a custom error" do + setup do + @config[:error] = lambda {|code| "error: #{code}" } + @toto.get('/unknown') + end + should("returns a 404") { topic.status }.equals 404 + should("return the custom error") { topic.body }.equals "error: 404" end context "Request is invalid" do setup { @toto.delete('/invalid') } should("returns a 400") { topic.status }.equals 400 @@ -182,10 +189,51 @@ end should("create a valid summary") { topic.summary.size }.within 75..80 end end + + context "in a subdirectory" do + context "with implicit leading forward slash" do + setup do + conf = Toto::Config.new({}) + conf.set(:prefix, "blog") + Toto::Article.new({ + :title => "Toto & The Wizard of Oz.", + :body => "#Chapter I\nhello, *stranger*." + }, conf) + end + + should("be in the directory") { topic.path }.equals Date.today.strftime("/blog/%Y/%m/%d/toto-and-the-wizard-of-oz/") + end + + context "with explicit leading forward slash" do + setup do + conf = Toto::Config.new({}) + conf.set(:prefix, "/blog") + Toto::Article.new({ + :title => "Toto & The Wizard of Oz.", + :body => "#Chapter I\nhello, *stranger*." + }, conf) + end + + should("be in the directory") { topic.path }.equals Date.today.strftime("/blog/%Y/%m/%d/toto-and-the-wizard-of-oz/") + end + + context "with explicit trailing forward slash" do + setup do + conf = Toto::Config.new({}) + conf.set(:prefix, "blog/") + Toto::Article.new({ + :title => "Toto & The Wizard of Oz.", + :body => "#Chapter I\nhello, *stranger*." + }, conf) + end + + should("be in the directory") { topic.path }.equals Date.today.strftime("/blog/%Y/%m/%d/toto-and-the-wizard-of-oz/") + end + end end context "using Config#set with a hash" do setup do conf = Toto::Config.new({}) @@ -205,11 +253,22 @@ end should("set the value to a proc") { topic[:to_html] }.respond_to :call end - context "extensions to the core Ruby library" do + context "testing individual configuration parameters" do + context "generate error pages" do + setup do + conf = Toto::Config.new({}) + conf.set(:error) {|code| "error code #{code}" } + conf + end + should("create an error page") { topic[:error].call(400) }.equals "error code 400" + end + end + + context "extensions to the core Ruby library" do should("respond to iso8601") { Date.today }.respond_to?(:iso8601) end end