test/unit/sinatra_runner_tests.rb in deas-0.13.1 vs test/unit/sinatra_runner_tests.rb in deas-0.14.0

- old
+ new

@@ -1,23 +1,23 @@ require 'assert' require 'deas/sinatra_runner' require 'deas/template' -require 'test/support/fake_app' +require 'test/support/fake_sinatra_call' require 'test/support/view_handlers' class Deas::SinatraRunner class BaseTests < Assert::Context desc "Deas::SinatraRunner" setup do - @fake_sinatra_call = FakeApp.new + @fake_sinatra_call = FakeSinatraCall.new @runner = Deas::SinatraRunner.new(FlagViewHandler, @fake_sinatra_call) end subject{ @runner } - should have_imeths :run, :request, :response, :params, :logger, :halt - should have_imeths :render, :session, :redirect + should have_imeths :run, :request, :response, :params, :logger, :session + should have_imeths :halt, :redirect, :content_type, :status, :render should "return the sinatra_call's request with #request" do assert_equal @fake_sinatra_call.request, subject.request end @@ -40,25 +40,45 @@ should "call the sinatra_call's halt with #halt" do return_value = catch(:halt){ subject.halt('test') } assert_equal [ 'test' ], return_value end + should "call the sinatra_call's redirect method with #redirect" do + return_value = catch(:halt){ subject.redirect('http://google.com') } + expected = [ 302, { 'Location' => 'http://google.com' } ] + + assert_equal expected, return_value + end + + should "call the sinatra_call's content_type method using the default_charset" do + expected = @fake_sinatra_call.content_type('text/plain', :charset => 'utf-8') + assert_equal expected, subject.content_type('text/plain') + + expected = @fake_sinatra_call.content_type('text/plain', :charset => 'latin1') + assert_equal expected, subject.content_type('text/plain', :charset => 'latin1') + end + + should "call the sinatra_call's status to set the response status" do + assert_equal [422], subject.status(422) + end + + should "call the sinatra_call's status to set the response status" do + exp_headers = { + 'a-header' => 'some value', + 'other' => 'other' + } + assert_equal [exp_headers], subject.headers(exp_headers) + end + should "render the template with a :view local and the handler layouts with #render" do exp_handler = FlagViewHandler.new(subject) exp_layouts = FlagViewHandler.layouts exp_result = Deas::Template.new(@fake_sinatra_call, 'index', { :locals => { :view => exp_handler }, :layout => exp_layouts }).render assert_equal exp_result, subject.render('index') - end - - should "call the sinatra_call's redirect method with #redirect" do - return_value = catch(:halt){ subject.redirect('http://google.com') } - expected = [ 302, { 'Location' => 'http://google.com' } ] - - assert_equal expected, return_value end end class RunTests < BaseTests