d6a62f3
From 79953c476c51ab407ab3e75b12e5f3d63b6a0a61 Mon Sep 17 00:00:00 2001
d6a62f3
From: John Hawthorn <john@hawthorn.email>
d6a62f3
Date: Wed, 14 Aug 2019 10:39:55 -0700
d6a62f3
Subject: [PATCH] Allow tests to run without a TTY
d6a62f3
d6a62f3
We had two tests which assigned IO.console.winsize (to ensure output was
d6a62f3
consistent), however it's possible for IO.console to be nil.
d6a62f3
d6a62f3
This commit makes these tests stub IO.console_size directly (the method
d6a62f3
we actually call, we shouldn't have been relying on that calling
d6a62f3
IO.console.winsize anyways) or passes the width when initializing the
d6a62f3
class.
d6a62f3
d6a62f3
This allows tests to run without a TTY. This can be tested with ex.
d6a62f3
d6a62f3
    ssh localhost "cd src/rails/actionpack && bundle exec rake"
d6a62f3
d6a62f3
or
d6a62f3
d6a62f3
    (setsid bundle exec rake) 
d6a62f3
---
d6a62f3
 actionpack/test/dispatch/routing/inspector_test.rb  |  7 +------
d6a62f3
d6a62f3
diff --git a/actionpack/test/dispatch/routing/inspector_test.rb b/actionpack/test/dispatch/routing/inspector_test.rb
d6a62f3
index fe1f1995d84d..b1dd71995547 100644
d6a62f3
--- a/actionpack/test/dispatch/routing/inspector_test.rb
d6a62f3
+++ b/actionpack/test/dispatch/routing/inspector_test.rb
d6a62f3
@@ -317,9 +317,6 @@ def test_routes_can_be_filtered
d6a62f3
       end
d6a62f3
 
d6a62f3
       def test_routes_when_expanded
d6a62f3
-        previous_console_winsize = IO.console.winsize
d6a62f3
-        IO.console.winsize = [0, 23]
d6a62f3
-
d6a62f3
         engine = Class.new(Rails::Engine) do
d6a62f3
           def self.inspect
d6a62f3
             "Blog::Engine"
d6a62f3
@@ -329,7 +326,7 @@ def self.inspect
d6a62f3
           get "/cart", to: "cart#show"
d6a62f3
         end
d6a62f3
 
d6a62f3
-        output = draw(formatter: ActionDispatch::Routing::ConsoleFormatter::Expanded.new) do
d6a62f3
+        output = draw(formatter: ActionDispatch::Routing::ConsoleFormatter::Expanded.new(width: 23)) do
d6a62f3
           get "/custom/assets", to: "custom_assets#show"
d6a62f3
           get "/custom/furnitures", to: "custom_furnitures#show"
d6a62f3
           mount engine => "/blog", :as => "blog"
d6a62f3
@@ -357,8 +354,6 @@ def self.inspect
d6a62f3
                       "Verb              | GET",
d6a62f3
                       "URI               | /cart(.:format)",
d6a62f3
                       "Controller#Action | cart#show"], output
d6a62f3
-      ensure
d6a62f3
-        IO.console.winsize = previous_console_winsize
d6a62f3
       end
d6a62f3
 
d6a62f3
       def test_no_routes_matched_filter_when_expanded