lundi 25 juillet 2016

Ruby unit test assert match case insensitive strings

In a Ruby unit test, how do I assert that a string matches another string even though the casing might be different? I want to avoid sanitizing the two strings to match incase I need to come back and do some investigation but at the same time they are the same outcomes.

e.g assert_match 'Test', 'TEST'

I've tried fudging with assert_match to make an case insensitive compare but I have had no luck thus far and I cannot get past the old implicit conversion of Regexp into String.

module Test::Unit::Assertions
  def assert_match matcher, obj, msg = nil
    msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
    assert_respond_to matcher, :"=~"
    matcher = Regexp.new Regexp.escape matcher if String === matcher
    assert matcher =~ /#{obj}/i, /#{msg}/i
  end
end

Aucun commentaire:

Enregistrer un commentaire