diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index f7a4be817f49b1d6fd5e19c2d19297f4d4f69a88..9d385fc514098299444766959d48ad8c86cba22f 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -256,12 +256,15 @@ class Formulary
   end
 
   def self.to_rack(ref)
-    # First, check whether the rack with the given name exists.
+    # If using a fully-scoped reference, check if the formula can be resolved.
+    factory(ref) if ref.include? "/"
+
+    # Check whether the rack with the given name exists.
     if (rack = HOMEBREW_CELLAR/File.basename(ref, ".rb")).directory?
       return rack.resolved_path
     end
 
-    # Second, use canonical name to locate rack.
+    # Use canonical name to locate rack.
     (HOMEBREW_CELLAR/canonical_name(ref)).resolved_path
   end
 
diff --git a/Library/Homebrew/test/test_formulary.rb b/Library/Homebrew/test/test_formulary.rb
index 7c7ad3e74a4c4c063759b52b1029dc1fdcfc8640..7a3ab65e0aef98e0dbea036c9ca260ff605cf50e 100644
--- a/Library/Homebrew/test/test_formulary.rb
+++ b/Library/Homebrew/test/test_formulary.rb
@@ -111,6 +111,15 @@ class FormularyFactoryTest < Homebrew::TestCase
   def test_load_from_contents
     assert_kind_of Formula, Formulary.from_contents(@name, @path, @path.read)
   end
+
+  def test_to_rack
+    assert_equal HOMEBREW_CELLAR/@name, Formulary.to_rack(@name)
+    (HOMEBREW_CELLAR/@name).mkpath
+    assert_equal HOMEBREW_CELLAR/@name, Formulary.to_rack(@name)
+    assert_raises(TapFormulaUnavailableError) { Formulary.to_rack("a/b/#{@name}") }
+  ensure
+    FileUtils.rm_rf HOMEBREW_CELLAR/@name
+  end
 end
 
 class FormularyTapFactoryTest < Homebrew::TestCase