Sha256: cb898440823350524db18335689a3a6265ba506265963f6bc906ebc5971b4c81

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'assert'

class Sanford::ExceptionHandler

  class BaseTest < Assert::Context
    desc "Sanford::Server::ExceptionHandler"
    setup do
      @exception = nil
      begin
        raise "test"
      rescue Exception => @exception
      end
      @logger = Sanford::NullLogger.new
      @exception_handler = Sanford::ExceptionHandler.new(@exception, @logger)
    end
    subject{ @exception_handler }

    should have_instance_methods :exception

    should "have built a 500 Sanford::Response" do
      response = subject.response

      assert_instance_of Sanford::Protocol::Response, response
      assert_equal 500, response.status.code
      assert_equal "An unexpected error occurred.", response.status.message
    end
  end

  class BadRequestTest < BaseTest
    desc "with a Sanford::BadRequest exception"
    setup do
      @exception = nil
      begin
        raise Sanford::Protocol::BadMessageError, "test"
      rescue Exception => @exception
      end
      @exception_handler = Sanford::ExceptionHandler.new(@exception, @logger)
    end

    should "have built a 400 Sanford::Response" do
      response = subject.response

      assert_instance_of Sanford::Protocol::Response, response
      assert_equal 400, response.status.code
      assert_equal "test", response.status.message
    end
  end

  class NotFoundTest < BaseTest
    desc "with a Sanford::NotFound exception"
    setup do
      @exception = nil
      begin
        raise Sanford::NotFoundError, "test"
      rescue Exception => @exception
      end
      @exception_handler = Sanford::ExceptionHandler.new(@exception, @logger)
    end

    should "have built a 404 Sanford::Response" do
      response = subject.response

      assert_instance_of Sanford::Protocol::Response, response
      assert_equal 404, response.status.code
      assert_equal nil, response.status.message
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sanford-0.1.0 test/unit/exception_handler_test.rb