From 166ce95f65cd6b54e23d43e0e61875d6c3a38047 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Thu, 15 Jan 2015 12:12:33 +0530 Subject: - Extracted silence_stream method to new module in activesupport/testing. - Added include for the same in ActiveSupport::Test. - Removed occurrences of silence_stream being used elsewhere. - Reordered activesupport testcase requires alphabetically. - Removed require of silence stream from test_case - Moved quietly method to stream helper - Moved capture output to stream helper module and setup requires for the same elsewhere --- .../test/cases/migration/foreign_key_test.rb | 13 ++----------- activerecord/test/cases/migration_test.rb | 22 +++------------------- activerecord/test/cases/test_case.rb | 20 +++----------------- 3 files changed, 8 insertions(+), 47 deletions(-) (limited to 'activerecord') diff --git a/activerecord/test/cases/migration/foreign_key_test.rb b/activerecord/test/cases/migration/foreign_key_test.rb index f8b1bf8c9d..7effde2618 100644 --- a/activerecord/test/cases/migration/foreign_key_test.rb +++ b/activerecord/test/cases/migration/foreign_key_test.rb @@ -1,4 +1,5 @@ require 'cases/helper' +require 'active_support/testing/stream' require 'support/ddl_helper' require 'support/schema_dumping_helper' @@ -8,6 +9,7 @@ module ActiveRecord class ForeignKeyTest < ActiveRecord::TestCase include DdlHelper include SchemaDumpingHelper + include ActiveSupport::Testing::Stream class Rocket < ActiveRecord::Base end @@ -221,17 +223,6 @@ module ActiveRecord silence_stream($stdout) { migration.migrate(:down) } end - private - - def silence_stream(stream) - old_stream = stream.dup - stream.reopen(IO::NULL) - stream.sync = true - yield - ensure - stream.reopen(old_stream) - old_stream.close - end end end end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 7c2d3e81d6..aed9db997a 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1,3 +1,4 @@ +require 'active_support/testing/stream' require "cases/helper" require "cases/migration/helper" require 'bigdecimal/util' @@ -718,6 +719,8 @@ if ActiveRecord::Base.connection.supports_bulk_alter? end class CopyMigrationsTest < ActiveRecord::TestCase + include ActiveSupport::Testing::Stream + def setup end @@ -927,23 +930,4 @@ class CopyMigrationsTest < ActiveRecord::TestCase ActiveRecord::Base.logger = old end - private - - def quietly - silence_stream(STDOUT) do - silence_stream(STDERR) do - yield - end - end - end - - def silence_stream(stream) - old_stream = stream.dup - stream.reopen(IO::NULL) - stream.sync = true - yield - ensure - stream.reopen(old_stream) - old_stream.close - end end diff --git a/activerecord/test/cases/test_case.rb b/activerecord/test/cases/test_case.rb index 5ba17359f0..e0b01ae8e0 100644 --- a/activerecord/test/cases/test_case.rb +++ b/activerecord/test/cases/test_case.rb @@ -1,10 +1,13 @@ require 'active_support/test_case' +require 'active_support/testing/stream' module ActiveRecord # = Active Record Test Case # # Defines some test assertions to test against SQL queries. class TestCase < ActiveSupport::TestCase #:nodoc: + include ActiveSupport::Testing::Stream + def teardown SQLCounter.clear_log end @@ -13,23 +16,6 @@ module ActiveRecord assert_equal expected.to_s, actual.to_s, message end - def capture(stream) - stream = stream.to_s - captured_stream = Tempfile.new(stream) - stream_io = eval("$#{stream}") - origin_stream = stream_io.dup - stream_io.reopen(captured_stream) - - yield - - stream_io.rewind - return captured_stream.read - ensure - captured_stream.close - captured_stream.unlink - stream_io.reopen(origin_stream) - end - def capture_sql SQLCounter.clear_log yield -- cgit v1.2.3