[mocha-developer] using mocha with rspec

Dan North dan at tastapod.com
Tue Mar 13 08:41:15 EDT 2007


I came up with a hacky way of doing named matchers by using lambdas:

first_arg_is_chewable = proc {|arg1, arg2| arg1.is_a? Chewable }
# ...
sheep.expects(:chew).with(&first_arg_is_chewable)

which while readable is fugly :)  I used it when I wanted to reuse the 
same with-block.

But yes, positional matchers would be much easier on both the eye and 
the brain!

James Mead wrote:
> On 13/03/07, Dan North <dan at tastapod.com> wrote:
>   
>> The big things on my wishlist are:
>>
>> 1. Matchers in with(..) like JMock has:
>> expects(:chew).with(is_a(Chewable), ANYTHING) where is_a(..) is a
>> [something] that responds to matches?(actual) with true/false, and
>> ANYTHING is a matcher that always returns true. That way, you could use
>> rspec's expectation matcher framework or roll your own matchers. (I've
>> got a bunch I wrote for my own mocking framework - everyone should write
>> a mocking framework at least twice once :)
>>
>> The method matches?(actual) seems fairly universal across these
>> frameworks.
>>     
>
>
> Something like this has been on the drawing board for a while.
>
> You can currently achieve something similar by using a block on the call to
> with(), but I admit the syntax is not great.
>
> expects(:chew).with { |mouthful1, mouthful2| mouthful1.is_a?(Chewable) }
>
> 2. Type-aware mocks that fail with a NoMethodError if the underlying
>   
>> type doesn't respond to an invoked method or method_missing (see earlier
>> thread).
>>     
>
>
>
> 3. Something akin to after(another_mock, :method).
>   
>> None of these are showstoppers, but 1 is really high on my priorities
>> and 2 and 3 would make my life happier. I might try to roll something
>> for 1 if I get the time (read: unlikely!).
>>
>>     
>
> Cool. My bandwidth is a bit limited at the moment too, but I'll see what we
> can do.
>
> Thanks for your constructive suggestions.
>
>   



More information about the mocha-developer mailing list