mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Remove AS::Testing::Stream in favor of Minitest assert_output
This commit is contained in:
parent
e35390623d
commit
fcdb58f67d
@ -222,7 +222,6 @@ Style/TrailingBlankLines:
|
||||
- 'test/adapter/null_test.rb'
|
||||
- 'test/serializers/cache_test.rb'
|
||||
- 'test/serializers/fieldset_test.rb'
|
||||
- 'test/support/stream_capture.rb'
|
||||
|
||||
# Offense count: 5
|
||||
# Cop supports --auto-correct.
|
||||
|
||||
@ -3,7 +3,6 @@ require 'test_helper'
|
||||
module ActionController
|
||||
module Serialization
|
||||
class ImplicitSerializerTest < ActionController::TestCase
|
||||
include ActiveSupport::Testing::Stream
|
||||
class ImplicitSerializationTestController < ActionController::Base
|
||||
include SerializationTesting
|
||||
def render_using_implicit_serializer
|
||||
@ -438,9 +437,9 @@ module ActionController
|
||||
false
|
||||
end
|
||||
end.new
|
||||
assert_match(/adapter: false/, (capture(:stderr) do
|
||||
assert_output(nil, /adapter: false/) do
|
||||
controller.get_serializer(Profile.new)
|
||||
end))
|
||||
end
|
||||
end
|
||||
|
||||
def test_dont_warn_overridding_use_adapter_as_truthy_on_controller_instance
|
||||
@ -449,9 +448,9 @@ module ActionController
|
||||
true
|
||||
end
|
||||
end.new
|
||||
assert_equal '', (capture(:stderr) do
|
||||
assert_output(nil, '') do
|
||||
controller.get_serializer(Profile.new)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_event_is_emmited
|
||||
|
||||
@ -6,11 +6,11 @@ module ActiveModel
|
||||
# Minitest.run_one_method isn't present in minitest 4
|
||||
if $minitest_version > 4 # rubocop:disable Style/GlobalVars
|
||||
class ArraySerializerTest < CollectionSerializerTest
|
||||
extend ActiveSupport::Testing::Stream
|
||||
extend Minitest::Assertions
|
||||
def self.run_one_method(*)
|
||||
stderr = (capture(:stderr) do
|
||||
_, stderr = capture_io do
|
||||
super
|
||||
end)
|
||||
end
|
||||
if stderr !~ /Calling deprecated ArraySerializer/
|
||||
fail Minitest::Assertion, stderr
|
||||
end
|
||||
@ -22,14 +22,13 @@ module ActiveModel
|
||||
end
|
||||
else
|
||||
class ArraySerializerTest < ActiveSupport::TestCase
|
||||
extend ActiveSupport::Testing::Stream
|
||||
def test_json_key_with_root_warns_when_using_array_serializer
|
||||
stderr = (capture(:stderr) do
|
||||
_, stderr = capture_io do
|
||||
comment = Comment.new
|
||||
post = Post.new
|
||||
serializer = ArraySerializer.new([comment, post])
|
||||
assert_equal 'comments', serializer.json_key
|
||||
end)
|
||||
end
|
||||
assert_match(/Calling deprecated ArraySerializer/, stderr)
|
||||
end
|
||||
end
|
||||
|
||||
@ -3,8 +3,6 @@ require 'tmpdir'
|
||||
require 'tempfile'
|
||||
module ActiveModelSerializers
|
||||
class CacheTest < ActiveSupport::TestCase
|
||||
include ActiveSupport::Testing::Stream
|
||||
|
||||
def setup
|
||||
ActionController::Base.cache_store.clear
|
||||
@comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
||||
@ -222,10 +220,10 @@ module ActiveModelSerializers
|
||||
def test_warn_on_serializer_not_defined_in_file
|
||||
called = false
|
||||
serializer = Class.new(ActiveModel::Serializer)
|
||||
assert_match(/_cache_digest/, (capture(:stderr) do
|
||||
assert_output(nil, /_cache_digest/) do
|
||||
serializer.digest_caller_file('')
|
||||
called = true
|
||||
end))
|
||||
end
|
||||
assert called
|
||||
end
|
||||
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
# Use cleaner stream testing interface from Rails 5 if available
|
||||
# see https://github.com/rails/rails/blob/29959eb59d/activesupport/lib/active_support/testing/stream.rb
|
||||
begin
|
||||
require 'active_support/testing/stream'
|
||||
rescue LoadError
|
||||
require 'tempfile'
|
||||
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}") # rubocop:disable Lint/Eval
|
||||
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
|
||||
|
||||
@ -43,8 +43,6 @@ end
|
||||
require 'minitest/reporters'
|
||||
Minitest::Reporters.use!
|
||||
|
||||
require 'support/stream_capture'
|
||||
|
||||
require 'support/rails_app'
|
||||
|
||||
require 'support/test_case'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user