Skip to content
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

Feature request: partial body matcher #29

Open
ryantm opened this issue Sep 3, 2015 · 3 comments
Open

Feature request: partial body matcher #29

ryantm opened this issue Sep 3, 2015 · 3 comments

Comments

@ryantm
Copy link

ryantm commented Sep 3, 2015

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.

@cgag
Copy link

cgag commented Jan 7, 2016

+1 on this being useful

@adlaika
Copy link

adlaika commented May 13, 2022

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

@adlaika
Copy link

adlaika commented May 13, 2022

...and I just realized this issue was last updated in 2016 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants