From af4cef024b40fd425ea7e24fd648591ccd196327 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 25 Jul 2017 15:01:33 +0900 Subject: Extract `assert_output` and `available_pty?` into `ConsoleHelpers` module We define almost the same method with multiple tests. Therefore, it extract into module. --- railties/test/application/console_test.rb | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'railties/test/application/console_test.rb') diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index 057d473870..31bef82ccc 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -1,4 +1,5 @@ require "isolation/abstract_unit" +require "console_helpers" class ConsoleTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation @@ -93,14 +94,11 @@ class ConsoleTest < ActiveSupport::TestCase end end -begin - require "pty" -rescue LoadError -end - class FullStackConsoleTest < ActiveSupport::TestCase + include ConsoleHelpers + def setup - skip "PTY unavailable" unless defined?(PTY) && PTY.respond_to?(:open) + skip "PTY unavailable" unless available_pty? build_app app_file "app/models/post.rb", <<-CODE @@ -116,24 +114,11 @@ class FullStackConsoleTest < ActiveSupport::TestCase teardown_app end - def assert_output(expected, timeout = 1) - timeout = Time.now + timeout - - output = "" - until output.include?(expected) || Time.now > timeout - if IO.select([@master], [], [], 0.1) - output << @master.read(1) - end - end - - assert_includes output, expected, "#{expected.inspect} expected, but got:\n\n#{output}" - end - def write_prompt(command, expected_output = nil) @master.puts command - assert_output command - assert_output expected_output if expected_output - assert_output "> " + assert_output command, @master + assert_output expected_output, @master if expected_output + assert_output "> ", @master end def spawn_console(options) @@ -142,7 +127,7 @@ class FullStackConsoleTest < ActiveSupport::TestCase in: @slave, out: @slave, err: @slave ) - assert_output "> ", 30 + assert_output "> ", @master, 30 end def test_sandbox -- cgit v1.2.3