Welcome to the CHICKEN Scheme pasting service

test-handler macro for testing spiffy handlers pasted by DerGuteMoritz on Wed Aug 31 19:54:22 2011

(testing-handler pox-handler)

(test-handler (POST "/users/max/tasks" "* foo")
              ((accept #(text/x-downtime)))
              => resp
              (test 200 (response-code resp)))

(test-handler (GET "/users/max/tasks?omit-origin=true")
              ((accept #(text/x-downtime)))
              => resp
              (test 200 (response-code resp))
              (let ((body (read-string #f (response-port resp))))
                (test "* foo #1  \n\n" body)))

current test-handler implementation added by DerGuteMoritz on Wed Aug 31 20:08:58 2011

(define-syntax test-handler
  (syntax-rules (=>)
    ((_ (method uri body)
        (additional-headers ...)
        => response
        tests ...)
     (parameterize ((current-request
                     (make-request uri: (uri-reference uri)
                                   method: 'method
                                   port: (open-input-string (or body ""))
                                   headers: (headers '(additional-headers ...)
                                                     (if body
                                                         (headers `((content-length ,(string-length body))))
                                                         (headers '())))))
                    (current-response (make-response port: (open-output-string))))
  
       ((testing-handler) void)
  
       (let* ((response (get-output-string (response-port (current-response))))
              (response (call-with-input-string response read-response)))
         tests ...)))

    ((_ (method uri)
        (additional-headers ...)
        => response
        tests ...)
     (test-handler (method uri #f)
                   (additional-headers ...)
                   => response
                   tests ...))))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which procedure can be used to check whether its argument is a procedure?
Visually impaired? Let me spell it for you (wav file) download WAV