GithubHelp home page GithubHelp logo

hspec's Introduction

hspec aims to be a simple, extendable, and useful tool for Behavior Driven Development in Haskell.


Step 1, write descriptions and examples of your desired behavior
> specs = describe "myabs" [
>   it "returns the original number when given a positive input"
>     (myabs 1 == 1),
> 
>   it "returns a positive number when given a negative input"
>     (myabs (-1) == 1),
> 
>   it "returns zero when given zero"
>     (myabs 0 == 0)
>   ]

Step 2, write whatever you are describing
> myabs n = undefined

Step 3, watch your examples fail with red text
> hspec specs
myabs
 x returns the original number when given a positive input FAILED [1]
 x returns a positive number when given a negative input FAILED [2]
 x returns zero when given zero FAILED [3]

1) myabs returns the original number when given a positive input FAILED
Prelude.undefined

2) myabs returns a positive number when given a negative input FAILED
Prelude.undefined

3) myabs returns zero when given zero FAILED
Prelude.undefined

Finished in 0.0002 seconds

3 examples, 3 failures

Step 4, implement your desired behavior
> myabs n = if n < 0 then negate n else n

Step 5, watch your examples pass with green text
> hspec specs
myabs
 - returns the original number when given a positive input
 - returns a positive number when given a negative input
 - returns zero when given zero

Finished in 0.0000 seconds

3 examples, 0 failures




Here's the report of hspec's behavior:


the "describe" function
 - takes a description of what the behavior is for
 - groups behaviors for what's being described

the "it" function
 - takes a description of a desired behavior
 - takes an example of that behavior
 - can use a Bool, HUnit Test, QuickCheck property, or "pending" as an example
 - will treat exceptions as failures

the "hspec" function
 - displays a header for each thing being described
 - displays one row for each behavior
 - displays a '-' for successfull examples
 - displays an 'x' for failed examples
 - displays a detailed list of failed examples
 - displays a '-' for pending examples
 - displays a '#' and an additional message for pending examples
 - summarizes the time it takes to finish
 - summarizes the number of examples and failures
 - outputs failed examples in red, pending in yellow, and passing in green

Bool as an example
 - is just an expression that evaluates to a Bool

HUnit TestCase as an example
 - is specified with the HUnit "TestCase" data constructor
 - is the assumed example for IO() actions
 - will show the failed assertion text if available (e.g. assertBool)
 - will show the failed assertion expected and actual values if available (e.g. assertEqual)

QuickCheck property as an example
 - is specified with the "property" function
 - will show what falsified it

pending as an example
 - is specified with the "pending" function and an explanation
 - accepts a message to display in the report

the "hHspecWithFormat" function
 - can use the "silent" formatter to show no output
 - can use the "progress" formatter to show '..F...FF.F' style output
 - can use the "specdoc" formatter to show all examples (default)
 - can use the "failed_examples" formatter to show only failed examples

quantify (an internal function)
 - returns an amount and a word given an amount and word
 - returns a singular word given the number 1
 - returns a plural word given a number greater than 1
 - returns a plural word given the number 0

Finished in 0.0627 seconds

33 examples, 0 failures

hspec's People

Contributors

bjornbm avatar gregwebs avatar trystan avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.