wireapp/hspec-wai

Name: hspec-wai

Owner: Wire Swiss GmbH

Description: Helpers to test WAI application with Hspec

Created: 2018-05-12 13:32:25.0

Updated: 2018-05-12 13:32:27.0

Pushed: 2018-05-12 13:53:41.0

Homepage:

Size: 134

Language: Haskell

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

hspec-wai Build Status

Helpers to test WAI applications with Hspec

Example
LANGUAGE OverloadedStrings, QuasiQuotes #-}
le Main (main) where

rt           Test.Hspec
rt           Test.Hspec.Wai
rt           Test.Hspec.Wai.JSON

rt           Network.Wai (Application)
rt qualified Web.Scotty as S
rt           Data.Aeson (Value(..), object, (.=))

 :: IO ()
 = hspec spec

:: IO Application
= S.scottyApp $ do
get "/" $ do
S.text "hello"

get "/some-json" $ do
S.json $ object ["foo" .= Number 23, "bar" .= Number 42]

 :: Spec
 = with app $ do
scribe "GET /" $ do
it "responds with 200" $ do
  get "/" `shouldRespondWith` 200

it "responds with 'hello'" $ do
  get "/" `shouldRespondWith` "hello"

it "responds with 200 / 'hello'" $ do
  get "/" `shouldRespondWith` "hello" {matchStatus = 200}

it "has 'Content-Type: text/plain; charset=utf-8'" $ do
  get "/" `shouldRespondWith` 200 {matchHeaders = ["Content-Type" <:> "text/plain; charset=utf-8"]}

scribe "GET /some-json" $ do
it "responds with some JSON" $ do
  get "/some-json" `shouldRespondWith` [json|{foo: 23, bar: 42}|]
Documentation

See hspec-wai on hackage: https://hackage.haskell.org/package/hspec-wai

Contributing
  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.