| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.Hspec.Lens
Description
Module is designed to be conveniently imported instead of Test.Hspec
It reexports Test.Hspec without expectations (except for shouldBe)
and Test.Hspec.Expectations.Lens expectations
- type Spec = SpecWith ()
- class Example e
- shouldBe :: (Show a, Eq a) => a -> a -> Expectation
- module Test.Hspec.Expectations.Lens
- describe :: String -> SpecWith a -> SpecWith a
- context :: String -> SpecWith a -> SpecWith a
- it :: Example a => String -> a -> SpecWith (Arg a)
- example :: Expectation -> Expectation
- pending :: Expectation
- pendingWith :: String -> Expectation
- before :: IO a -> SpecWith a -> Spec
- after :: ActionWith a -> SpecWith a -> SpecWith a
- around :: (ActionWith a -> IO ()) -> SpecWith a -> Spec
- parallel :: SpecWith a -> SpecWith a
- hspec :: Spec -> IO ()
Types
Setting expectations
shouldBe :: (Show a, Eq a) => a -> a -> Expectation infix 1
actual `shouldBe` expected sets the expectation that actual is equal
to expected (this is just an alias for @?=).
module Test.Hspec.Expectations.Lens
Defining a spec
describe :: String -> SpecWith a -> SpecWith a
The describe function combines a list of specs into a larger spec.
it :: Example a => String -> a -> SpecWith (Arg a)
The it function creates a spec item.
A spec item consists of:
- a textual description of a desired behavior
- an example for that behavior
describe "absolute" $ do
it "returns a positive number when given a negative number" $
absolute (-1) == 1example :: Expectation -> Expectation
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
pending can be used to indicate that an example is pending.
If you want to textually specify a behavior but do not have an example yet, use this:
describe "fancyFormatter" $ do
it "can format text in a way that everyone likes" $
pendingpendingWith :: String -> Expectation
pendingWith is similar to pending, but it takes an additional string
argument that can be used to specify the reason for why it's pending.
after :: ActionWith a -> SpecWith a -> SpecWith a
Run a custom action after every spec item.
around :: (ActionWith a -> IO ()) -> SpecWith a -> Spec
Run a custom action before and/or after every spec item.
parallel :: SpecWith a -> SpecWith a
parallel marks all spec items of the given spec to be safe for parallel
evaluation.
Running a spec
Run given spec and write a report to stdout.
Exit with exitFailure if at least one spec item fails.