私が大好きな Pipes を使用するプロジェクトのプログラムを作成しました。ただし、コードの単体テストに苦労しています。
Pipe In Out IO ()
HSpec でテストしたいタイプ (たとえば) の一連の関数があります。これについてどうすればいいですか?
たとえば、次のドメインがあるとします。
data Person = Person String Int | Unknown deriving (Show, Eq)
data Classification = Friend | Foe | Undecided deriving Show
そしてこのパイプ:
classify :: Pipe Person (Person, Classification) IO ()
classify = do
p@(Person name _) <- await
case name of
"Alex" -> yield (p, Friend)
"Bob" -> yield (p, Foe)
_ -> yield (p, Undecided)
仕様を書きたいと思います:
main = hspec $ do
describe "readFileP" $
it "yields all the lines of a file"
pendingWith "How can I test this Pipe? :("