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
Hi Zach, I''m not fixed on the idea of the block check going away. It''s great to have your example usage. You are right that readability is one advantage of the parameter matcher classes, but another benefit is hopefully more useful error messages. Maybe the solution is to have a custom matcher which takes a block. What do you think? I''ll give it some more thought. -- James. http://blog.floehopper.org
James Mead wrote:> Hi Zach, > > I''m not fixed on the idea of the block check going away. It''s great to have > your example usage. You are right that readability is one advantage of the > parameter matcher classes, but another benefit is hopefully more useful > error messages. Maybe the solution is to have a custom matcher which takes a > block. What do you think? > > I''ll give it some more thought. >I agree - having a custom matcher that knows about procs is a cleaner solution than having the whole proc thing baked into expectations. Expecting a proc is an edge case when you are mostly mocking services. It''s normally simple value objects like strings that get passed in as parameters. Cheers, Dan
James, Yeah that''s fine with me. I''m really swamped now, but I''ll try and work out something soon and submit a patch of what I''m thinking. I do want give kudos to the team for developing a nice mocking library. It hasn''t been a silver bullet, but it does make my testing much easier. -Zach On Jun 22, 2007, at 8:26 AM, Dan North wrote:> James Mead wrote: >> Hi Zach, >> >> I''m not fixed on the idea of the block check going away. It''s >> great to have >> your example usage. You are right that readability is one >> advantage of the >> parameter matcher classes, but another benefit is hopefully more >> useful >> error messages. Maybe the solution is to have a custom matcher >> which takes a >> block. What do you think? >> >> I''ll give it some more thought. >> > I agree - having a custom matcher that knows about procs is a cleaner > solution than having the whole proc thing baked into expectations. > Expecting a proc is an edge case when you are mostly mocking services. > It''s normally simple value objects like strings that get passed in as > parameters. > > Cheers, > Dan > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer