mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Remove warning about #capture under 4.2+
This commit is contained in:
parent
547d8b762f
commit
c49241601f
2 changed files with 31 additions and 16 deletions
|
@ -1,19 +1,34 @@
|
|||
module Kernel
|
||||
unless method_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)
|
||||
# #capture, #silence_stream, and #silence_stderr are deprecated after Rails
|
||||
# 4.2 and will be removed in 5.0, so just override them completely here
|
||||
|
||||
yield
|
||||
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)
|
||||
|
||||
stream_io.rewind
|
||||
return captured_stream.read
|
||||
ensure
|
||||
captured_stream.unlink
|
||||
stream_io.reopen(origin_stream)
|
||||
end
|
||||
yield
|
||||
|
||||
stream_io.rewind
|
||||
return captured_stream.read
|
||||
ensure
|
||||
captured_stream.unlink
|
||||
stream_io.reopen(origin_stream)
|
||||
end
|
||||
|
||||
def silence_stream(stream)
|
||||
old_stream = stream.dup
|
||||
stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
|
||||
stream.sync = true
|
||||
yield
|
||||
ensure
|
||||
stream.reopen(old_stream)
|
||||
old_stream.close
|
||||
end
|
||||
|
||||
def silence_stderr
|
||||
silence_stream(STDERR) { yield }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -437,7 +437,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
|||
it 'matches' do
|
||||
valid_values = [true, false]
|
||||
builder = build_object_allowing(valid_values)
|
||||
capture(:stderr) do
|
||||
silence_stderr do
|
||||
expect_to_match_in_array(builder, valid_values)
|
||||
end
|
||||
end
|
||||
|
@ -469,7 +469,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
|||
it 'matches' do
|
||||
valid_values = [nil]
|
||||
builder = build_object_allowing(valid_values)
|
||||
capture(:stderr) do
|
||||
silence_stderr do
|
||||
expect_to_match_in_array(builder, valid_values)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue