packages feed

hspec 1.7.1 → 1.7.2

raw patch · 3 files changed

+48/−2 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Test.Hspec: after :: IO () -> Spec -> Spec
+ Test.Hspec: around :: (IO () -> IO ()) -> Spec -> Spec

Files

hspec.cabal view
@@ -1,5 +1,5 @@ name:             hspec-version:          1.7.1+version:          1.7.2 license:          MIT license-file:     LICENSE copyright:        (c) 2011-2013 Simon Hengel,
src/Test/Hspec.hs view
@@ -33,6 +33,8 @@ , pending , pendingWith , before+, after+, around , parallel  -- * Running a spec@@ -45,6 +47,9 @@ import           Test.Hspec.Expectations import qualified Test.Hspec.Core as Core +import           Data.IORef+import           Control.Applicative+ -- $intro -- -- The three functions you'll use the most are 'hspec', 'describe', and 'it'.@@ -150,7 +155,20 @@  -- | Run a custom action before every spec item. before :: IO () -> Spec -> Spec-before action = mapSpecItem $ \b r e -> SpecItem b r (\params -> (action >> (e params)))+before action = mapSpecItem $ \b r e -> SpecItem b r (\params -> action *> e params)++-- | Run a custom action after every spec item.+after :: IO () -> Spec -> Spec+after action = mapSpecItem $ \b r e -> SpecItem b r (\params -> e params <* action)++-- | Run a custom action before and/or after every spec item.+around :: (IO () -> IO ()) -> Spec -> Spec+around action = mapSpecItem $ \b r e -> SpecItem b r (\params -> wrap (e params))+  where+    wrap e = do+      ref <- newIORef (Fail "")+      action (e >>= writeIORef ref)+      readIORef ref  mapSpecItem :: (Bool -> String -> (Params -> IO Result) -> SpecTree) -> Spec -> Spec mapSpecItem f = fromSpecList . map go . runSpecM
test/Test/HspecSpec.hs view
@@ -4,6 +4,7 @@ import           Mock import           Data.List (isPrefixOf) +import           Data.IORef import           Test.Hspec.Core (SpecTree(..), Result(..), runSpecM) import qualified Test.Hspec as H import qualified Test.Hspec.Runner as H (hspecResult)@@ -93,6 +94,33 @@           mockCounter mock `shouldReturn` 1         H.it "bar" $ do           mockCounter mock `shouldReturn` 2+      mockCounter mock `shouldReturn` 2++  describe "after" $ do+    it "runs an action after each spec item" $ do+      mock <- newMock+      silence $ H.hspec $ H.after (mockAction mock) $ do+        H.it "foo" $ do+          mockCounter mock `shouldReturn` 0+        H.it "bar" $ do+          mockCounter mock `shouldReturn` 1+      mockCounter mock `shouldReturn` 2++  describe "around" $ do+    it "runs an action before and/or after each spec item" $ do+      ref <- newIORef (0 :: Int)+      let wrapper :: IO () -> IO ()+          wrapper e = do+            readIORef ref `shouldReturn` 0+            writeIORef ref 1+            e+            readIORef ref `shouldReturn` 2+            writeIORef ref 3+      silence $ H.hspec $ H.around wrapper $ do+        H.it "foo" $ do+          readIORef ref `shouldReturn` 1+          writeIORef ref 2+      readIORef ref `shouldReturn` 3   where     runSpec :: H.Spec -> IO [String]     runSpec = captureLines . H.hspecResult