packages feed

hspec-wai 0.9.0 → 0.9.1

raw patch · 5 files changed

+48/−21 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Test.Hspec.Wai.Internal: instance Control.Monad.Fail.MonadFail Test.Hspec.Wai.Internal.WaiSession
- Test.Hspec.Wai: liftIO :: MonadIO m => forall a. IO a -> m a
+ Test.Hspec.Wai: liftIO :: MonadIO m => IO a -> m a

Files

hspec-wai.cabal view
@@ -1,9 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.19.3.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.0. -- -- see: https://github.com/sol/hpack+--+-- hash: f19a5cdb12c601cb9d7b3f43cfab50f72b7e014ca5a9a1ba0c69aaa12b380931  name:             hspec-wai-version:          0.9.0+version:          0.9.1 homepage:         https://github.com/hspec/hspec-wai#readme bug-reports:      https://github.com/hspec/hspec-wai/issues license:          MIT@@ -15,11 +19,9 @@ maintainer:       Fujimura Daisuke <me@fujimuradaisuke.com>,                   Simon Hengel <sol@typeful.net> build-type:       Simple-cabal-version:    >= 1.10 category:         Testing synopsis:         Experimental Hspec support for testing WAI applications description:      Experimental Hspec support for testing WAI applications- extra-source-files:     changelog 
src/Test/Hspec/Wai/Internal.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE CPP #-} module Test.Hspec.Wai.Internal (   WaiExpectation , WaiSession(..)@@ -21,6 +22,10 @@ import           Test.Hspec.Core.Spec import           Test.Hspec.Wai.Util (formatHeader) +#if MIN_VERSION_base(4,12,0)+import           Control.Monad.Fail+#endif+ -- | An expectation in the `WaiSession` monad.  Failing expectations are -- communicated through exceptions (similar to `Test.Hspec.Expectations.Expectation` and -- `Test.HUnit.Base.Assertion`).@@ -29,7 +34,11 @@ -- | A <http://www.yesodweb.com/book/web-application-interface WAI> test -- session that carries the `Application` under test and some client state. newtype WaiSession a = WaiSession {unWaiSession :: Session a}-  deriving (Functor, Applicative, Monad, MonadIO)+  deriving (Functor, Applicative, Monad, MonadIO+#if MIN_VERSION_base(4,12,0)+  , MonadFail+#endif+  )  runWaiSession :: WaiSession a -> Application -> IO a runWaiSession = runSession . unWaiSession
src/Test/Hspec/Wai/Util.hs view
@@ -1,8 +1,8 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE CPP #-} module Test.Hspec.Wai.Util where  import           Control.Monad-import           Data.Monoid import           Data.Maybe import           Data.List import           Data.Word@@ -18,6 +18,10 @@ import qualified Data.Text.Encoding as T import qualified Data.CaseInsensitive as CI import           Network.HTTP.Types++#if !MIN_VERSION_base(4,11,0)+import           Data.Monoid+#endif  formatHeader :: Header -> String formatHeader header@(name, value) = "  " ++ fromMaybe (show header) (safeToString $ B8.concat [CI.original name, ": ", value])
test/Test/Hspec/Wai/UtilSpec.hs view
@@ -1,16 +1,20 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE CPP #-} module Test.Hspec.Wai.UtilSpec (main, spec) where  import           Test.Hspec import           Test.Hspec.QuickCheck import           Test.QuickCheck import           Test.Hspec.Wai.Util-import           Data.Monoid import           Network.HTTP.Types (parseSimpleQuery) import           Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as LB import qualified Data.Text as T import qualified Data.Text.Encoding as T++#if !MIN_VERSION_base(4,11,0)+import           Data.Monoid+#endif  main :: IO () main = hspec spec
test/Test/Hspec/WaiSpec.hs view
@@ -8,6 +8,7 @@ import           Network.Wai  import           Test.Hspec.Wai+import           Test.Hspec.Wai.Internal (withApplication)  main :: IO () main = hspec spec@@ -28,32 +29,39 @@  spec :: Spec spec = do-  describe "get" $ with (return $ expectMethod methodGet) $-    it "sends a get request" $+  describe "WaiSession" $ do+    it "has a MonadFail instance" $ do+      withApplication undefined $ do+        23 <- return (42 :: Int)+        return ()+      `shouldThrow` anyIOException++  describe "get" $ with (return $ expectMethod methodGet) $ do+    it "sends a get request" $ do       get "/" `shouldRespondWith` 200 -  describe "post" $ with (return $ expectMethod methodPost) $-    it "sends a post request" $+  describe "post" $ with (return $ expectMethod methodPost) $ do+    it "sends a post request" $ do       post "/" "" `shouldRespondWith` 200 -  describe "put" $ with (return $ expectMethod methodPut) $-    it "sends a put request" $+  describe "put" $ with (return $ expectMethod methodPut) $ do+    it "sends a put request" $ do       put "/" "" `shouldRespondWith` 200 -  describe "options" $ with (return $ expectMethod methodOptions) $-    it "sends an options request" $+  describe "options" $ with (return $ expectMethod methodOptions) $ do+    it "sends an options request" $ do       options "/" `shouldRespondWith` 200 -  describe "delete" $ with (return $ expectMethod methodDelete) $-    it "sends a delete request" $+  describe "delete" $ with (return $ expectMethod methodDelete) $ do+    it "sends a delete request" $ do       delete "/" `shouldRespondWith` 200 -  describe "request" $ with (return $ expectRequest methodGet "/foo" body accept) $-    it "sends method, path, headers, and body" $+  describe "request" $ with (return $ expectRequest methodGet "/foo" body accept) $ do+    it "sends method, path, headers, and body" $ do       request methodGet "/foo" accept (BL.fromChunks [body]) `shouldRespondWith` 200 -  describe "postHtmlForm" $ with (return $ expectRequest methodPost "/foo" "foo=bar" formEncoded) $-    it "sends a post request with form-encoded params" $+  describe "postHtmlForm" $ with (return $ expectRequest methodPost "/foo" "foo=bar" formEncoded) $ do+    it "sends a post request with form-encoded params" $ do       postHtmlForm "/foo" [("foo", "bar")] `shouldRespondWith` 200    where