[rspec-users] Cherry-picking mocks?!
pergesu at gmail.com
Mon Jun 2 14:50:56 EDT 2008
On Mon, Jun 2, 2008 at 11:38 AM, Rick DeNatale <rick.denatale at gmail.com> wrote:
> A colleague just came in and asked me about a problem he was having with
> stub_render, which reminded me of another issue he had a week or so ago,
> which seems related.
> Let me start with the earlier issue.
> He was trying to write specs for a method which sends the same message
> possibly multiple times, but with different arguments under different
> calling conditions. He wanted to write
> except that the other calls would cause this to fail. He was trying to get
> this to work by specifying ordered expectations but this was getting messy.
> What he really wanted was some kind of paired mock and stub, so that the
> expectation that the method would be invoked with the given arguments could
> be verified, but the other calls would just be stubbed.
> Now after today's question, and understanding how expect_render and
> mock_render differ from normal expectations, these seem to be related.
> Maybe we should be able to say something like:
> something_else.expects(:bar).with(arguments).otherwise(:pass) # if the
> arguments don't match pass the method to the real object
> Which is really just a strawman to see if a discussion ensues. There are
> other issues like providing return values, and perhaps optionally passing a
> method through after verification that it was called with the expected
I've never used *_render before so I'm going to ignore that part.
I just tried out
describe "Mixed mocks and stubs" do
@object = Object.new
it "should allow both mocking and stubbing" do
@object.foo(:mock).should == 2 #mock
@object.foo.should == 1 #stub
and it passes. Would that be helpful to your coworker's situation?
More information about the rspec-users