ImpSpec-0.1.0.0: Imperative approach to testing stateful applications. ImpSpec is build on top of HSpec and QuickCheck
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.ImpSpec.Expectations

Synopsis

Expectations

Common

assertBool #

Arguments

:: HasCallStack 
=> String

The message that is displayed if the assertion fails

-> Bool

The condition

-> Assertion 

Asserts that the specified condition holds.

assertFailure #

Arguments

:: HasCallStack 
=> String

A message that is displayed with the assertion failure

-> IO a 

Unconditionally signals that a failure has occurred.

shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation infix 1 #

actual `shouldBe` expected sets the expectation that actual is equal to expected.

shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation infix 1 #

v `shouldSatisfy` p sets the expectation that p v is True.

shouldStartWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #

list `shouldStartWith` prefix sets the expectation that list starts with prefix,

shouldEndWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #

list `shouldEndWith` suffix sets the expectation that list ends with suffix,

shouldContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #

list `shouldContain` sublist sets the expectation that sublist is contained, wholly and intact, anywhere in list.

shouldMatchList :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #

xs `shouldMatchList` ys sets the expectation that xs has the same elements that ys has, possibly in another order

shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation infix 1 #

action `shouldReturn` expected sets the expectation that action returns expected.

shouldNotBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation infix 1 #

actual `shouldNotBe` notExpected sets the expectation that actual is not equal to notExpected

shouldNotSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation infix 1 #

v `shouldNotSatisfy` p sets the expectation that p v is False.

shouldNotContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #

list `shouldNotContain` sublist sets the expectation that sublist is not contained anywhere in list.

shouldNotReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation infix 1 #

action `shouldNotReturn` notExpected sets the expectation that action does not return notExpected.

shouldThrow :: (HasCallStack, Exception e) => IO a -> Selector e -> Expectation infix 1 #

action `shouldThrow` selector sets the expectation that action throws an exception. The precise nature of the expected exception is described with a Selector.

type Selector a = a -> Bool #

A Selector is a predicate; it can simultaneously constrain the type and value of an exception.

Custom

assertColorFailure :: HasCallStack => String -> IO a Source #

Similar to assertFailure, except hspec will not interfer with any escape sequences that indicate color output.

Either

shouldBeRight :: (HasCallStack, Show a, Show b, Eq b) => Either a b -> b -> Expectation infix 1 Source #

Same as shouldBe, except it checks that the value is Right

shouldBeLeft :: (HasCallStack, Show a, Eq a, Show b) => Either a b -> a -> Expectation infix 1 Source #

Same as shouldBe, except it checks that the value is Left

expectRight :: (HasCallStack, Show a) => Either a b -> IO b Source #

Return value on the Right and fail otherwise.

Difference from shouldSatisfy action isRight in that expectRight will force the content of the Right to WHNF and return it. This expectation will also show the content of the Left when expectation fails.

expectRightDeep :: (HasCallStack, Show a, NFData b) => Either a b -> IO b Source #

Same as expectRight, but also evaluate the returned value to NF

expectRightDeep_ :: (HasCallStack, Show a, NFData b) => Either a b -> IO () Source #

Same as expectRightDeep, but discards the result

expectLeft :: (HasCallStack, Show b) => Either a b -> IO a Source #

Return value on the Left an fail otherwise

Difference from shouldSatisfy action isLeft in that expectLeft will force the content of the Left to WHNF and and return it. This expectation will also show the content of the Right when expectation fails.

expectLeftDeep :: (HasCallStack, NFData a, Show b) => Either a b -> IO a Source #

Same as expectLeft, but also evaluate the returned value to NF

expectLeftDeep_ :: (HasCallStack, NFData a, Show b) => Either a b -> IO () Source #

Same as expectLeftDeep, but discards the result

Maybe

shouldBeJust :: (HasCallStack, Show a, Eq a) => Maybe a -> a -> Expectation Source #

Same as shouldBe, except it checks that the value is Just

expectJust :: HasCallStack => Maybe a -> IO a Source #

Return value from the Just an fail otherwise

Difference from shouldSatisfy action isJust in that expectJust will force the content of the Just to WHNF and it will also return it.

expectJustDeep :: (HasCallStack, NFData a) => Maybe a -> IO a Source #

Same as expectJust, but will force the value to NF

expectJustDeep_ :: (HasCallStack, NFData a) => Maybe a -> IO () Source #

Same as expectJustDeep, but will discard the forced contents of Just

CallStack helpers

callStackToLocation :: CallStack -> Maybe Location Source #

Convert the top call from the CallStack to hspec's Location