vendredi 21 septembre 2018

How emulate 100% coverage for double check expression?

I have some code, where there are two checks for zero price (for example). If the first check fails, the second check will not reach the queue, or not? How can I create a test that can cover 100% of this code?

def products
  # first check on zero price
  products = database.query 'SELECT * FROM product WHERE price > 0;'
  products.map do |product|

    # second check on zero price
    unless product[:price] > 0
      warn 'wrong price'
      next
    end

    # some operation under product
  end
end

Aucun commentaire:

Enregistrer un commentaire