mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Keep quietly and capture undeprecated on your suite
This commit is contained in:
parent
af2ffa8c79
commit
3121412cf1
10 changed files with 140 additions and 21 deletions
|
@ -895,4 +895,14 @@ class CopyMigrationsTest < ActiveRecord::TestCase
|
||||||
ensure
|
ensure
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -288,6 +288,25 @@ module ActiveRecord
|
||||||
@configuration.merge('port' => 10000),
|
@configuration.merge('port' => 10000),
|
||||||
filename)
|
filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
class MySQLStructureLoadTest < ActiveRecord::TestCase
|
class MySQLStructureLoadTest < ActiveRecord::TestCase
|
||||||
|
|
|
@ -30,14 +30,6 @@ class KernelTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_silence_stderr
|
|
||||||
old_stderr_position = STDERR.tell
|
|
||||||
silence_stderr { STDERR.puts 'hello world' }
|
|
||||||
assert_equal old_stderr_position, STDERR.tell
|
|
||||||
rescue Errno::ESPIPE
|
|
||||||
# Skip if we can't STDERR.tell
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_silence_stream
|
def test_silence_stream
|
||||||
old_stream_position = STDOUT.tell
|
old_stream_position = STDOUT.tell
|
||||||
silence_stream(STDOUT) { STDOUT.puts 'hello world' }
|
silence_stream(STDOUT) { STDOUT.puts 'hello world' }
|
||||||
|
@ -56,9 +48,11 @@ class KernelTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_quietly
|
def test_quietly
|
||||||
old_stdout_position, old_stderr_position = STDOUT.tell, STDERR.tell
|
old_stdout_position, old_stderr_position = STDOUT.tell, STDERR.tell
|
||||||
quietly do
|
assert_deprecated do
|
||||||
puts 'see me, feel me'
|
quietly do
|
||||||
STDERR.puts 'touch me, heal me'
|
puts 'see me, feel me'
|
||||||
|
STDERR.puts 'touch me, heal me'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
assert_equal old_stdout_position, STDOUT.tell
|
assert_equal old_stdout_position, STDOUT.tell
|
||||||
assert_equal old_stderr_position, STDERR.tell
|
assert_equal old_stderr_position, STDERR.tell
|
||||||
|
@ -66,10 +60,6 @@ class KernelTest < ActiveSupport::TestCase
|
||||||
# Skip if we can't STDERR.tell
|
# Skip if we can't STDERR.tell
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_silence_stderr_with_return_value
|
|
||||||
assert_equal 1, silence_stderr { 1 }
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_class_eval
|
def test_class_eval
|
||||||
o = Object.new
|
o = Object.new
|
||||||
class << o; @x = 1; end
|
class << o; @x = 1; end
|
||||||
|
@ -77,10 +67,18 @@ class KernelTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_capture
|
def test_capture
|
||||||
assert_equal 'STDERR', capture(:stderr) { $stderr.print 'STDERR' }
|
assert_deprecated do
|
||||||
assert_equal 'STDOUT', capture(:stdout) { print 'STDOUT' }
|
assert_equal 'STDERR', capture(:stderr) { $stderr.print 'STDERR' }
|
||||||
assert_equal "STDERR\n", capture(:stderr) { system('echo STDERR 1>&2') }
|
end
|
||||||
assert_equal "STDOUT\n", capture(:stdout) { system('echo STDOUT') }
|
assert_deprecated do
|
||||||
|
assert_equal 'STDOUT', capture(:stdout) { print 'STDOUT' }
|
||||||
|
end
|
||||||
|
assert_deprecated do
|
||||||
|
assert_equal "STDERR\n", capture(:stderr) { system('echo STDERR 1>&2') }
|
||||||
|
end
|
||||||
|
assert_deprecated do
|
||||||
|
assert_equal "STDOUT\n", capture(:stdout) { system('echo STDOUT') }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -355,4 +355,21 @@ class DeprecationTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
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
|
||||||
|
|
|
@ -100,6 +100,23 @@ module Rails
|
||||||
dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
|
dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
|
||||||
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
|
||||||
|
|
|
@ -26,3 +26,26 @@ end
|
||||||
def jruby_skip(message = '')
|
def jruby_skip(message = '')
|
||||||
skip message if defined?(JRUBY_VERSION)
|
skip message if defined?(JRUBY_VERSION)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class ActiveSupport::TestCase
|
||||||
|
private
|
||||||
|
|
||||||
|
unless defined?(:capture)
|
||||||
|
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
|
||||||
|
|
|
@ -242,7 +242,7 @@ class ActionsTest < Rails::Generators::TestCase
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def action(*args, &block)
|
def action(*args, &block)
|
||||||
silence(:stdout){ generator.send(*args, &block) }
|
capture(:stdout){ generator.send(*args, &block) }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -490,7 +490,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def action(*args, &block)
|
def action(*args, &block)
|
||||||
silence(:stdout) { generator.send(*args, &block) }
|
capture(:stdout) { generator.send(*args, &block) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_gem(gem)
|
def assert_gem(gem)
|
||||||
|
|
|
@ -41,4 +41,12 @@ module GeneratorsTestHelper
|
||||||
FileUtils.mkdir_p(destination)
|
FileUtils.mkdir_p(destination)
|
||||||
FileUtils.cp routes, destination
|
FileUtils.cp routes, destination
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def quietly
|
||||||
|
silence_stream(STDOUT) do
|
||||||
|
silence_stream(STDERR) do
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -291,6 +291,33 @@ class ActiveSupport::TestCase
|
||||||
include TestHelpers::Paths
|
include TestHelpers::Paths
|
||||||
include TestHelpers::Rack
|
include TestHelpers::Rack
|
||||||
include TestHelpers::Generation
|
include TestHelpers::Generation
|
||||||
|
|
||||||
|
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
|
||||||
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