hspec-expectations 0.5.0.1 → 0.6.0
raw patch · 2 files changed
+35/−3 lines, 2 files
Files
hspec-expectations.cabal view
@@ -1,5 +1,5 @@ name: hspec-expectations-version: 0.5.0.1+version: 0.6.0 synopsis: Catchy combinators for HUnit description: Catchy combinators for HUnit: <https://github.com/sol/hspec-expectations#readme> license: MIT
src/Test/Hspec/Expectations/Contrib.hs view
@@ -2,8 +2,11 @@ -- Experimental combinators, that may become part of the main distribution, if -- they turn out to be useful for a wider audience. module Test.Hspec.Expectations.Contrib (-- module Test.Hspec.Expectations+-- * Additional combinators for setting expectations+ shouldNotBe+, shouldNotSatisfy+, shouldNotReturn+, shouldNotContain -- * Predicates -- | (useful in combination with `shouldSatisfy`)@@ -12,6 +15,8 @@ ) where import Test.Hspec.Expectations+import Test.HUnit (assertBool)+import Data.List (isInfixOf) isLeft :: Either a b -> Bool isLeft (Left _) = True@@ -20,3 +25,30 @@ isRight :: Either a b -> Bool isRight (Left _) = False isRight (Right _) = True++infix 1 `shouldNotBe`, `shouldNotSatisfy`, `shouldNotContain`, `shouldNotReturn`++-- |+-- @actual \`shouldNotBe\` notExpected@ sets the expectation that @actual@ is not+-- equal to @notExpected@+shouldNotBe :: (Show a, Eq a) => a -> a -> Expectation+actual `shouldNotBe` notExpected = assertBool ("not expected: " ++ show actual) (actual /= notExpected)++-- |+-- @v \`shouldNotSatisfy\` p@ sets the expectation that @p v@ is @False@.+shouldNotSatisfy :: (Show a) => a -> (a -> Bool) -> Expectation+v `shouldNotSatisfy` p = assertBool ("predicate succeded on: " ++ show v) ((not . p) v)++-- |+-- @list \`shouldNotContain\` sublist@ sets the expectation that @sublist@ is not+-- contained anywhere in the second.+shouldNotContain :: (Show a, Eq a) => [a] -> [a] -> Expectation+list `shouldNotContain` sublist = assertBool errorMsg ((not . isInfixOf sublist) list)+ where+ errorMsg = show list ++ " does contain " ++ show sublist++-- |+-- @action \`shouldNotReturn\` notExpected@ sets the expectation that @action@+-- does not return @notExpected@.+shouldNotReturn :: (Show a, Eq a) => IO a -> a -> Expectation+action `shouldNotReturn` notExpected = action >>= (`shouldNotBe` notExpected)