here = File.expand_path File.dirname(__FILE__) require "#{here}/spec_helper" require "deck/rack_app" require "rack/test" module Deck describe RackApp do include Rack::Test::Methods include Files def assert_ok unless last_response.ok? status, errors = last_response.status, last_response.errors assert(last_response.inspect) { errors.empty? && status == 200 } end end def here File.expand_path File.dirname(__FILE__) end describe "app with middleware" do def app @app ||= Deck::RackApp.build [] end def apps @apps ||= begin [app].tap do |apps| while (next_app = apps.last.instance_variable_get(:@app)) apps << next_app end end end end def raw_app apps.last end it "middleware chain resolves to the real app" do assert { raw_app.is_a? Deck::RackApp } end it "serves up deck.js source files" do deckjs_core_path = "deck.js/core/deck.core.js" get "/#{deckjs_core_path}" path = "#{here}/../public/#{deckjs_core_path}" expected_body = begin File.read(path, :encoding => last_response.body.encoding) rescue NoMethodError # fix for Ruby 1.8.7 File.read(path) end assert { last_response.body == expected_body } end it "finds coderay.css" do get "/coderay.css" assert_ok end end describe "raw app" do def app @app ||= Deck::RackApp.new [] end it "serves a .md file as a deck.js HTML file" do foo_path = file "foo.md" @app = Deck::RackApp.new [foo_path] get "/" assert_ok assert { last_response.body.include? "contents of foo.md" } assert { last_response.body.include? "