Bug #770: assert_match should escape string argument
http://redmine.ruby-lang.org/issues/show/770

Author: Jeremy Kemper
Status: Open, Priority: Normal
Assigned to: Ryan Davis

String expectation for assert_match should be matched literally, not as a regexp.

test/unit: assert_match '.', 'a'  #=> fails
minitest: assert_match '.', 'a' #=> passes

Index: lib/minitest/unit.rb
===================================================================
--- lib/minitest/unit.rb	(revision 20290)
+++ lib/minitest/unit.rb	(working copy)
@@ -118,7 +118,7 @@
     def assert_match exp, act, msg = nil
       msg = message(msg) { "Expected #{mu_pp(act)} to match #{mu_pp(exp)}" }
       assert_respond_to act, :"=~"
-      (exp = /#{exp}/) if String === exp && String === act
+      (exp = /#{Regexp.escape(exp)}/) if String === exp && String === act
       assert act =~ exp, msg
     end


----------------------------------------
http://redmine.ruby-lang.org