[mocha-developer] With Parameter Block

Zach Moazeni zach.lists at gmail.com
Thu Jun 21 09:55:17 EDT 2007


I'm curious why the Parameter block check for the with is going to be  
removed.

I like the concept of clean, readable tests, however I also like to  
test as efficiently as possible. For some tests, I'll take the  
approach of putting test assertions inside the parameter block, and  
always returning true.

This is a contrived example:

def test_something
   mock = mock("some_mock")
   mock.expects(:foo).with do | param_that_is_a_string,  
param_that_is_a_model |
     assert_match(/something-for1/, param_that_is_a_string)
     assert param_that_is_a_model.valid?
     true
   end.returns("blah")
end

Again, I'm not against code readability, but I do prefer to be able  
to write my tests explicitly instead of creating a matcher for each  
special case.

-Zach


More information about the mocha-developer mailing list