From fcdb58f67d924042f7e46a5170cc4bd94628fa57 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 25 Feb 2016 23:21:44 -0600 Subject: [PATCH] Remove AS::Testing::Stream in favor of Minitest assert_output --- .rubocop_todo.yml | 1 - test/action_controller/serialization_test.rb | 9 ++-- test/array_serializer_test.rb | 11 ++--- test/serializers/cache_test.rb | 6 +-- test/support/stream_capture.rb | 50 -------------------- test/test_helper.rb | 2 - 6 files changed, 11 insertions(+), 68 deletions(-) delete mode 100644 test/support/stream_capture.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c9c8e604..43b34bb9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/test/action_controller/serialization_test.rb b/test/action_controller/serialization_test.rb index 6c566300..e8e99dd5 100644 --- a/test/action_controller/serialization_test.rb +++ b/test/action_controller/serialization_test.rb @@ -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 diff --git a/test/array_serializer_test.rb b/test/array_serializer_test.rb index 350e4447..50028371 100644 --- a/test/array_serializer_test.rb +++ b/test/array_serializer_test.rb @@ -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 diff --git a/test/serializers/cache_test.rb b/test/serializers/cache_test.rb index 4167a77f..7c76d270 100644 --- a/test/serializers/cache_test.rb +++ b/test/serializers/cache_test.rb @@ -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 diff --git a/test/support/stream_capture.rb b/test/support/stream_capture.rb deleted file mode 100644 index da6acba3..00000000 --- a/test/support/stream_capture.rb +++ /dev/null @@ -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 - diff --git a/test/test_helper.rb b/test/test_helper.rb index 59c0d3f4..4a6950d3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -43,8 +43,6 @@ end require 'minitest/reporters' Minitest::Reporters.use! -require 'support/stream_capture' - require 'support/rails_app' require 'support/test_case'