Blob Blame History Raw
From 79953c476c51ab407ab3e75b12e5f3d63b6a0a61 Mon Sep 17 00:00:00 2001
From: John Hawthorn <john@hawthorn.email>
Date: Wed, 14 Aug 2019 10:39:55 -0700
Subject: [PATCH] Allow tests to run without a TTY

We had two tests which assigned IO.console.winsize (to ensure output was
consistent), however it's possible for IO.console to be nil.

This commit makes these tests stub IO.console_size directly (the method
we actually call, we shouldn't have been relying on that calling
IO.console.winsize anyways) or passes the width when initializing the
class.

This allows tests to run without a TTY. This can be tested with ex.

    ssh localhost "cd src/rails/actionpack && bundle exec rake"

or

    (setsid bundle exec rake) </dev/null |& cat
---
 actionpack/lib/action_dispatch/routing/inspector.rb | 11 ++++++-----

diff --git a/actionpack/lib/action_dispatch/routing/inspector.rb b/actionpack/lib/action_dispatch/routing/inspector.rb
index bf286c299dba..e60f43ed2dbb 100644
--- a/actionpack/lib/action_dispatch/routing/inspector.rb
+++ b/actionpack/lib/action_dispatch/routing/inspector.rb
@@ -200,6 +200,11 @@ def widths(routes)
       end
 
       class Expanded < Base
+        def initialize(width: IO.console_size.second)
+          @width = width
+          super()
+        end
+
         def section_title(title)
           @buffer << "\n#{"[ #{title} ]"}"
         end
@@ -222,11 +227,7 @@ def draw_expanded_section(routes)
           end
 
           def route_header(index:)
-            console_width = IO.console_size.second
-            header_prefix = "--[ Route #{index} ]"
-            dash_remainder = [console_width - header_prefix.size, 0].max
-
-            "#{header_prefix}#{'-' * dash_remainder}"
+            "--[ Route #{index} ]".ljust(@width, "-")
           end
       end
     end