Yotta Meter wrote:
> Another question, is my philosophy off? I'm a little confused by the 
> amount of test options out there, rspec, cucumber, etc.

Well, they're apples and oranges to some extent. rspec is similar in 
concept to Test::Unit but with a very different syntax (which I 
personally dislike, so I stick to Test::Unit). But as far as I know, 
assertion failures in rspec also raise exceptions and so can't continue. 
There are a whole bunch of alternative test frameworks out there, but I 
don't know enough about any of them to say whether they would fit your 
needs better.

Cucumber works at a different layer. It sits on top of either rspec or 
test/unit and lets you write tests in plain language, using regexps to 
match that plain language and turn it into actual test code. But again, 
if one step fails within a scenario, the remaining steps are skipped.

> Is there another 
> testing strategy I should be working with in this instance where I want 
> to iterate through an array of complex objects?

Apart from the ideas I gave before, you could try rescuing 
Test::Unit::AssertionFailedError explicitly inside your loop, to allow 
it to continue (but making a note of the failure).

Indeed, the core code for Test::Unit which handles this looks very 
simple:

      # Runs the individual test method represented by this
      # instance of the fixture, collecting statistics, failures
      # and errors in result.
      def run(result)
        yield(STARTED, name)
        @_result = result
        begin
          setup
          __send__(@method_name)
        rescue AssertionFailedError => e
          add_failure(e.message, e.backtrace)
        rescue Exception
          raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
          add_error($!)
        ensure
          begin
            teardown
          rescue AssertionFailedError => e
            add_failure(e.message, e.backtrace)
          rescue Exception
            raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
            add_error($!)
          end
        end
        result.add_run
        yield(FINISHED, name)
      end

So it looks like you could just call add_failure yourself and continue. 
This is a private method/undocumented API, but I'd happily do that if it 
gets the job done.

Here's a proof-of-concept:

require "test/unit"

class TestImplArchFile < Test::Unit::TestCase

  def no_stop
    yield
  rescue Test::Unit::AssertionFailedError => e
    add_failure(e.message, e.backtrace)
  rescue Exception
    raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
    add_error($!)
  end

  def test_loop
    [0,1,2].each do |i|
      no_stop do
        assert_equal(i, 6, "Duh, #{i} is not equal to 6.")
      end
    end
  end

end
-- 
Posted via http://www.ruby-forum.com/.