Safe Haskell | None |
---|
Have a look at the README for an example of how to use this library.
- data WaiSession a
- type WaiExpectation = WaiSession ()
- get :: ByteString -> WaiSession SResponse
- post :: ByteString -> ByteString -> WaiSession SResponse
- put :: ByteString -> ByteString -> WaiSession SResponse
- patch :: ByteString -> ByteString -> WaiSession SResponse
- delete :: ByteString -> WaiSession SResponse
- request :: Method -> ByteString -> ByteString -> WaiSession SResponse
- shouldRespondWith :: WaiSession SResponse -> ResponseMatcher -> WaiExpectation
- data ResponseMatcher = ResponseMatcher {
- matchStatus :: Int
- matchHeaders :: [Header]
- matchBody :: Maybe ByteString
- liftIO :: MonadIO m => forall a. IO a -> m a
- with :: IO a -> SpecWith a -> Spec
Types
data WaiSession a Source
A WAI test
session that carries the Application
under test an some client state.
type WaiExpectation = WaiSession ()Source
An expectation in the WaiSession
monad. Failing expectations are
communicated through exceptions (similar to Expectation
and
Assertion
).
Performing requests
get :: ByteString -> WaiSession SResponseSource
Perform a GET
request to the application under test.
post :: ByteString -> ByteString -> WaiSession SResponseSource
Perform a POST
request to the application under test.
put :: ByteString -> ByteString -> WaiSession SResponseSource
Perform a PUT
request to the application under test.
patch :: ByteString -> ByteString -> WaiSession SResponseSource
Perform a PATCH
request to the application under test.
delete :: ByteString -> WaiSession SResponseSource
Perform a DELETE
request to the application under test.
request :: Method -> ByteString -> ByteString -> WaiSession SResponseSource
Perform a request to the application under test, with specified HTTP method, request path and body.
Matching on the response
shouldRespondWith :: WaiSession SResponse -> ResponseMatcher -> WaiExpectationSource
Set the expectation that a response matches a specified ResponseMatcher
.
A ResponseMatcher
matches a response if:
- the specified status matches the HTTP response status code
- the specified body (if any) matches the response body
- the response has all of the specified
Header
fields (the response may have arbitrary additionalHeader
fields)
You can use ResponseMatcher
's (broken) Num
instance to match for a HTTP
status code:
get "/" `shouldRespondWith` 200 -- matches if status is 200
You can use ResponseMatcher
's IsString
instance to match for a HTTP
status 200
and a body:
get "/" `shouldRespondWith` "foo" -- matches if body is "foo" and status is 200
If you want to match for a different HTTP status, you can use record update
notation to specify matchStatus
explicitly:
get "/" `shouldRespondWith` "foo" {matchStatus = 404} -- matches if body is "foo" and status is 404
If you want to require a specific header field you can specify
matchHeaders
:
get "/" `shouldRespondWith` "foo" {matchHeaders = "Content-Type: text/plain"} -- matches if body is "foo", status is 200 and ther is a header field "Content-Type: text/plain"
data ResponseMatcher Source
ResponseMatcher | |
|