packages feed

hspec2 0.0.1 → 0.1.0

raw patch · 6 files changed

+30/−14 lines, 6 files

Files

hspec2.cabal view
@@ -1,5 +1,5 @@ name:             hspec2-version:          0.0.1+version:          0.1.0 license:          MIT license-file:     LICENSE copyright:        (c) 2011-2014 Simon Hengel,
src/Test/Hspec.hs view
@@ -10,6 +10,7 @@ -- * Types   Spec , SpecWith+, ActionWith , Example  -- * Setting expectations@@ -27,6 +28,7 @@ , after_ , around , around_+, aroundWith , parallel  -- * Running a spec@@ -87,17 +89,24 @@ before action = around (action >>=)  -- | Run a custom action after every spec item.-after :: (a -> IO ()) -> SpecWith a -> SpecWith a-after a2 = mapSpecItem $ \item -> item {itemExample = \params a1 -> itemExample item params (\f -> a1 (\a -> f a `finally` a2 a))}+after :: ActionWith a -> SpecWith a -> SpecWith a+after action = aroundWith $ \e x -> e x `finally` action x  -- | Run a custom action after every spec item. after_ :: IO () -> Spec -> Spec after_ action = after $ \() -> action  -- | Run a custom action before and/or after every spec item.-around :: ((a -> IO ()) -> IO ()) -> SpecWith a -> Spec-around a2 = mapSpecItem $ \item -> item {itemExample = \params a1 -> itemExample item params (\x -> a1 $ \() -> a2 x)}+around :: (ActionWith a -> IO ()) -> SpecWith a -> Spec+around action = aroundWith $ \e () -> action e  -- | Run a custom action before and/or after every spec item. around_ :: (IO () -> IO ()) -> Spec -> Spec around_ action = around $ action . ($ ())++-- | Run a custom action before and/or after every spec item.+aroundWith :: (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b+aroundWith action = mapAround (. action)++mapAround :: ((ActionWith b -> IO ()) -> ActionWith a -> IO ()) -> SpecWith a -> SpecWith b+mapAround f = mapSpecItem $ \i@Item{itemExample = e} -> i{itemExample = (. f) . e}
src/Test/Hspec/Core.hs view
@@ -20,6 +20,7 @@ -- * Internal representation of a spec tree , SpecTree (..) , Item (..)+, ActionWith , mapSpecItem , modifyParams , describe
src/Test/Hspec/Core/Type.hs view
@@ -7,6 +7,7 @@ , fromSpecList , SpecTree (..) , Item (..)+, ActionWith , mapSpecItem , Example (..) , Result (..)@@ -85,9 +86,12 @@  data Item a = Item {   itemIsParallelizable :: Bool-, itemExample :: Params -> ((a -> IO ()) -> IO ()) -> ProgressCallback -> IO Result+, itemExample :: Params -> (ActionWith a -> IO ()) -> ProgressCallback -> IO Result } +-- | An `IO` action that expects an argument of type a.+type ActionWith a = a -> IO ()+ mapSpecItem :: (Item a -> Item b) -> SpecWith a -> SpecWith b mapSpecItem f = fromSpecList . map go . runSpecM   where@@ -114,7 +118,7 @@ -- | A type class for examples. class Example e where   type Arg e-  evaluateExample :: e -> Params -> ((Arg e -> IO ()) -> IO ()) -> ProgressCallback -> IO Result+  evaluateExample :: e -> Params -> (ActionWith (Arg e) -> IO ()) -> ProgressCallback -> IO Result  instance Example Bool where   type Arg Bool = ()
src/Test/Hspec/QuickCheck.hs view
@@ -5,13 +5,7 @@   modifyMaxSuccess , modifyMaxDiscardRatio , modifyMaxSize--- * Re-exports from QuickCheck--- |--- Previous versions of Hspec provided a distinct `property` combinator, but--- it's now possible to use QuickCheck's `property` instead.  For backward--- compatibility we now re-export QuickCheck's `property`, but it is advisable--- to import it from "Test.QuickCheck" instead.-, property+ -- * Shortcuts , prop ) where
test/Test/HspecSpec.hs view
@@ -221,6 +221,14 @@           , "after inner"           , "after outer"           ]++  describe "aroundWith" $ do+    it "wraps every spec item with an action" $ do+      let action :: H.ActionWith String -> H.ActionWith Int+          action e n = e (show n)+      property $ \n -> do+        silence $ H.hspec $ H.before (return n) $ H.aroundWith action $ do+          H.it "foo" $ (`shouldBe` show n)   where     runSpec :: H.Spec -> IO [String]     runSpec = captureLines . H.hspecResult