google-code-export / pymox

Automatically exported from code.google.com/p/pymox
0 stars 0 forks source link

__equals__ impl of MockObject is too generous; fails e.g. when passing mocks as expected arguments #32

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Record an expectation, where a mock is passed as argument to a method of 
another mock. This expectation will be fulfilled, even if another mock-instance 
is actually passed, as long as this is of the same type. Example code is 
attached.

What is the expected output? What do you see instead?
Expectation should fails. Testing for object identity in __equals__ would 
achieve this.

What version of the product are you using? On what operating system?
pymox 0.5.3, windows 7 64 bit, jython 2.5.2rc3

Please provide any additional information below.

Original issue reported on code.google.com by f.scholl...@web.de on 2 Mar 2011 at 10:41

Attachments:

GoogleCodeExporter commented 9 years ago
The issue here is equality vs identity. In your example, the two mocks are 
equal (see __eq__ for definition) but they are not identical.  If you are 
looking for identity, you can use the Is() comparator.

c.do_smth(Is(d_mock1))
m.ReplayAll()
c.do_smth(d_mock2)
m.VerifyAll()

Original comment by steve.mi...@gmail.com on 2 Mar 2011 at 9:50

GoogleCodeExporter commented 9 years ago
Alright, thank you for the hint about the Is() comparator. I didn't know it 
existed, because it's only available in the trunk, but not in the latests 0.5.3 
release.

Original comment by f.scholl...@web.de on 3 Mar 2011 at 7:33