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

Add support for not contains json matcher #42

Closed
Crow-EH opened this issue Jun 19, 2019 · 5 comments · Fixed by #48
Closed

Add support for not contains json matcher #42

Crow-EH opened this issue Jun 19, 2019 · 5 comments · Fixed by #48

Comments

@Crow-EH
Copy link
Contributor

Crow-EH commented Jun 19, 2019

Hi everyone.

I created this issue instead of a PR to talk about it with you first. I'm still 100% motivated to code it myself though.

Here's the issue: Today we can't make an explicit, concise and human readable test that a JSON field doesn't contain a string.

How about adding a way to negate matchers or add new negated matchers not contain / not contains ? (or even !contains)

Example / Use case

Let's say I want to test this object :

{
  a: string
  b: string
}

Additionally a and b :

  • have very, very long values (e.g. URLs with many query params, tokens, etc.)
  • might evolve many times in the project lifecycle (e.g. by adding params regularly)

=> I don't want to use the equals matcher because I'll have to update every tests every time, plus my tests would be over verbose.

Now let's pretend that I have to develop a new feature where:

  • I need to add a new foo query param only for a
  • But absolutely not for b (i.e. they have a similar method of generation and errors could be made)

I'd want to test that :

  • a contains foo
  • b does not contain foo

And here's what it would look like today :

And json response should match
    | field | matcher  | value         |
    | a     | contains | foo           |
    | b     | match    | ^((?!foo).)*$ |

The only way to do the second test is to match the value against ^((?!foo).)*$ with match, which is not really human readable and more error prone than a simple not contains.

The negated contains would look like this:

And json response should match
    | field | matcher      | value |
    | a     | contains     | foo   |
    | b     | not contains | foo   |

WDYT @plouc @leguellec ?

TL;DR

Need to test if a value is not contained by another one, but regexps are not human friendly :

tenor

@Crow-EH Crow-EH changed the title Add support for negation of the contains matcher Add support for negation of the contains json matcher Jun 19, 2019
@Crow-EH Crow-EH changed the title Add support for negation of the contains json matcher Add support for not contains json matcher Jun 19, 2019
@Crow-EH
Copy link
Contributor Author

Crow-EH commented Jun 19, 2019

Here's a PR.

Not sure if I did everything right, so don't hesitate to roast me. 😄

Thank you !

@plouc
Copy link
Contributor

plouc commented Jun 20, 2019

Maybe we could use does not or doesn't instead as gherkin is supposed to be human readable, this way we'll have something like props | doesn't contain | something.

Also I think we could support this for all matchers, what do you think?

@Crow-EH
Copy link
Contributor Author

Crow-EH commented Jun 20, 2019

Good point!
I'll rename it and extend to every matchers.

@plouc
Copy link
Contributor

plouc commented Jun 20, 2019

perfect, thanks!

@Crow-EH
Copy link
Contributor Author

Crow-EH commented Jun 23, 2019

Done !

I added support for every matchers negation with: !, not, does not, doesn't, is not, isn't.

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