File: handler_spec.cr

package info (click to toggle)
crystal 1.6.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,956 kB
  • sloc: javascript: 1,712; sh: 592; cpp: 541; makefile: 243; ansic: 119; python: 105; xml: 32
file content (28 lines) | stat: -rw-r--r-- 659 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require "spec"
require "http/server/handler"

private class EmptyHTTPHandler
  include HTTP::Handler

  def call(context)
    call_next(context)
  end
end

describe HTTP::Handler do
  it "responds with not found if there's no next handler" do
    io = IO::Memory.new
    request = HTTP::Request.new("GET", "/")
    response = HTTP::Server::Response.new(io)
    context = HTTP::Server::Context.new(request, response)

    handler = EmptyHTTPHandler.new
    handler.call(context)
    response.close

    io.rewind
    response = HTTP::Client::Response.from_io(io)
    response.status_code.should eq(404)
    response.body.should eq("404 Not Found\n")
  end
end