hspec-wai
hspec-wai copied to clipboard
Feature request: partial body matcher
It would be nice if there were a way to match part of the body of a response. Sometimes responses contain random bits that you don't care about testing.
+1 on this being useful
You can write your own custom matchers to do whatever you like using ResponseMatcher. For instance:
partialMatcher :: String -> ResponseMatcher
partialMatcher expected = ResponseMatcher {
matchStatus=200
, matchHeaders=[]
, matchBody=MatchBody (\_ actual -> do
if encode expected `isInfixOf` actual
then Nothing
else Just "expected string wasn't a partial match of actual!"
)
}
You can then use this in your tests like so:
let expected = "expected partial response"
request methodPost someTestPath [] body `shouldRespondWith` partialMatcher expected
...and I just realized this issue was last updated in 2016 😅