Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:21:39+00:00 2026-06-17T22:21:39+00:00

I’m using Ruby 1.9.3 with MiniTest. I know the best practice is to have

  • 0

I’m using Ruby 1.9.3 with MiniTest. I know the best practice is to have one assertion per test, but there are cases wherein I want to dynamically make assertions, like when comparing arrays:

if added_skus.each { |s| assert(skus_in_cart.include?(s), "SKUs #{added_skus} or SKU amount do not match SKUs #{skus_in_cart} on Cart page.") }
  puts "Product SKUs #{added_skus} match SKUs #{skus_in_cart} on Cart page."
end

As you know, when it hits the first assertion failure the test ends. I’d like to continue the test and report all failures after the test has finished.

I found a solution using an old version of test/unit and Ruby 1.8.7 (the add_failure method in the test/unit library), but I can’t find a good solution for MiniTest and Ruby 1.9.3. I would really appreciate some feedback (even if that means I’m doing it wrong – please point me in the right direction). Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:21:40+00:00Added an answer on June 17, 2026 at 10:21 pm

    Solution 1 – Combine assertions into a single assertion:

    You could write your current code as a single assertion by considering all the skus together:

    #Determine the missing skus:
    missing_skus = added_skus.find_all{ |s| not(skus_in_cart.include?(s)) }
    
    #Assert that there are no missing skus:
    assert( missing_skus.empty?, "SKUs #{missing_skus} do not match SKUs on Cart page." )
    

    Solution 2 – Custom method for asserting multiple elements:

    If you really want the assertion count to be per individual SKU (instead of the entire set), you could create a custom assertion method. Though I do not believe this adds any real benefit over Solution 1.

    Example running code:

    require ‘test/unit’

    module MiniTest::Assertions
        #Asserts that each element passes the test
        # Inputs:
        #   enumerable - The object to iterate over (ex an array)
        #   msg - Custom message to include in assertion failure
        #   test - A block that each element will be tested against
        def assert_each(enumerable, msg = nil, &test)
            msg ||= "No message given."
    
            failed_elements = Array.new
            enumerable.each do |e|
                self._assertions += 1
                failed_elements << e unless yield(e)
            end
    
            msg = " #{failed_elements} failed assertion. #{msg}"    
            raise( MiniTest::Assertion, msg ) unless failed_elements.empty?
        end
    end
    
    class MyTest < Test::Unit::TestCase
        def test()
            added_skus = ['b', 'a', 'c', 'd']
            skus_in_cart = ['c', 'b']
    
            assert_each(added_skus, "SKUs missing from cart."){ |s| skus_in_cart.include?(s) }
        end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.