Merge pull request #692 from airblade/capture_io

Use capture_io instead of capture (deprecated)
This commit is contained in:
Jared Beck 2016-01-15 00:06:19 -05:00
commit f8c8f7d52b
2 changed files with 17 additions and 5 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ vendor/*
.tags_sorted_by_file
.ruby-version
.ruby-gemset
.rbenv-gemsets

View File

@ -645,17 +645,28 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
assert_not_nil @wotsit.versions.last.reify.updated_at
end
# Tests that it doesn't try to write created_on as an attribute just because
# a created_on method exists.
#
# - Deprecation warning in Rails 3.2
# - ActiveModel::MissingAttributeError in Rails 4
#
# In rails 5, `capture` is deprecated in favor of `capture_io`.
#
should 'not generate warning' do
# Tests that it doesn't try to write created_on as an attribute just because a created_on
# method exists.
warnings = capture(:stderr) { # Deprecation warning in Rails 3.2
assert_nothing_raised { # ActiveModel::MissingAttributeError in Rails 4
assert_update_raises_nothing = -> {
assert_nothing_raised {
@wotsit.update_attributes! :name => 'changed'
}
}
warnings =
if respond_to?(:capture_io)
capture_io { assert_update_raises_nothing.call }.last
else
capture(:stderr) { assert_update_raises_nothing.call }
end
assert_equal '', warnings
end
end