[Haskell] ANNOUNCE: hspec-0.1.0 (Behavior Driven Development for Haskell)
trystan.s at comcast.net
trystan.s at comcast.net
Sat Feb 12 05:42:55 CET 2011
hspec - Behavior Driven Development for Haskell
hspec ties together requirements and code that verifies the requirements are met. The verifying code can be a boolean expression, a QuickCheck property, or an explination of why it's pending. The requirements can then be turned into documentation of what the code does and what remains to be implemented.
hspec verifies its own requirements as an example of how to use it.
You can find the code on github:
https://github.com/trystan/hspec
There's also a cabal generated tar.gz:
https://github.com/downloads/trystan/hspec/hspec-0.1.0.tar.gz
I'll add it to hackageDB when I get a user name....
And here it is in action:
Step 1, define some requirements
]> import Test.Hspec
]>
]> specs :: IO [Spec]
]> specs = describe "quantify" [
]> it "returns the singular form of a word when given the number 1"
]> (quantify 1 "thing" == "1 thing"),
]>
]> it "returns the plural form of a word when given a number greater than 1"
]> (quantify 2 "thing" == "2 things"),
]>
]> it "returns the plural form of a word when given the number 0"
]> (quantify 0 "thing" == "0 things"),
]>
]> it "handles describing the plural of words that end with an 'x'"
]> (pending "no need for this yet")
]> ]
Step 2, make it compile
]> quantify _ _ = ""
Step 3, watch your requirements fail
]> hspec specs
quantify
x returns the singular form of a word when given the number 1
x returns the plural form of a word when given a number greater than 1
x returns the plural form of a word when given the number 0
- handles describing the plural of words that end with an 'x'
# no need for this yet
Finished in 0.001 seconds
4 examples, 3 failures
Step 4, make it right
]> quantify :: Int -> String -> String
]> quantify 1 s = "1 " ++ s
]> quantify n s = show n ++ " " ++ s ++ "s"
Step 5, watch your requirements pass
]> hspec specs
quantify
- returns the singular form of a word when given the number 1
- returns the plural form of a word when given a number greater than 1
- returns the plural form of a word when given the number 0
- handles describing the plural of words that end with an 'x'
# no need for this yet
Finished in 0.001 seconds
4 examples, 3 failures
Any advice, comments, or questions are welcome.
Trystan Spangler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell/attachments/20110212/f10e8f1c/attachment.htm>
More information about the Haskell
mailing list