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

Guilherme Machado Cirne gcirne at gmail.com
Sat Mar 21 19:20:59 EDT 2009


I have this exact same problem. Anyone have a solution?

TIA,

-- 
Guilherme Machado Cirne
gcirne at gmail.com


On Mon, Mar 16, 2009 at 8:00 AM, Yun Huang Yong <yun at nomitor.com> wrote:

> 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
> --
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090321/fac25f89/attachment.html>


More information about the rspec-users mailing list