Feature Requests: Browse | Submit New | Admin

[#10412] Merge 'with' and the expected method

Date:
2007-04-27 16:33
Priority:
3
Submitted By:
Brian Takita (btakita)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Merge 'with' and the expected method

Detailed description
It seems that the 'with' method can be merged with the method name expectation.
This would make mocks shorter and easier to read for some people.

Here are a couple of examples with their equivalent current syntax:

the_mock.expects.foo(1,2) {|a, b| :bar}
the_mock.expects(:foo).with(1,2) {|a, b| :bar}

the_mock.expects.foo(1,2).returns(:bar)
the_mock.expects.(:foo).with(1,2).returns(:bar)

Also, please look at the mock block feature request.
WDYT?

Add A Comment: Notepad

Please login


Followup

Message
Date: 2009-01-02 16:46
Sender: James Mead

This feature request has moved to Lighthouse [1].

[1] http://floehopper.lighthouseapp.com/projects/22289/tickets/4
Date: 2007-11-05 10:06
Sender: James Mead

Hi Steve,

Thanks for taking the time to submit a patch. I agree with you
about Brian's second example being the more compelling.

There's clearly a trade-off between adding extra complexity to
the Mocha code-base and providing an alternative API. This is
a judgement call and depends somewhat on the perceived usefulness
of the alternative API. While I like the expected method call
looking more like the actual call, I don't particularly like
the dot between the expects and foo.

I have some other ideas about this, but in the meantime I'll
take a look at your patch and see how much complexity it adds.
You might want to look at Brian's rubyforge project
- http://rubyforge.org/projects/mocha-shot/ which is a mini fork
of Mocha.

Thanks again for your interest.

Cheers, James.
http://blog.floehopper.org
Date: 2007-10-31 15:00
Sender: Steve Purcell

Okay, so I'm not permitted to attach a file to this ticket, so
I've filed my patch as #15235.  ("Patches" section
of "Tracker" for this project.)
Date: 2007-10-31 14:54
Sender: Steve Purcell

I agree.  I implemented this feature in my own (otherwise inferior)
precursor to Mocha, called mockr
(http://dev.sanityinc.com/mockr/).

Before seeing this ticket I sat down to add this "pseudo
call" behaviour to Mocha.  The attached patch implements
it in what I believe is a simpler and less intrusive way.

Note that I do not support passing block-based parameter constraints,
such as in the first of Brian's examples, since I believe it
can be confusing -- Brian's second example is the compelling
day-to-day case.
Date: 2007-05-02 09:20
Sender: Brian Takita

I am posting a patch that implements this. It's actually
pretty simple.

Attached Files:

Name Description Download
terse_mocha.patch Download

Changes:

Field Old Value Date By
File Added1909: terse_mocha.patch2007-05-02 09:20btakita