From: nathaniel@... Date: 2003-01-22T15:31:01+09:00 Subject: Re: iterating in a test Paul Brannan [mailto:pbrannan@atdesk.com] wrote: > On Sat, Jan 11, 2003 at 01:58:07AM +0900, Nathaniel Talbott wrote: > > How about (untested): > > > > 10.times { |i| > > assert_nothing_raised("Testing f where i=#{i}") { > > assert_equal(1, f(i), "Testing f where i=#{i}") > > } > > } > > In this case I still have to duplicate the message for the > assert_nothing_raised and the assert_equal call. Hmmm... you're right - I should've used a temp var to store the message ;-). Seriously, that doesn't seem like a hardship to me, and it seems much simpler than what you propose below... > What I think I'd like to see is something like this: > > def test_foo > 10.times do |i| > performing_action("Testing f(x) where i=#{i}") do > assert_equal 1, f(i) > some_helper_function(1) > end > end > end > > def some_helper_function(i) > performing_action("inside the helper function") do > # make some assertions here > end > end > > The performing_action() method could append the passed string onto an > array at the start of the block (and remove it at the end), so I have > a list of actions that I'm in the middle of performing. This list of > actions should be printed for every failed assertion and every > exception that escapes. def performing_action(message) # Not tested @message_stack ||= [] @message_stack.push(message) begin yield rescue Exception raise $!, [$!.message, *@message_stack].join("\n"), $!.backtrace ensure @message_stack.pop end end It's seems overly complex for me to want to use it, though; if the simpler solution I gave above wouldn't work, I'd probably start looking to refactor my tests. Just my $0.02. HTH, Nathaniel <:((>< + - - | RoleModel Software, Inc. | EQUIP VI