diff --git a/Library/Homebrew/test/utils_test.rb b/Library/Homebrew/test/utils_test.rb
index 7ae5793e2b18b8d0514d9c1b25ac292278ff6c49..1f2fb7b55f7f50511e2658d287dc8c1a6d9c3af7 100644
--- a/Library/Homebrew/test/utils_test.rb
+++ b/Library/Homebrew/test/utils_test.rb
@@ -9,14 +9,10 @@ class UtilTests < Homebrew::TestCase
     @dir = Pathname.new(mktmpdir)
   end
 
-  # Helper for matching escape sequences.
-  def e(code)
+  def esc(code)
     /(\e\[\d+m)*\e\[#{code}m/
   end
 
-  # Helper for matching that style is reset at the end of a string.
-  Z = /(\e\[\d+m)*\e\[0m\Z/
-
   def test_ofail
     shutup { ofail "foo" }
     assert Homebrew.failed?
@@ -32,10 +28,12 @@ class UtilTests < Homebrew::TestCase
   def test_pretty_installed
     $stdout.stubs(:tty?).returns true
     ENV.delete("HOMEBREW_NO_EMOJI")
-    assert_match(/\A#{e 1}foo #{e 32}鉁�#{Z}/, pretty_installed("foo"))
+    tty_with_emoji_output = /\A#{esc 1}foo #{esc 32}鉁�#{esc 0}\Z/
+    assert_match tty_with_emoji_output, pretty_installed("foo")
 
     ENV["HOMEBREW_NO_EMOJI"] = "1"
-    assert_match(/\A#{e 1}foo \(installed\)#{Z}/, pretty_installed("foo"))
+    tty_no_emoji_output = /\A#{esc 1}foo \(installed\)#{esc 0}\Z/
+    assert_match tty_no_emoji_output, pretty_installed("foo")
 
     $stdout.stubs(:tty?).returns false
     assert_equal "foo", pretty_installed("foo")
@@ -44,10 +42,12 @@ class UtilTests < Homebrew::TestCase
   def test_pretty_uninstalled
     $stdout.stubs(:tty?).returns true
     ENV.delete("HOMEBREW_NO_EMOJI")
-    assert_match(/\A#{e 1}foo #{e 31}鉁�#{Z}/, pretty_uninstalled("foo"))
+    tty_with_emoji_output = /\A#{esc 1}foo #{esc 31}鉁�#{esc 0}\Z/
+    assert_match tty_with_emoji_output, pretty_uninstalled("foo")
 
     ENV["HOMEBREW_NO_EMOJI"] = "1"
-    assert_match(/\A#{e 1}foo \(uninstalled\)#{Z}/, pretty_uninstalled("foo"))
+    tty_no_emoji_output = /\A#{esc 1}foo \(uninstalled\)#{esc 0}\Z/
+    assert_match tty_no_emoji_output, pretty_uninstalled("foo")
 
     $stdout.stubs(:tty?).returns false
     assert_equal "foo", pretty_uninstalled("foo")