Stability | stable |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Test.Hspec
Description
Hspec is a testing framework for Haskell.
This is the library reference for Hspec. The User's Manual contains more in-depth documentation.
Synopsis
- type Spec = SpecWith ()
- type SpecWith a = SpecM a ()
- type family Arg e
- class Example e
- type Selector a = a -> Bool
- type HasCallStack = ?callStack :: CallStack
- type Expectation = Assertion
- shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
- shouldContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldEndWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldMatchList :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldNotBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
- shouldNotContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldNotReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
- shouldNotSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
- shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
- shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
- shouldStartWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldThrow :: (HasCallStack, Exception e) => IO a -> Selector e -> Expectation
- anyArithException :: Selector ArithException
- anyErrorCall :: Selector ErrorCall
- anyException :: Selector SomeException
- anyIOException :: Selector IOException
- errorCall :: String -> Selector ErrorCall
- expectationFailure :: HasCallStack => String -> Expectation
- it :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- specify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- describe :: HasCallStack => String -> SpecWith a -> SpecWith a
- context :: HasCallStack => String -> SpecWith a -> SpecWith a
- example :: Expectation -> Expectation
- parallel :: SpecWith a -> SpecWith a
- sequential :: SpecWith a -> SpecWith a
- runIO :: IO r -> SpecM a r
- pending :: HasCallStack => Expectation
- pendingWith :: HasCallStack => String -> Expectation
- xit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- xspecify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- xdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a
- xcontext :: HasCallStack => String -> SpecWith a -> SpecWith a
- focus :: SpecWith a -> SpecWith a
- fit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- fspecify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- fdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a
- fcontext :: HasCallStack => String -> SpecWith a -> SpecWith a
- type ActionWith a = a -> IO ()
- before :: IO a -> SpecWith a -> Spec
- before_ :: IO () -> SpecWith a -> SpecWith a
- beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b
- beforeAll :: HasCallStack => IO a -> SpecWith a -> Spec
- beforeAll_ :: HasCallStack => IO () -> SpecWith a -> SpecWith a
- beforeAllWith :: HasCallStack => (b -> IO a) -> SpecWith a -> SpecWith b
- after :: ActionWith a -> SpecWith a -> SpecWith a
- after_ :: IO () -> SpecWith a -> SpecWith a
- afterAll :: HasCallStack => ActionWith a -> SpecWith a -> SpecWith a
- afterAll_ :: HasCallStack => IO () -> SpecWith a -> SpecWith a
- around :: (ActionWith a -> IO ()) -> SpecWith a -> Spec
- around_ :: (IO () -> IO ()) -> SpecWith a -> SpecWith a
- aroundWith :: (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b
- aroundAll :: HasCallStack => (ActionWith a -> IO ()) -> SpecWith a -> Spec
- aroundAll_ :: HasCallStack => (IO () -> IO ()) -> SpecWith a -> SpecWith a
- aroundAllWith :: HasCallStack => (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b
- mapSubject :: (b -> a) -> SpecWith a -> SpecWith b
- ignoreSubject :: SpecWith () -> SpecWith a
- hspec :: Spec -> IO ()
Types
Instances
type Arg Property | |
Defined in Test.Hspec.Core.QuickCheck type Arg Property = () | |
type Arg Result | |
Defined in Test.Hspec.Core.Example type Arg Result = () | |
type Arg Expectation | |
Defined in Test.Hspec.Core.Example | |
type Arg Bool | |
Defined in Test.Hspec.Core.Example | |
type Arg (a -> Property) | |
Defined in Test.Hspec.Core.QuickCheck type Arg (a -> Property) = a | |
type Arg (a -> Result) | |
Defined in Test.Hspec.Core.Example type Arg (a -> Result) = a | |
type Arg (a -> Expectation) | |
Defined in Test.Hspec.Core.Example | |
type Arg (a -> Bool) | |
Defined in Test.Hspec.Core.Example |
Minimal complete definition
evaluateExample
Instances
Example Result | |||||
Defined in Test.Hspec.Core.Example Associated Types
Methods evaluateExample :: Result -> Params -> (ActionWith (Arg Result) -> IO ()) -> ProgressCallback -> IO Result | |||||
Example Expectation | |||||
Defined in Test.Hspec.Core.Example Associated Types
Methods evaluateExample :: Expectation -> Params -> (ActionWith (Arg Expectation) -> IO ()) -> ProgressCallback -> IO Result | |||||
Example Bool | |||||
Defined in Test.Hspec.Core.Example Associated Types
Methods evaluateExample :: Bool -> Params -> (ActionWith (Arg Bool) -> IO ()) -> ProgressCallback -> IO Result | |||||
Example (a -> Result) | |||||
Defined in Test.Hspec.Core.Example Associated Types
Methods evaluateExample :: (a -> Result) -> Params -> (ActionWith (Arg (a -> Result)) -> IO ()) -> ProgressCallback -> IO Result | |||||
Example (a -> Expectation) | |||||
Defined in Test.Hspec.Core.Example Associated Types
Methods evaluateExample :: (a -> Expectation) -> Params -> (ActionWith (Arg (a -> Expectation)) -> IO ()) -> ProgressCallback -> IO Result | |||||
Example (a -> Bool) | |||||
Defined in Test.Hspec.Core.Example Associated Types
Methods evaluateExample :: (a -> Bool) -> Params -> (ActionWith (Arg (a -> Bool)) -> IO ()) -> ProgressCallback -> IO Result |
Setting expectations
type HasCallStack = ?callStack :: CallStack #
type Expectation = Assertion #
shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation #
shouldContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation #
shouldEndWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation #
shouldMatchList :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation #
shouldNotBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation #
shouldNotContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation #
shouldNotReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation #
shouldNotSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation #
shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation #
shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation #
shouldStartWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation #
shouldThrow :: (HasCallStack, Exception e) => IO a -> Selector e -> Expectation #
anyArithException :: Selector ArithException #
anyErrorCall :: Selector ErrorCall #
anyException :: Selector SomeException #
anyIOException :: Selector IOException #
expectationFailure :: HasCallStack => String -> Expectation #
Defining a spec
example :: Expectation -> Expectation Source #
example
is a type restricted version of id
. It can be used to get better
error messages on type mismatches.
Compare e.g.
it "exposes some behavior" $ example $ do putStrLn
with
it "exposes some behavior" $ do putStrLn
sequential :: SpecWith a -> SpecWith a #
Pending spec items
During a test run a pending spec item is:
- not executed
- reported as "pending"
pending :: HasCallStack => Expectation #
pendingWith :: HasCallStack => String -> Expectation #
Focused spec items
During a test run, when a spec contains focused spec items, all other spec items are ignored.
Hooks
type ActionWith a = a -> IO () #
beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b #
beforeAll_ :: HasCallStack => IO () -> SpecWith a -> SpecWith a #
beforeAllWith :: HasCallStack => (b -> IO a) -> SpecWith a -> SpecWith b #
after :: ActionWith a -> SpecWith a -> SpecWith a #
afterAll :: HasCallStack => ActionWith a -> SpecWith a -> SpecWith a #
aroundWith :: (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b #
aroundAll :: HasCallStack => (ActionWith a -> IO ()) -> SpecWith a -> Spec #
aroundAll_ :: HasCallStack => (IO () -> IO ()) -> SpecWith a -> SpecWith a #
aroundAllWith :: HasCallStack => (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b #
mapSubject :: (b -> a) -> SpecWith a -> SpecWith b #
ignoreSubject :: SpecWith () -> SpecWith a #