On Mon, Mar 16, 2009 at 7:00 AM, Yun Huang Yong <y...@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
Hi Yun. Have a look at #and_yield , described at http://rspec.info/documentation/mocks/message_expectations.html . Cheers, Nick _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users