onsi / gomega

Ginkgo's Preferred Matcher Library
http://onsi.github.io/gomega/
MIT License
2.16k stars 281 forks source link

Add HaveExactElements matcher #634

Closed rickyson96 closed 1 year ago

rickyson96 commented 1 year ago

This is the PR for implementing the ordered matcher.

Closes #622

rickyson96 commented 1 year ago

I wanted to implement some mechanism of reporting the matching failure. Something like this

Expected
    <[]int | len:2, cap:2>: [1, 2]
to have exact elements with
    <[]int | len:2, cap:2>: [2, 1]
the mismatch indexes were:
    index: 0, actual: 1, expects: to equal 2
    index: 1, actual: 2, expects: to equal 1

I'm thinking of utilizing the matcher messages used to fail the elements, but don't want to have the newlines. Is there anyway to do that? Or maybe other alternative solution?

Thanks! 😄

onsi commented 1 year ago

hey! sorry for the delay - thanks for pulling this together. i'll take a look tomorrow and share feedback/pull it in. for now - it looks like one of the tests failed on ci?

onsi commented 1 year ago

Ok - took a look and this looks good to me. i don't think it's gonna be super easy to generically remove the new lines in the responses - but I think it's fine to err on the verbose side:

Expected
    <[]int | len:2, cap:2>: [1, 2]
to have exact elements with
    <[]int | len:2, cap:2>: [2, 1]
the mismatch indexes were:
    0: Expected
        <int>: 1
    to equal:
        <int>: 2
    1: Expected
        <int>: 2
    to equal:
        <int>: 1
rickyson96 commented 1 year ago

Hi, sorry for the late response.

I have updated the implementation on the test reporting. I have also fixed the failed test, seems like I accidentaly ran ginkgo bootstrap there

onsi commented 1 year ago

Looks great, thanks - I'll merge this in after the tests go green. Would you be up for adding a brief snippet of documentation to docs/index.md ? Fine if not, I can do it after I pull it in.

Thanks!

rickyson96 commented 1 year ago

done! 😁