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/test/dispatch/routing/inspector_test.rb  |  7 +------

diff --git a/actionpack/test/dispatch/routing/inspector_test.rb b/actionpack/test/dispatch/routing/inspector_test.rb
index fe1f1995d84d..b1dd71995547 100644
--- a/actionpack/test/dispatch/routing/inspector_test.rb
+++ b/actionpack/test/dispatch/routing/inspector_test.rb
@@ -317,9 +317,6 @@ def test_routes_can_be_filtered
       end
 
       def test_routes_when_expanded
-        previous_console_winsize = IO.console.winsize
-        IO.console.winsize = [0, 23]
-
         engine = Class.new(Rails::Engine) do
           def self.inspect
             "Blog::Engine"
@@ -329,7 +326,7 @@ def self.inspect
           get "/cart", to: "cart#show"
         end
 
-        output = draw(formatter: ActionDispatch::Routing::ConsoleFormatter::Expanded.new) do
+        output = draw(formatter: ActionDispatch::Routing::ConsoleFormatter::Expanded.new(width: 23)) do
           get "/custom/assets", to: "custom_assets#show"
           get "/custom/furnitures", to: "custom_furnitures#show"
           mount engine => "/blog", :as => "blog"
@@ -357,8 +354,6 @@ def self.inspect
                       "Verb              | GET",
                       "URI               | /cart(.:format)",
                       "Controller#Action | cart#show"], output
-      ensure
-        IO.console.winsize = previous_console_winsize
       end
 
       def test_no_routes_matched_filter_when_expanded