hspec 1.11.1 → 1.11.2
raw patch · 3 files changed
+34/−1 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Test.Hspec: beforeAll :: IO () -> Spec -> Spec
Files
- hspec.cabal +1/−1
- src/Test/Hspec.hs +18/−0
- test/Test/HspecSpec.hs +15/−0
hspec.cabal view
@@ -1,5 +1,5 @@ name: hspec-version: 1.11.1+version: 1.11.2 license: MIT license-file: LICENSE copyright: (c) 2011-2014 Simon Hengel,
src/Test/Hspec.hs view
@@ -23,6 +23,7 @@ , pending , pendingWith , before+, beforeAll , after , around , parallel@@ -33,6 +34,7 @@ ) where import Control.Exception (finally)+import Control.Concurrent.MVar import Test.Hspec.Core.Type hiding (describe, it) import Test.Hspec.Runner@@ -88,6 +90,22 @@ -- | Run a custom action before every spec item. before :: IO () -> Spec -> Spec before action = around (action >>)++-- | Run a custom action before all spec items.+beforeAll :: IO () -> Spec -> Spec+beforeAll action = fromSpecList . return . BuildSpecs . go+ where+ go spec = do+ mvar <- newMVar Nothing+ let action_ = memoize mvar action+ runSpecM $ before action_ spec++memoize :: MVar (Maybe a) -> IO a -> IO a+memoize mvar action = modifyMVar mvar $ \ma -> case ma of+ Just a -> return (ma, a)+ Nothing -> do+ a <- action+ return (Just a, a) -- | Run a custom action after every spec item. after :: IO () -> Spec -> Spec
test/Test/HspecSpec.hs view
@@ -111,6 +111,21 @@ H.it "foo" $ do readIORef ref `shouldReturn` 2 + describe "beforeAll" $ do+ it "runs an action before the first spec item" $ do+ ref <- newIORef ([] :: [String])+ let append n = modifyIORef ref (++ return n)+ silence $ H.hspec $ H.beforeAll (append "beforeAll") $ do+ H.it "foo" $ do+ append "foo"+ H.it "bar" $ do+ append "bar"+ readIORef ref `shouldReturn` [+ "beforeAll"+ , "foo"+ , "bar"+ ]+ describe "after" $ do it "runs an action after each spec item" $ do mock <- newMock