-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Behavior Driven Development for Haskell -- -- Behavior Driven Development for Haskell -- -- Hspec is roughly based on the Ruby library RSpec. However, Hspec is -- just a framework for running HUnit and QuickCheck tests. Compared to -- other options, it provides a much nicer syntax that makes tests very -- easy to read. -- -- Start with the introductory documentation: -- http://hspec.github.com/ @package hspec @version 1.2.0 -- | This module contains formatters that take a set of specs and write to -- a given handle. They follow a structure similar to RSpec formatters. module Test.Hspec.Formatters silent :: Formatter specdoc :: Formatter progress :: Formatter failed_examples :: Formatter data Formatter Formatter :: String -> (Int -> String -> FormatM ()) -> (Int -> String -> FormatM ()) -> (Int -> String -> String -> FormatM ()) -> (Int -> String -> Maybe String -> FormatM ()) -> FormatM () -> FormatM () -> Formatter formatterName :: Formatter -> String -- | evaluated before each test group exampleGroupStarted :: Formatter -> Int -> String -> FormatM () -- | evaluated after each successful example exampleSucceeded :: Formatter -> Int -> String -> FormatM () -- | evaluated after each failed example exampleFailed :: Formatter -> Int -> String -> String -> FormatM () -- | evaluated after each pending example examplePending :: Formatter -> Int -> String -> Maybe String -> FormatM () -- | evaluated after a test run failedFormatter :: Formatter -> FormatM () -- | evaluated after failuresFormatter footerFormatter :: Formatter -> FormatM () data FormatM a -- | Get the number of successful examples encountered so far. getSuccessCount :: FormatM Int -- | Get the number of pending examples encountered so far. getPendingCount :: FormatM Int -- | Get the number of failed examples encountered so far. getFailCount :: FormatM Int -- | Get the total number of examples encountered so far. getTotalCount :: FormatM Int -- | Get the list of accumulated failure messages. getFailMessages :: FormatM [String] -- | Get the used CPU time since the test run has been started. getCPUTime :: FormatM Double -- | Get the passed real time since the test run has been started. getRealTime :: FormatM Double -- | Append some output to the report. write :: String -> FormatM () -- | The same as write, but adds a newline character. writeLine :: String -> FormatM () -- | Set output to color green, run given action, and finally restore the -- default color. withSuccessColor :: FormatM a -> FormatM a -- | Set output color to yellow, run given action, and finally restore the -- default color. withPendingColor :: FormatM a -> FormatM a -- | Set output color to red, run given action, and finally restore the -- default color. withFailColor :: FormatM a -> FormatM a -- | This module contains the runners that take a set of specs, evaluate -- their examples, and report to a given handle. module Test.Hspec.Runner -- | A list of specs. type Specs = [Spec] -- | Create a document of the given specs and write it to stdout. -- -- Exit the program with exitSuccess if all examples passed, with -- exitFailure otherwise. hspec :: Specs -> IO () -- | Create a document of the given specs and write it to stdout. -- -- Return True if all examples passed, False otherwise. hspecB :: Specs -> IO Bool -- | Create a document of the given specs and write it to the given handle. -- --
-- writeReport filename specs = withFile filename WriteMode (\h -> hHspec h specs) --hHspec :: Handle -> Specs -> IO Summary -- | Create a document of the given specs and write it to the given handle. -- THIS IS LIKELY TO CHANGE hHspecWithFormat :: Formatter -> Bool -> Handle -> Specs -> IO Summary toExitCode :: Bool -> ExitCode -- | Summary of a test run. data Summary Summary :: Int -> Int -> Summary summaryExamples :: Summary -> Int summaryFailures :: Summary -> Int hspecX :: Specs -> IO a instance Eq Summary instance Show Summary instance Monoid Summary -- | Hspec is a Behaviour-Driven Development tool for Haskell programmers. -- BDD is an approach to software development that combines Test-Driven -- Development, Domain Driven Design, and Acceptance Test-Driven -- Planning. Hspec helps you do the TDD part of that equation, focusing -- on the documentation and design aspects of TDD. -- -- Hspec (and the preceding intro) are based on the Ruby library RSpec. -- Much of what applies to RSpec also applies to Hspec. Hspec ties -- together descriptions of behavior and examples of that -- behavior. The examples can also be run as tests and the output -- summarises what needs to be implemented. -- -- NOTE: There is a monadic and a non-monadic API. This is the -- documentation for the non-monadic API. The monadic API is more stable, -- so you may prefer it over this one. For documentation on the monadic -- API look at Test.Hspec.Monadic. module Test.Hspec.Core -- | Internal representation of a spec. data Spec -- | A list of specs. type Specs = [Spec] -- | A type class for examples. -- -- To use an HUnit Test or an Assertion as an example you -- need to import Test.Hspec.HUnit. -- -- To use a QuickCheck Property as an example you need to import -- Test.Hspec.QuickCheck. class Example a evaluateExample :: Example a => a -> IO Result -- | A pending example. data Pending -- | The describe function combines a list of specs into a larger -- spec. describe :: String -> [Spec] -> Spec -- | Create a set of specifications for a specific type being described. -- Once you know what you want specs for, use this. -- --
-- describe "abs" [ -- it "returns a positive number given a negative number" -- (abs (-1) == 1) -- ] --it :: Example a => String -> a -> Spec -- | A pending example. -- -- If you want to report on a behavior but don't have an example yet, use -- this. -- --
-- describe "fancyFormatter" [ -- it "can format text in a way that everyone likes" $ -- pending -- ] ---- -- You can give an optional reason for why it's pending. -- --
-- describe "fancyFormatter" [ -- it "can format text in a way that everyone likes" $ -- pending "waiting for clarification from the designers" -- ] --pending :: String -> Pending -- | Create a document of the given specs and write it to stdout. -- -- Exit the program with exitSuccess if all examples passed, with -- exitFailure otherwise. hspec :: Specs -> IO () -- | Create a document of the given specs and write it to stdout. -- -- Return True if all examples passed, False otherwise. hspecB :: Specs -> IO Bool -- | Create a document of the given specs and write it to the given handle. -- --
-- writeReport filename specs = withFile filename WriteMode (\h -> hHspec h specs) --hHspec :: Handle -> Specs -> IO Summary -- | Summary of a test run. data Summary Summary :: Int -> Int -> Summary summaryExamples :: Summary -> Int summaryFailures :: Summary -> Int -- | Create a more readable display of a quantity of something. -- -- Examples: -- --
-- >>> quantify 0 "example" -- "0 examples" ---- --
-- >>> quantify 1 "example" -- "1 example" ---- --
-- >>> quantify 2 "example" -- "2 examples" --quantify :: Int -> String -> String -- | The result of running an example. data Result Success :: Result Pending :: (Maybe String) -> Result Fail :: String -> Result -- | Hspec is a Behaviour-Driven Development tool for Haskell programmers. -- BDD is an approach to software development that combines Test-Driven -- Development, Domain Driven Design, and Acceptance Test-Driven -- Planning. Hspec helps you do the TDD part of that equation, focusing -- on the documentation and design aspects of TDD. -- -- Hspec (and the preceding intro) are based on the Ruby library RSpec. -- Much of what applies to RSpec also applies to Hspec. Hspec ties -- together descriptions of behavior and examples of that -- behavior. The examples can also be run as tests and the output -- summarises what needs to be implemented. module Test.Hspec.Monadic -- | A type class for examples. -- -- To use an HUnit Test or an Assertion as an example you -- need to import Test.Hspec.HUnit. -- -- To use a QuickCheck Property as an example you need to import -- Test.Hspec.QuickCheck. class Example a -- | A pending example. data Pending -- | The describe function combines a list of specs into a larger -- spec. describe :: String -> Spec -> Spec -- | An alias for describe. context :: String -> Spec -> Spec -- | Create a set of specifications for a specific type being described. -- Once you know what you want specs for, use this. -- --
-- describe "abs" $ do -- it "returns a positive number given a negative number" $ -- abs (-1) == 1 --it :: Example v => String -> v -> Spec -- | A pending example. -- -- If you want to report on a behavior but don't have an example yet, use -- this. -- --
-- describe "fancyFormatter" $ do -- it "can format text in a way that everyone likes" $ -- pending ---- -- You can give an optional reason for why it's pending. -- --
-- describe "fancyFormatter" $ do -- it "can format text in a way that everyone likes" $ -- pending "waiting for clarification from the designers" --pending :: String -> Pending -- | Create a document of the given spec and write it to stdout. -- -- Exit the program with exitSuccess if all examples passed, -- with exitFailure otherwise. hspec :: Spec -> IO () -- | Create a document of the given spec and write it to stdout. -- -- Return True if all examples passed, False otherwise. hspecB :: Spec -> IO Bool -- | Create a document of the given specs and write it to the given handle. -- --
-- writeReport filename specs = withFile filename WriteMode (\h -> hHspec h specs) --hHspec :: Handle -> Spec -> IO Summary -- | Summary of a test run. data Summary Summary :: Int -> Int -> Summary summaryExamples :: Summary -> Int summaryFailures :: Summary -> Int -- | Convert a monadic spec into a non-monadic spec. runSpecM :: Spec -> [Spec] -- | Convert a non-monadic spec into a monadic spec. fromSpecList :: [Spec] -> Spec instance Monad SpecM -- | Importing this module allows you to use an HUnit Test -- as an example for a behavior. You can use an explicit TestCase -- data constructor or use an Assertion. For an -- Assertion, any exception means the example failed; otherwise, -- it's successfull. -- -- NOTE: Any output from the example to stdout is ignored. If -- you need to write out for debugging, you can write to stderr -- or a file handle. -- --
-- import Test.Hspec.Monadic -- import Test.Hspec.HUnit () -- import Test.HUnit -- -- main :: IO () -- main = hspecX $ do -- describe "reverse" $ do -- it "reverses a list" $ do -- reverse [1, 2, 3] @?= [3, 2, 1] -- -- it "gives the original list, if applied twice" $ TestCase $ -- (reverse . reverse) [1, 2, 3] @?= [1, 2, 3] --module Test.Hspec.HUnit instance Example Test instance Example Assertion -- | Importing this module allows you to use a QuickCheck Property -- as an example for a behavior. Use property to turn any -- Testable into a Property. -- -- NOTE: Any output from the example to stdout is ignored. If -- you need to write out for debugging, you can write to stderr -- or a file handle. -- --
-- import Test.Hspec.Monadic -- import Test.Hspec.QuickCheck -- -- main :: IO () -- main = hspecX $ do -- describe "reverse" $ do -- it "gives the original list, if applied twice" $ property $ -- \xs -> (reverse . reverse) xs == (xs :: [Int]) --module Test.Hspec.QuickCheck property :: Testable prop => prop -> Property -- | Monadic DSL shortcut, use this instead of it. prop :: Testable t => String -> t -> Spec instance Example Property -- | Hspec is a Behaviour-Driven Development tool for Haskell programmers. -- BDD is an approach to software development that combines Test-Driven -- Development, Domain Driven Design, and Acceptance Test-Driven -- Planning. Hspec helps you do the TDD part of that equation, focusing -- on the documentation and design aspects of TDD. -- -- Hspec (and the preceding intro) are based on the Ruby library RSpec. -- Much of what applies to RSpec also applies to Hspec. Hspec ties -- together descriptions of behavior and examples of that -- behavior. The examples can also be run as tests and the output -- summarises what needs to be implemented. -- -- NOTE: There is a monadic and a non-monadic API. This is the -- documentation for the non-monadic API. The monadic API is more stable, -- so you may prefer it over this one. For documentation on the monadic -- API look at Test.Hspec.Monadic. module Test.Hspec -- | Internal representation of a spec. data Spec -- | A list of specs. type Specs = [Spec] -- | A type class for examples. -- -- To use an HUnit Test or an Assertion as an example you -- need to import Test.Hspec.HUnit. -- -- To use a QuickCheck Property as an example you need to import -- Test.Hspec.QuickCheck. class Example a -- | A pending example. data Pending -- | The describe function combines a list of specs into a larger -- spec. describe :: String -> [Spec] -> Spec -- | Create a set of specifications for a specific type being described. -- Once you know what you want specs for, use this. -- --
-- describe "abs" [ -- it "returns a positive number given a negative number" -- (abs (-1) == 1) -- ] --it :: Example a => String -> a -> Spec -- | A pending example. -- -- If you want to report on a behavior but don't have an example yet, use -- this. -- --
-- describe "fancyFormatter" [ -- it "can format text in a way that everyone likes" $ -- pending -- ] ---- -- You can give an optional reason for why it's pending. -- --
-- describe "fancyFormatter" [ -- it "can format text in a way that everyone likes" $ -- pending "waiting for clarification from the designers" -- ] --pending :: String -> Pending -- | Create a document of the given specs and write it to stdout. -- -- Exit the program with exitSuccess if all examples passed, with -- exitFailure otherwise. hspec :: Specs -> IO () -- | Create a document of the given specs and write it to stdout. -- -- Return True if all examples passed, False otherwise. hspecB :: Specs -> IO Bool -- | Create a document of the given specs and write it to the given handle. -- --
-- writeReport filename specs = withFile filename WriteMode (\h -> hHspec h specs) --hHspec :: Handle -> Specs -> IO Summary -- | Summary of a test run. data Summary Summary :: Int -> Int -> Summary summaryExamples :: Summary -> Int summaryFailures :: Summary -> Int