psyho / bogus

Fake library for Ruby
Other
359 stars 14 forks source link

#send #66

Closed tpendragon closed 9 years ago

tpendragon commented 9 years ago

Should calls to #send(:method, args) be recorded as if you called .method(args), for purposes of verifying contracts? Trying to de-duplicate some common accessor code, and I can't do it without eval.

psyho commented 9 years ago

This one is a bit tricky, because send is pretty often overwritten (as in message.send). Double recording sends will pollute the interaction list and probably sometimes lead to incorrect results.

An alternative (which already works) is to use __send__ instead of send in your code. It's a bit more verbose, but it's pretty much never overwritten (and I would consider it a very bad practice to overwrite that method) and the __send__ calls are recorded exactly as you'd expect.

tpendragon commented 9 years ago

@psyho That solves my problems. :)