[rspec-users] Testing return value of a block argument

Yun Huang Yong yun at nomitor.com
Mon Mar 16 07:00:02 EDT 2009


Hi,

I'm using Log4r and one of its neat features is its handling of blocks 
such that you can do:
   log.debug { "Something bad happened" + some_expensive_method() }
instead of:
   log.debug("Something bad happened" + some_expensive_method())

The benefit of the former is that some_expensive_method() is not 
executed until the debug() method executes so if your log level doesn't 
include DEBUG you don't suffer the performance hit of calling 
some_expensive_method() needlessly.

Is there any way to test what the resultant log message is from 
evaluating the block?

i.e. something like:
   log_mock.should_receive(:debug) { |log_block|
     # execute log_block, and check its return value
   }

I have a simple bit of code to tinker with: http://gist.github.com/79820

Thanks in advance,
yun

-- 
Yun Huang Yong
yun at nomitor.com                  ...nom nom nom
--


More information about the rspec-users mailing list