hspec2 0.1.0 → 0.1.1
raw patch · 5 files changed
+20/−4 lines, 5 files
Files
- hspec2.cabal +1/−1
- src/Test/Hspec.hs +5/−0
- src/Test/Hspec/Runner/Eval.hs +0/−1
- src/Test/Hspec/Runner/Tree.hs +6/−2
- test/Test/HspecSpec.hs +8/−0
hspec2.cabal view
@@ -1,5 +1,5 @@ name: hspec2-version: 0.1.0+version: 0.1.1 license: MIT license-file: LICENSE copyright: (c) 2011-2014 Simon Hengel,
src/Test/Hspec.hs view
@@ -24,6 +24,7 @@ , pending , pendingWith , before+, beforeWith , after , after_ , around@@ -87,6 +88,10 @@ -- | Run a custom action before every spec item. before :: IO a -> SpecWith a -> Spec before action = around (action >>=)++-- | Run a custom action before every spec item.+beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b+beforeWith action = aroundWith $ \e x -> action x >>= e -- | Run a custom action after every spec item. after :: ActionWith a -> SpecWith a -> SpecWith a
src/Test/Hspec/Runner/Eval.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE DeriveFunctor #-} module Test.Hspec.Runner.Eval (runFormatter) where import Control.Applicative
src/Test/Hspec/Runner/Tree.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE DeriveFunctor #-} module Test.Hspec.Runner.Tree where import Test.Hspec.Core.Type@@ -6,7 +5,12 @@ data Tree a = Node String [Tree a] | Leaf String a- deriving (Eq, Show, Functor)+ deriving (Eq, Show)++instance Functor Tree where+ fmap f t = case t of+ Node s xs -> Node s (map (fmap f) xs)+ Leaf s x -> Leaf s (f x) toTree :: SpecTree () -> Tree (Item ()) toTree spec = case spec of
test/Test/HspecSpec.hs view
@@ -129,6 +129,14 @@ H.it "foo" $ property $ append "foo" readIORef ref `shouldReturn` (take 200 . cycle) ["before", "foo"] + describe "beforeWith" $ do+ it "runs an action before every spec item" $ do+ let action :: Int -> IO String+ action n = return (show n)+ property $ \n -> do+ silence $ H.hspec $ H.before (return n) $ H.beforeWith action $ do+ H.it "foo" $ (`shouldBe` show n)+ describe "after" $ do it "must be used with a before action" $ do ref <- newIORef ([] :: [String])