sydtest-wai 0.1.0.0 → 0.2.0.0
raw patch · 5 files changed
+25/−37 lines, 5 filesdep ~sydtestPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: sydtest
API changes (from Hackage documentation)
- Test.Syd.Wai: wit :: forall env e outers. (HasCallStack, IsTest (WaiClient env -> IO e), Arg1 (WaiClient env -> IO e) ~ (), Arg2 (WaiClient env -> IO e) ~ WaiClient env) => String -> WaiClientM env e -> TestDefM outers (WaiClient env) ()
- Test.Syd.Wai.Def: wit :: forall env e outers. (HasCallStack, IsTest (WaiClient env -> IO e), Arg1 (WaiClient env -> IO e) ~ (), Arg2 (WaiClient env -> IO e) ~ WaiClient env) => String -> WaiClientM env e -> TestDefM outers (WaiClient env) ()
+ Test.Syd.Wai.Client: instance Test.Syd.Run.IsTest (Test.Syd.Wai.Client.WaiClientM env ())
+ Test.Syd.Wai.Client: instance Test.Syd.Run.IsTest (outerArgs -> Test.Syd.Wai.Client.WaiClientM env ())
Files
- src/Test/Syd/Wai.hs +1/−2
- src/Test/Syd/Wai/Client.hs +12/−0
- src/Test/Syd/Wai/Def.hs +0/−23
- sydtest-wai.cabal +2/−2
- test/Test/Syd/WaiSpec.hs +10/−10
src/Test/Syd/Wai.hs view
@@ -13,7 +13,7 @@ -- > spec = -- > waiClientSpec exampleApplication $ -- > describe "get" $--- > wit "can GET the root and get a 200" $ do+-- > it "can GET the root and get a 200" $ do -- > resp <- get "/" -- > liftIO $ responseStatus resp `shouldBe` ok200 module Test.Syd.Wai@@ -30,7 +30,6 @@ waiClientSpecWith, waiClientSpecWithSetupFunc, waiClientSpecWithSetupFunc',- wit, -- ** A test suite that uses a single HTTP manager accross tests managerSpec,
src/Test/Syd/Wai/Client.hs view
@@ -1,5 +1,7 @@ {-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-} module Test.Syd.Wai.Client where@@ -53,6 +55,16 @@ MonadState WaiClientState, MonadFail )++instance IsTest (WaiClientM env ()) where+ type Arg1 (WaiClientM env ()) = ()+ type Arg2 (WaiClientM env ()) = WaiClient env+ runTest func = runTest (\() -> func)++instance IsTest (outerArgs -> WaiClientM env ()) where+ type Arg1 (outerArgs -> WaiClientM env ()) = outerArgs+ type Arg2 (outerArgs -> WaiClientM env ()) = WaiClient env+ runTest func = runTest (\outerArgs waiClient -> runWaiClientM waiClient (func outerArgs)) -- | For compatibility with @hspec-wai@ type WaiSession st a = WaiClientM st a
src/Test/Syd/Wai/Def.hs view
@@ -7,7 +7,6 @@ module Test.Syd.Wai.Def where -import GHC.Stack (HasCallStack) import Network.HTTP.Client as HTTP import Network.Socket (PortNumber) import Network.Wai as Wai@@ -54,28 +53,6 @@ waiClientPort = p } pure client---- | Define a test in the 'WaiClientM site' monad instead of 'IO'.------ Example usage:------ > waiClientSpec exampleApplication $ do--- > describe "/" $ do--- > wit "works with a get" $--- > get "/" `shouldRespondWith` 200--- > wit "works with a post" $--- > post "/" `shouldRespondWith` ""-wit ::- forall env e outers.- ( HasCallStack,- IsTest (WaiClient env -> IO e),- Arg1 (WaiClient env -> IO e) ~ (),- Arg2 (WaiClient env -> IO e) ~ WaiClient env- ) =>- String ->- WaiClientM env e ->- TestDefM outers (WaiClient env) ()-wit s f = it s ((\cenv -> runWaiClientM cenv f) :: WaiClient env -> IO e) -- | Run a given 'Wai.Application' around every test. --
sydtest-wai.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: sydtest-wai-version: 0.1.0.0+version: 0.2.0.0 synopsis: A wai companion library for sydtest category: Testing homepage: https://github.com/NorfairKing/sydtest#readme@@ -41,7 +41,7 @@ , mtl , network , pretty-show- , sydtest+ , sydtest >=0.3.0.0 , text , time , wai
test/Test/Syd/WaiSpec.hs view
@@ -18,43 +18,43 @@ responseBody resp `shouldBe` body waiClientSpec exampleApplication $ do describe "get" $ do- wit "can GET the root and get a 200" $ do+ it "can GET the root and get a 200" $ do resp <- get "/" liftIO $ responseStatus resp `shouldBe` ok200- wit "can GET the /redirect and get a 303 with a location header" $ do+ it "can GET the /redirect and get a 303 with a location header" $ do resp <- get "/redirect" liftIO $ case lookup "Location" $ responseHeaders resp of Nothing -> expectationFailure "should have found a location header" Just l -> l `shouldBe` "/"- wit "carries cookies correctly" $ do+ it "carries cookies correctly" $ do _ <- get "/set-cookie" resp <- get "/expects-cookie" liftIO $ responseStatus resp `shouldBe` ok200 describe "post" $- wit "can POST the root and get a 200" $ do+ it "can POST the root and get a 200" $ do resp <- post "/" "hello world" liftIO $ responseStatus resp `shouldBe` ok200 liftIO $ responseBody resp `shouldBe` "hello world" describe "put" $- wit "can PUT the root and get a 200" $ do+ it "can PUT the root and get a 200" $ do resp <- put "/" "hello world" liftIO $ responseStatus resp `shouldBe` ok200 liftIO $ responseBody resp `shouldBe` "hello world" describe "patch" $- wit "can PATCH the root and get a 200" $ do+ it "can PATCH the root and get a 200" $ do resp <- patch "/" "hello world" liftIO $ responseStatus resp `shouldBe` ok200 liftIO $ responseBody resp `shouldBe` "hello world" describe "options" $- wit "can OPTIONS the root and get a 200" $ do+ it "can OPTIONS the root and get a 200" $ do resp <- options "/" liftIO $ responseStatus resp `shouldBe` ok200 describe "request" $- wit "can make a weird request" $ do+ it "can make a weird request" $ do resp <- request "HELLO" "" [] "" liftIO $ responseStatus resp `shouldBe` ok200 describe "shouldRespondWith" $ do- wit "works with a number" $+ it "works with a number" $ get "/" `shouldRespondWith` 200- wit "works with a string" $+ it "works with a string" $ get "/" `shouldRespondWith` ""