require 'assert' require 'deas/server' require 'logger' require 'deas/router' module Deas::Server class BaseTests < Assert::Context desc "Deas::Server" setup do @server_class = Class.new{ include Deas::Server } end subject{ @server_class } should have_imeths :new, :configuration # DSL for sinatra-based settings should have_imeths :env, :root, :public_folder, :views_folder should have_imeths :dump_errors, :method_override, :sessions, :show_exceptions should have_imeths :static_files, :reload_templates, :default_charset # DSL for server handling settings should have_imeths :init, :error, :template_helpers, :template_helper? should have_imeths :use, :set, :view_handler_ns, :verbose_logging, :logger should have_imeths :get, :post, :put, :patch, :delete should have_imeths :redirect, :route, :url, :url_for # DSL for server routing settings should have_imeths :router, :view_handler_ns should have_imeths :url, :url_for should have_imeths :get, :post, :put, :patch, :delete should have_imeths :route, :redirect should "allow setting it's configuration options" do config = subject.configuration subject.env 'staging' assert_equal 'staging', config.env subject.root '/path/to/root' assert_equal '/path/to/root', config.root.to_s subject.public_folder '/path/to/public' assert_equal '/path/to/public', config.public_folder.to_s subject.views_folder '/path/to/views' assert_equal '/path/to/views', config.views_folder.to_s subject.dump_errors true assert_equal true, config.dump_errors subject.method_override false assert_equal false, config.method_override subject.sessions false assert_equal false, config.sessions subject.show_exceptions true assert_equal true, config.show_exceptions subject.static_files false assert_equal false, config.static_files subject.reload_templates true assert_equal true, config.reload_templates assert_equal 0, config.init_procs.size init_proc = proc{ } subject.init(&init_proc) assert_equal 1, config.init_procs.size assert_equal init_proc, config.init_procs.first assert_equal 0, config.error_procs.size error_proc = proc{ } subject.error(&error_proc) assert_equal 1, config.error_procs.size assert_equal error_proc, config.error_procs.first subject.use 'MyMiddleware' assert_equal [ ['MyMiddleware'] ], config.middlewares subject.set :testing_set_meth, 'it works!' assert_equal({ :testing_set_meth => 'it works!'}, config.settings) stdout_logger = Logger.new(STDOUT) subject.logger stdout_logger assert_equal stdout_logger, config.logger subject.default_charset 'latin1' assert_equal 'latin1', config.default_charset end should "add and query helper modules" do subject.template_helpers(helper_module = Module.new) assert subject.template_helper?(helper_module) end should "have a router by default and allow overriding it" do assert_kind_of Deas::Router, subject.router new_router = Deas::Router.new subject.router new_router assert_same new_router, subject.router end end end