You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect to be able to define a partial mock (i.e. flexmock(realobject)), use the object and then test against what messages were sent to the real object. Here's an example of what I mean using a flexmock on a class:
require'spec_helper'classFooclass << selfattr_accessor:track_this_valueendenddescribe"spying and passing through"dobefore{flexmock(Foo)}subject{Foo}before{Foo.track_this_value="baz"}its(:track_this_value){should == "baz"}# it passes throughit"records methods on the mocked class"doFoo.shouldhave_received(:track_this_value)endend
The test does pass the its(:track_this_value) expectation, but not the should have_received. Instead I get:
1) spying and passing through records methods on the mocked class
Failure/Error: Foo.should have_received(:track_this_value)
expected track_this_value(...) to be received by Foo.
No messages have been received
# ./spec/spy_spec.rb:16:in `block (2 levels) in <top (required)>'
The text was updated successfully, but these errors were encountered:
I haven't responded to this, and I apologize for this.
I am a little worried about performance. If we spy on every method, then we have to proxy every method on the object. To do that by default means that every partial object gets that overhead, even if they never take advantage of the spy calls.
Perhaps we can flag those mocks that need to have all their methods spied upon. Something like flexmock(Foo, :fullspy) (or :spyall, or :mole, or .... something).
Thoughts? Meanwhile, I'll investigate the performance impact and see if my concerns are valid.
I would expect to be able to define a partial mock (i.e.
flexmock(realobject)
), use the object and then test against what messages were sent to the real object. Here's an example of what I mean using a flexmock on a class:The test does pass the
its(:track_this_value)
expectation, but not theshould have_received
. Instead I get:The text was updated successfully, but these errors were encountered: