test/integration/ruby_slippers_test.rb in ruby-slippers-0.0.13 vs test/integration/ruby_slippers_test.rb in ruby-slippers-0.0.25

- old
+ new

@@ -1,77 +1,70 @@ require 'support/test_helper' require 'date' -context RubySlippers::Engine do - setup do - @config = RubySlippers::Engine::Config.new(:markdown => true, :author => AUTHOR, :url => URL) - @ruby_slippers = Rack::MockRequest.new(RubySlippers::Engine::App.new(@config)) - RubySlippers::Engine::Paths[:articles] = "test/fixtures/articles" - RubySlippers::Engine::Paths[:pages] = "test/fixtures/pages" - RubySlippers::Engine::Paths[:templates] = "test/fixtures/templates" - end +module RubySlippers + context Engine do + setup do + @config = RubySlippers::Engine::Config.new(:markdown => true, :author => AUTHOR, :url => URL) + @ruby_slippers = Rack::MockRequest.new(RubySlippers::Engine::App.new(@config)) + + RubySlippers::Engine::Paths[:articles] = "test/fixtures/articles" + if File.expand_path("../../", __FILE__) =~ /engine/ + RubySlippers::Engine::Paths[:templates] = "test/fixtures/templates" + RubySlippers::Engine::Paths[:pages] = "test/fixtures/pages" + end + end - context "GET /" do - setup { @ruby_slippers.get('/') } + context "GET /" do + setup { @ruby_slippers.get('/') } - 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 articles") { topic.body }.includes_elements("#articles li", 2) - should("include an archive") { topic.body }.includes_elements("#archives li", 2) + 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 3 articles"){ topic.body }.includes_elements("article", 3) - context "with no articles" do - setup { Rack::MockRequest.new(RubySlippers::Engine::App.new(@config.merge(:ext => 'oxo'))).get('/') } + context "with no articles" do + setup { Rack::MockRequest.new(RubySlippers::Engine::App.new(@config.merge(:ext => 'oxo'))).get('/') } - asserts("body is not empty") { not topic.body.empty? } - asserts("returns a 200") { topic.status }.equals 200 - end + asserts("body is not empty") { not topic.body.empty? } + asserts("returns a 200") { topic.status }.equals 200 + end - context "with a user-defined to_html" do - setup do - @config[:to_html] = lambda do |path, page, binding| - ERB.new(File.read("#{path}/#{page}.rhtml")).result(binding) + context "with a user-defined to_html" do + setup do + @config[:to_html] = lambda do |path, page, binding| + ERB.new(File.read("#{path}/#{page}.rhtml")).result(binding) + end + @ruby_slippers.get('/') end - @ruby_slippers.get('/') + + 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 3 articles"){ topic.body }.includes_elements("article", 3) + 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 { @ruby_slippers.get('/about') } 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", 2) - 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 { @ruby_slippers.get('/about') } - asserts("returns a 200") { topic.status }.equals 200 - asserts("body is not empty") { not topic.body.empty? } - should("have access to @articles") { topic.body }.includes_html("#count" => /4/) - end + context "GET to an unknown route with a custom error" do + setup do + @config[:error] = lambda {|code| "error: #{code}" } + @ruby_slippers.get('/unknown') + end - context "GET to an unknown route with a custom error" do - setup do - @config[:error] = lambda {|code| "error: #{code}" } - @ruby_slippers.get('/unknown') + should("returns a 404") { topic.status }.equals 404 + should("return the custom error") { topic.body }.equals "error: 404" 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 { @ruby_slippers.delete('/invalid') } - should("returns a 400") { topic.status }.equals 400 - end - - context "GET /index?param=testparam (get parameter)" do - setup { @ruby_slippers.get('/index?param=testparam') } - asserts("returns a 200") { topic.status }.equals 200 - asserts("content type is set properly") { topic.content_type }.equals "text/html" - asserts("contain the env variable") { topic.body }.includes_html("p" => /env passed: true/) - asserts("access the http get parameter") { topic.body }.includes_html("p" => /request method type: GET/) - asserts("access the http parameter name value pair") { topic.body }.includes_html("p" => /request name value pair: param=testparam/) + context "Request is invalid" do + setup { @ruby_slippers.delete('/invalid') } + should("returns a 400") { topic.status }.equals 400 + end end end