# encoding: UTF-8 require "spec_helper" require "rack/test" describe Mango::Application do include Rack::Test::Methods def app Mango::Application end ################################################################################################# describe "GET /robots.txt" do before(:each) do get "/robots.txt" end it "returns 200 status code" do last_response.should be_ok end it "sends the correct Content-Type header" do last_response["Content-Type"] == "text/plain" end it "sends the correct body content" do last_response.body.should == <<-EXPECTED User-agent: * Disallow: /cgi-bin/ EXPECTED end end ################################################################################################# describe "GET /images/" do before(:each) do get "/images/" end it "returns 200 status code" do last_response.should be_ok end it "sends the correct Content-Type header" do last_response["Content-Type"] == "text/html" end it "sends the correct body content" do last_response.body.should == <<-EXPECTED /themes/default/public/images/index.html

/themes/default/public/images/index.html

EXPECTED end end ################################################################################################# describe "GET /" do before(:each) do @file_name = File.join(Mango::Application.public, "index.html") @expected_body = <<-EXPECTED /themes/default/public/index.html

/themes/default/public/index.html

EXPECTED File.open(@file_name, "w") { |f| f.write(@expected_body) } get "/" end after(:each) do File.delete(@file_name) end it "returns 200 status code" do last_response.should be_ok end it "sends the correct Content-Type header" do last_response["Content-Type"] == "text/html" end it "sends the correct body content" do last_response.body.should == @expected_body end end ################################################################################################# describe "GET /images/ripe-mango.jpg" do before(:each) do get "/images/ripe-mango.jpg" end it "returns 200 status code" do last_response.should be_ok end it "sends the correct Content-Type header" do last_response["Content-Type"] == "image/jpeg" end it "sends the correct body content" do content_path = File.join(Mango::Application.public, "images", "ripe-mango.jpg") last_response.body.should == File.open(content_path, "rb").read end end ################################################################################################# describe "GET /override" do before(:each) do get "/override" end it "returns 200 status code" do last_response.should be_ok end it "sends the correct Content-Type header" do last_response["Content-Type"] == "text/html" end it "sends the correct body content" do last_response.body.should == <<-EXPECTED /themes/default/public/override

/themes/default/public/override

EXPECTED end end ################################################################################################# # see http://bit.ly/9kLBDx describe "GET /images/" do before(:each) do get "/images/" end it "returns 200 status code" do last_response.should be_ok end it "sends the correct Content-Type header" do last_response["Content-Type"] == "text/html" end it "sends the correct body content" do last_response.body.should == <<-EXPECTED /themes/default/public/images/index.html

/themes/default/public/images/index.html

EXPECTED end end ################################################################################################# describe "GET /../security_hole.txt" do before(:each) do get "/../security_hole.txt" end it "returns 404 status code" do last_response.should be_not_found end it "sends the correct Content-Type header" do last_response["Content-Type"] == "text/html" end it "sends the correct body content" do last_response.body.should == <<-EXPECTED 404 Page

Page not found

EXPECTED end end end