question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Placeholder (or similar concept) with generic matching

See original GitHub issue

Sometimes, I don’t know the exact value my API would return, but I know that it has to return a value, and maybe I know that the value has to have a specific shape (e.g. an UUID or a Date).

Currently, I can use body.path("id").isPresent to assert that a value is there at all. This is somewhat fine, but doesn’t have a nice reading flow, e.g.:

And assert body.whiteListing.is(
"""
{
  "firstName": "Foo",
  "lastName": "Bar",
  "isAwesome": true
}
""")
And assert body.path("id").isPresent

The reading flow is better if the "id" presence is checked within the body-assertion.

And assert body.whiteListing.is(
"""
{
  "id": <is-present>,
  "firstName": "Foo",
  "lastName": "Bar",
  "isAwesome": true
}
""")

It would be even better if we can define matchers for the shape of the fields, e.g.:

And assert body.whiteListing.is(
"""
{
  "id": "<any-uuid>",
  "firstName": "Foo",
  "lastName": "Bar",
  "isAwesome": <any-boolean>,
  "createdAt": "<any-iso-date>"
}
""")

I used the <> syntax from placeholders in the examples. It would also be completely valid to introduce another syntax for it, as it’s a different concept (e.g. []).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
agourlaycommented, Nov 8, 2016

Looks really good, thank you for the input! I can definitely see how this could improve the user experience.

However it does require a non-trivial modification of the current model so no promises 😄

1reaction
agourlaycommented, Jan 27, 2017

I have done the predicate change, the code is much cleaner. https://github.com/agourlay/cornichon/commit/9c9733e5f7d58e2576b1f3d607ec81b0a02e4812

I also added a description field to help our dear users :bowtie:

Read more comments on GitHub >

github_iconTop Results From Across the Web

swift - What's a placeholder? Why do we need to define ...
Your question is really "What is a generic?", which is kind of broad for Stack Overflow. Would it help you to read a...
Read more >
Generics: How They Work and Why They Are Important - Oracle
Generics can be applied at the method level to solve such situations. Method arguments can contain generic types, and methods can also contain...
Read more >
Generics — The Swift Programming Language (Swift 5.7)
Type parameters specify and name a placeholder type, and are written immediately after the function's name, between a pair of matching angle brackets...
Read more >
How To Use Generics in TypeScript - DigitalOcean
Generics are a fundamental feature of statically-typed languages, allowing developers to pass types as parameters to a type, function, ...
Read more >
Using Generic Types in Rust - Matt Oswalt
A syntax that allows the developer to use generic terms as placeholders for more concrete types to be passed in elsewhere; An underlying ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found