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

Allow StringPattern for simple text response #291

Closed
joeftiger opened this issue Jun 14, 2023 · 1 comment
Closed

Allow StringPattern for simple text response #291

joeftiger opened this issue Jun 14, 2023 · 1 comment

Comments

@joeftiger
Copy link

When building an expecting response, it is currently only possible to define JSON patterns (afaik).

However, some apis may return a plain text boolean as in True or False.
I do not find a possibility to define a pattern for a text response, as the function ResponseBuilder::body() accepts no patterns.

I tried fiddling with body_and_matching_rules_mut(), but this would

  1. be a bit cumbersome to use
  2. does not work as necessary structs are not public.

The following does not work either as it returns the boolean encapsulated inside "True" or "False".

PactBuilder::new_v4( ... )
    .interaction( ..., |mut i| {
        ...
        i.response
             ...
             .json_body(term!("^(True|False)$", "True"))
    })

It would be great when textual patterns could be implemented.

@rholshausen
Copy link
Contributor

1.0.2 now supports matching on text bodies:

let pact = PactBuilder::new("C", "P")
      .interaction("I", "", |mut i| {
        i.request.body_matching(term!("^(True|False)$", "True"));
        i
      })
      .build()

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

2 participants