Skip to content

house: Rewrite tests to use hspec with fail-fast. #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/house/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ tests:
source-dirs: test
dependencies:
- house
- HUnit
- hspec
205 changes: 99 additions & 106 deletions exercises/house/test/Tests.hs
Original file line number Diff line number Diff line change
@@ -1,110 +1,103 @@
import Test.HUnit ( Test(..), (~?=), runTestTT, Counts(..) )
import System.Exit (ExitCode(..), exitWith)
import House ( rhyme )
import Test.Hspec (Spec, describe, it, shouldBe)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

exitProperly :: IO Counts -> IO ()
exitProperly m = do
counts <- m
exitWith $ if failures counts /= 0 || errors counts /= 0
then ExitFailure 1
else ExitSuccess

houseTest :: Test
houseTest = rhyme ~?= expected
import House (rhyme)

main :: IO ()
main = exitProperly $ runTestTT houseTest
main = hspecWith defaultConfig {configFastFail = True} specs

expected :: String
expected = unlines [
"This is the house that Jack built."
, ""
, "This is the malt"
, "that lay in the house that Jack built."
, ""
, "This is the rat"
, "that ate the malt"
, "that lay in the house that Jack built."
, ""
, "This is the cat"
, "that killed the rat"
, "that ate the malt"
, "that lay in the house that Jack built."
, ""
, "This is the dog"
, "that worried the cat"
, "that killed the rat"
, "that ate the malt"
, "that lay in the house that Jack built."
, ""
, "This is the cow with the crumpled horn"
, "that tossed the dog"
, "that worried the cat"
, "that killed the rat"
, "that ate the malt"
, "that lay in the house that Jack built."
, ""
, "This is the maiden all forlorn"
, "that milked the cow with the crumpled horn"
, "that tossed the dog"
, "that worried the cat"
, "that killed the rat"
, "that ate the malt"
, "that lay in the house that Jack built."
, ""
, "This is the man all tattered and torn"
, "that kissed the maiden all forlorn"
, "that milked the cow with the crumpled horn"
, "that tossed the dog"
, "that worried the cat"
, "that killed the rat"
, "that ate the malt"
, "that lay in the house that Jack built."
, ""
, "This is the priest all shaven and shorn"
, "that married the man all tattered and torn"
, "that kissed the maiden all forlorn"
, "that milked the cow with the crumpled horn"
, "that tossed the dog"
, "that worried the cat"
, "that killed the rat"
, "that ate the malt"
, "that lay in the house that Jack built."
, ""
, "This is the rooster that crowed in the morn"
, "that woke the priest all shaven and shorn"
, "that married the man all tattered and torn"
, "that kissed the maiden all forlorn"
, "that milked the cow with the crumpled horn"
, "that tossed the dog"
, "that worried the cat"
, "that killed the rat"
, "that ate the malt"
, "that lay in the house that Jack built."
, ""
, "This is the farmer sowing his corn"
, "that kept the rooster that crowed in the morn"
, "that woke the priest all shaven and shorn"
, "that married the man all tattered and torn"
, "that kissed the maiden all forlorn"
, "that milked the cow with the crumpled horn"
, "that tossed the dog"
, "that worried the cat"
, "that killed the rat"
, "that ate the malt"
, "that lay in the house that Jack built."
, ""
, "This is the horse and the hound and the horn"
, "that belonged to the farmer sowing his corn"
, "that kept the rooster that crowed in the morn"
, "that woke the priest all shaven and shorn"
, "that married the man all tattered and torn"
, "that kissed the maiden all forlorn"
, "that milked the cow with the crumpled horn"
, "that tossed the dog"
, "that worried the cat"
, "that killed the rat"
, "that ate the malt"
, "that lay in the house that Jack built."
, ""
]
specs :: Spec
specs = describe "house" $
it "rhyme" $ rhyme `shouldBe` expected
where
expected = "This is the house that Jack built.\n\
\\n\
\This is the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\This is the rat\n\
\that ate the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\This is the cat\n\
\that killed the rat\n\
\that ate the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\This is the dog\n\
\that worried the cat\n\
\that killed the rat\n\
\that ate the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\This is the cow with the crumpled horn\n\
\that tossed the dog\n\
\that worried the cat\n\
\that killed the rat\n\
\that ate the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\This is the maiden all forlorn\n\
\that milked the cow with the crumpled horn\n\
\that tossed the dog\n\
\that worried the cat\n\
\that killed the rat\n\
\that ate the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\This is the man all tattered and torn\n\
\that kissed the maiden all forlorn\n\
\that milked the cow with the crumpled horn\n\
\that tossed the dog\n\
\that worried the cat\n\
\that killed the rat\n\
\that ate the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\This is the priest all shaven and shorn\n\
\that married the man all tattered and torn\n\
\that kissed the maiden all forlorn\n\
\that milked the cow with the crumpled horn\n\
\that tossed the dog\n\
\that worried the cat\n\
\that killed the rat\n\
\that ate the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\This is the rooster that crowed in the morn\n\
\that woke the priest all shaven and shorn\n\
\that married the man all tattered and torn\n\
\that kissed the maiden all forlorn\n\
\that milked the cow with the crumpled horn\n\
\that tossed the dog\n\
\that worried the cat\n\
\that killed the rat\n\
\that ate the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\This is the farmer sowing his corn\n\
\that kept the rooster that crowed in the morn\n\
\that woke the priest all shaven and shorn\n\
\that married the man all tattered and torn\n\
\that kissed the maiden all forlorn\n\
\that milked the cow with the crumpled horn\n\
\that tossed the dog\n\
\that worried the cat\n\
\that killed the rat\n\
\that ate the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\This is the horse and the hound and the horn\n\
\that belonged to the farmer sowing his corn\n\
\that kept the rooster that crowed in the morn\n\
\that woke the priest all shaven and shorn\n\
\that married the man all tattered and torn\n\
\that kissed the maiden all forlorn\n\
\that milked the cow with the crumpled horn\n\
\that tossed the dog\n\
\that worried the cat\n\
\that killed the rat\n\
\that ate the malt\n\
\that lay in the house that Jack built.\n\
\\n\
\"