mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
- 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
This commit is contained in:
parent
850159bd2c
commit
166ce95f65
9 changed files with 63 additions and 150 deletions
|
@ -1,4 +1,5 @@
|
||||||
require 'cases/helper'
|
require 'cases/helper'
|
||||||
|
require 'active_support/testing/stream'
|
||||||
require 'support/ddl_helper'
|
require 'support/ddl_helper'
|
||||||
require 'support/schema_dumping_helper'
|
require 'support/schema_dumping_helper'
|
||||||
|
|
||||||
|
@ -8,6 +9,7 @@ module ActiveRecord
|
||||||
class ForeignKeyTest < ActiveRecord::TestCase
|
class ForeignKeyTest < ActiveRecord::TestCase
|
||||||
include DdlHelper
|
include DdlHelper
|
||||||
include SchemaDumpingHelper
|
include SchemaDumpingHelper
|
||||||
|
include ActiveSupport::Testing::Stream
|
||||||
|
|
||||||
class Rocket < ActiveRecord::Base
|
class Rocket < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
@ -221,17 +223,6 @@ module ActiveRecord
|
||||||
silence_stream($stdout) { migration.migrate(:down) }
|
silence_stream($stdout) { migration.migrate(:down) }
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
require 'active_support/testing/stream'
|
||||||
require "cases/helper"
|
require "cases/helper"
|
||||||
require "cases/migration/helper"
|
require "cases/migration/helper"
|
||||||
require 'bigdecimal/util'
|
require 'bigdecimal/util'
|
||||||
|
@ -718,6 +719,8 @@ if ActiveRecord::Base.connection.supports_bulk_alter?
|
||||||
end
|
end
|
||||||
|
|
||||||
class CopyMigrationsTest < ActiveRecord::TestCase
|
class CopyMigrationsTest < ActiveRecord::TestCase
|
||||||
|
include ActiveSupport::Testing::Stream
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -927,23 +930,4 @@ class CopyMigrationsTest < ActiveRecord::TestCase
|
||||||
ActiveRecord::Base.logger = old
|
ActiveRecord::Base.logger = old
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
require 'active_support/test_case'
|
require 'active_support/test_case'
|
||||||
|
require 'active_support/testing/stream'
|
||||||
|
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
# = Active Record Test Case
|
# = Active Record Test Case
|
||||||
#
|
#
|
||||||
# Defines some test assertions to test against SQL queries.
|
# Defines some test assertions to test against SQL queries.
|
||||||
class TestCase < ActiveSupport::TestCase #:nodoc:
|
class TestCase < ActiveSupport::TestCase #:nodoc:
|
||||||
|
include ActiveSupport::Testing::Stream
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
SQLCounter.clear_log
|
SQLCounter.clear_log
|
||||||
end
|
end
|
||||||
|
@ -13,23 +16,6 @@ module ActiveRecord
|
||||||
assert_equal expected.to_s, actual.to_s, message
|
assert_equal expected.to_s, actual.to_s, message
|
||||||
end
|
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
|
def capture_sql
|
||||||
SQLCounter.clear_log
|
SQLCounter.clear_log
|
||||||
yield
|
yield
|
||||||
|
|
42
activesupport/lib/active_support/testing/stream.rb
Normal file
42
activesupport/lib/active_support/testing/stream.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
module ActiveSupport
|
||||||
|
module Testing
|
||||||
|
module Stream #:nodoc:
|
||||||
|
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
|
||||||
|
|
||||||
|
def quietly
|
||||||
|
silence_stream(STDOUT) do
|
||||||
|
silence_stream(STDERR) do
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +1,5 @@
|
||||||
require 'abstract_unit'
|
require 'abstract_unit'
|
||||||
|
require 'active_support/testing/stream'
|
||||||
|
|
||||||
class Deprecatee
|
class Deprecatee
|
||||||
def initialize
|
def initialize
|
||||||
|
@ -36,6 +37,8 @@ end
|
||||||
|
|
||||||
|
|
||||||
class DeprecationTest < ActiveSupport::TestCase
|
class DeprecationTest < ActiveSupport::TestCase
|
||||||
|
include ActiveSupport::Testing::Stream
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
# Track the last warning.
|
# Track the last warning.
|
||||||
@old_behavior = ActiveSupport::Deprecation.behavior
|
@old_behavior = ActiveSupport::Deprecation.behavior
|
||||||
|
@ -356,20 +359,4 @@ class DeprecationTest < ActiveSupport::TestCase
|
||||||
deprecator
|
deprecator
|
||||||
end
|
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
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'active_support/core_ext/class/attribute'
|
||||||
require 'active_support/core_ext/module/delegation'
|
require 'active_support/core_ext/module/delegation'
|
||||||
require 'active_support/core_ext/hash/reverse_merge'
|
require 'active_support/core_ext/hash/reverse_merge'
|
||||||
require 'active_support/core_ext/kernel/reporting'
|
require 'active_support/core_ext/kernel/reporting'
|
||||||
|
require 'active_support/testing/stream'
|
||||||
require 'active_support/concern'
|
require 'active_support/concern'
|
||||||
require 'rails/generators'
|
require 'rails/generators'
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ module Rails
|
||||||
module Testing
|
module Testing
|
||||||
module Behaviour
|
module Behaviour
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
include ActiveSupport::Testing::Stream
|
||||||
|
|
||||||
included do
|
included do
|
||||||
class_attribute :destination_root, :current_path, :generator_class, :default_arguments
|
class_attribute :destination_root, :current_path, :generator_class, :default_arguments
|
||||||
|
@ -101,22 +103,6 @@ module Rails
|
||||||
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
|
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
|
||||||
end
|
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,7 @@ require File.expand_path("../../../load_paths", __FILE__)
|
||||||
|
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
require 'active_support/testing/autorun'
|
require 'active_support/testing/autorun'
|
||||||
|
require 'active_support/testing/stream'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
|
||||||
require 'active_support'
|
require 'active_support'
|
||||||
|
@ -28,26 +29,10 @@ def jruby_skip(message = '')
|
||||||
end
|
end
|
||||||
|
|
||||||
class ActiveSupport::TestCase
|
class ActiveSupport::TestCase
|
||||||
|
include ActiveSupport::Testing::Stream
|
||||||
|
|
||||||
# FIXME: we have tests that depend on run order, we should fix that and
|
# FIXME: we have tests that depend on run order, we should fix that and
|
||||||
# remove this method call.
|
# remove this method call.
|
||||||
self.test_order = :sorted
|
self.test_order = :sorted
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
require 'abstract_unit'
|
require 'abstract_unit'
|
||||||
require 'active_support/core_ext/module/remove_method'
|
require 'active_support/core_ext/module/remove_method'
|
||||||
|
require 'active_support/testing/stream'
|
||||||
require 'rails/generators'
|
require 'rails/generators'
|
||||||
require 'rails/generators/test_case'
|
require 'rails/generators/test_case'
|
||||||
|
|
||||||
|
@ -23,6 +24,8 @@ require 'action_dispatch'
|
||||||
require 'action_view'
|
require 'action_view'
|
||||||
|
|
||||||
module GeneratorsTestHelper
|
module GeneratorsTestHelper
|
||||||
|
include ActiveSupport::Testing::Stream
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
destination File.join(Rails.root, "tmp")
|
destination File.join(Rails.root, "tmp")
|
||||||
|
@ -42,21 +45,4 @@ module GeneratorsTestHelper
|
||||||
FileUtils.cp routes, destination
|
FileUtils.cp routes, destination
|
||||||
end
|
end
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
|
@ -11,6 +11,7 @@ require 'fileutils'
|
||||||
require 'bundler/setup' unless defined?(Bundler)
|
require 'bundler/setup' unless defined?(Bundler)
|
||||||
require 'active_support'
|
require 'active_support'
|
||||||
require 'active_support/testing/autorun'
|
require 'active_support/testing/autorun'
|
||||||
|
require 'active_support/testing/stream'
|
||||||
require 'active_support/test_case'
|
require 'active_support/test_case'
|
||||||
|
|
||||||
RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..")
|
RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..")
|
||||||
|
@ -309,45 +310,10 @@ class ActiveSupport::TestCase
|
||||||
include TestHelpers::Paths
|
include TestHelpers::Paths
|
||||||
include TestHelpers::Rack
|
include TestHelpers::Rack
|
||||||
include TestHelpers::Generation
|
include TestHelpers::Generation
|
||||||
|
include ActiveSupport::Testing::Stream
|
||||||
|
|
||||||
self.test_order = :sorted
|
self.test_order = :sorted
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
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 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
|
end
|
||||||
|
|
||||||
# Create a scope and build a fixture rails app
|
# Create a scope and build a fixture rails app
|
||||||
|
|
Loading…
Reference in a new issue