assertion loop in test/unit?

Discussion in 'Ruby' started by tjacobs-sndr-019fdb@codegnome.org, Nov 2, 2007.

  1. Guest

    In the following snippet, the first two fields exist, the remaining do
    not. However, the test correctly tells me that replyaddr is missing, but
    never processes the last two items in the list:

    def test_fields_exist
    @fields = ['jobid', 'company', 'replyaddr', 'SEEKER_CC', 'RESUME_FILE']
    @fields.each do |field|
    assert(@reply_form.has_field?(field), "Field missing: #{field}")
    end
    end

    Why is that?

    --
    "Oh, look: rocks!"
    -- Doctor Who, "Destiny of the Daleks"
    , Nov 2, 2007
    #1
    1. Advertising

  2. Guest

    On Nov 1, 2007, at 9:17 PM, Todd A. Jacobs wrote:

    > In the following snippet, the first two fields exist, the remaining do
    > not. However, the test correctly tells me that replyaddr is
    > missing, but
    > never processes the last two items in the list:
    >
    > def test_fields_exist
    > @fields = ['jobid', 'company', 'replyaddr', 'SEEKER_CC',
    > 'RESUME_FILE']
    > @fields.each do |field|
    > assert(@reply_form.has_field?(field), "Field missing: #
    > {field}")
    > end
    > end
    >
    > Why is that?


    AFAIK the Test::Unit framework always terminates a test method at the
    first failure. To get what I think you are looking for, you might
    write something like:

    <code--not tested>
    def test_fields_present
    ['jobid', 'company'].each do |field|
    assert(@reply_form.has_field?(field), "Field missing: #{field}")
    end
    end
    def test_fields_missing
    ['replyaddr', 'SEEKER_CC', 'RESUME_FILE'].each do |field|
    assert(not @reply_form.has_field?(field), "Field present: #
    {field}")
    end
    end
    </code>

    Regards, Morton
    , Nov 2, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    169
    Bret Pettichord
    Oct 7, 2005
  2. aidy
    Replies:
    2
    Views:
    146
    Tim Pease
    Apr 16, 2007
  3. Curt Sampson
    Replies:
    3
    Views:
    114
    Phlip
    Aug 11, 2007
  4. John Smith

    Test::unit assertion pass scenario

    John Smith, Dec 30, 2009, in forum: Ruby
    Replies:
    12
    Views:
    256
    Phillip Gawlowski
    Dec 31, 2009
  5. timr
    Replies:
    2
    Views:
    164
Loading...

Share This Page