Comments (8)
Ginkgo (the matcher library Gomega, actually) uses Golang's reflect.DeepEqual under the hood to do the equality matching (http://golang.org/pkg/reflect/#DeepEqual). DeepEqual
's docs claim to use "==" first under the hood but a look at the code says otherwise. Looks like they perform a type assertion before attempting to do any sort of equality.
I think Gomega'sEqual
matcher could use ==
first and then fallback on DeepEqual
when that fails. That would at least work for cases where one is type aliasing primitives that work well with ==
. Type aliasing a more complex type (e.g. a slice or a map or a custom type) however, would still require a cast as DeepEqual
is more suited to copmaring complex types than ==
.
If all goes well with ==
there should be a fix on master by EOD.
from ginkgo.
Hmm... so I've found a fix for this, but I'm conflicted about it. I can modify the Equality matcher so that it converts the actual value (the left hand side) to have the same value as the expected value (the right hand side) if such a conversion is possible. The converted actual is then passed in to reflect.DeepEqual
.
This works with your string alias example, and doesn't break any other tests that I've written....
But it has the undesirable property that it will convert numbers... This would mean that the float64
5.1
will actually "Equal" the int
5
... boo... this is terrible.
I'm inclined to leave the matcher as is: anal about types, and put the onus of converting types on to the developer. This does mean you'd need:
Ω(info.User).Should(Equal(User("guest"))
Which, while wordy, is actually nice and explicit -- (BTW I think User("guest")
on the RHS would be preferred to string(info.User)
on the LHS)
That said, I'm open to discussion (and would love to have some discussion) about this. I could imagine a separate equality matcher that doesn't care about types.... but I'm not sure what I'd call it.
from ginkgo.
As for the new matcher name, Be
and BeEqual
come to mind. It may be worth renaming the existing matcher to DeepEqual
, although I understand that it would break existing code. But it's now or never, you are only going to have more projects using Gomega in the future.
from ginkgo.
I think I'd prefer Equal
to be strict. Since my main concern is that
converting numbers can lead to false positives, I'll look into making the
matcher strict about not performing numerical conversions... that's what
the BeNumerically
matcher is for.
On Sat, Oct 26, 2013 at 9:19 PM, Michael Klishin
[email protected]:
As for the new matcher name, Be and BeEqual come to mind. It may be worth
renaming the existing matcher to DeepEqual, although I understand that it
would break existing code. But it's now or never, you are only going to
have more projects using Gomega in the future.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/11#issuecomment-27162601
.
from ginkgo.
I agree. What do you think about ValueEqual
or BeEquivalent
(for the new matcher)?
from ginkgo.
I think BeEquivalentTo
works and conveys the intent (these are equivalent, but not - stritctly speaking - equal.). Will add it...
from ginkgo.
Just added BeEquivalentTo
matcher to gomega:
from ginkgo.
Thank you!
from ginkgo.
Related Issues (20)
- Junit report should have system-out HOT 1
- could not log in Eventually with fmt.Fprintf(GinkgoWriter) HOT 3
- Question: One Suite to rule them all HOT 2
- when using concurrency, a test case failure in a background go routine does not show which test case failed HOT 3
- Add cli flag to fail when no tests were run HOT 1
- `ginko -p 2` does not complain about having an extra argument
- How to integrate with xgo? HOT 7
- when watching, add ability to ignore hidden files (including tests!) HOT 5
- Report Portal and Gingko integration plugin
- Implement generic transformer decorator: ginkgo.ContextTransformer HOT 3
- why can't generate html report? HOT 1
- CLI: add long aliases for short options
- --focus-file should work with failing test location HOT 6
- panic when passing context AND nil in a table Entry HOT 2
- Add support for Label Sets
- support outputting the time spent on each spec HOT 1
- [feature request] Test execution and reporting controller HOT 1
- [Documentation] Fix the wrong variable call in Section "Reporting Nodes - ReportBeforeSuite and ReportAfterSuite"
- It function use only check last test case param HOT 1
- Run tests in individual process HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ginkgo.