require 'assert' require 'deas/runner' require 'test/support/view_handlers' class Deas::Runner class UnitTests < Assert::Context desc "Deas::Runner" setup do @runner = Deas::Runner.new(TestViewHandler) end subject{ @runner } should have_readers :handler_class, :handler should have_readers :request, :response, :params, :logger, :session should have_imeths :halt, :redirect, :content_type, :status, :headers should have_imeths :render, :partial, :send_file should "know its handler and handler class" do assert_equal TestViewHandler, subject.handler_class assert_instance_of subject.handler_class, subject.handler end should "not set any settings" do assert_nil subject.request assert_nil subject.response assert_nil subject.params assert_nil subject.logger assert_nil subject.session end should "not implement any actions" do assert_raises(NotImplementedError){ subject.halt } assert_raises(NotImplementedError){ subject.redirect } assert_raises(NotImplementedError){ subject.content_type } assert_raises(NotImplementedError){ subject.status } assert_raises(NotImplementedError){ subject.headers } assert_raises(NotImplementedError){ subject.render } assert_raises(NotImplementedError){ subject.partial } assert_raises(NotImplementedError){ subject.send_file } end end class NormalizedParamsTests < UnitTests desc "NormalizedParams" should "convert any non-Array or non-Hash values to strings" do exp_params = { 'nil' => '', 'int' => '42', 'str' => 'string' } assert_equal exp_params, normalized({ 'nil' => nil, 'int' => 42, 'str' => 'string' }) end should "recursively convert array values to strings" do exp_params = { 'array' => ['', '42', 'string'] } assert_equal exp_params, normalized({ 'array' => [nil, 42, 'string'] }) end should "recursively convert hash values to strings" do exp_params = { 'values' => { 'nil' => '', 'int' => '42', 'str' => 'string' } } assert_equal exp_params, normalized({ 'values' => { 'nil' => nil, 'int' => 42, 'str' => 'string' } }) end should "convert any non-string hash keys to string keys" do exp_params = { 'nil' => '', 'vals' => { '42' => 'int', 'str' => 'string' } } assert_equal exp_params, normalized({ 'nil' => '', :vals => { 42 => :int, 'str' => 'string' } }) end private def normalized(params) TestNormalizedParams.new(params).value end class TestNormalizedParams < Deas::Runner::NormalizedParams def file_type?(value); false; end end end end