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
assert_match /Test/i, 'TEST'Example.assert_matchexpects a "matcher" (Regex to match against) and the "obj" the value to try and match. "msg" is simply the message to display on failure. To make this dynamic you could simply useassert_match /#{matcher}/i, valuewhere matcher is the string to match and value is the string to compare.