Skip to content

Commit df7a370

Browse files
authored
Use RSpec expect output instead of StringIO (#747)
1 parent a3884a0 commit df7a370

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

spec/mysql2/client_spec.rb

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# encoding: UTF-8
22
require 'spec_helper'
3-
require 'stringio'
43

54
RSpec.describe Mysql2::Client do
65
context "using defaults file" do
@@ -206,22 +205,21 @@ def run_gc
206205

207206
if RUBY_PLATFORM =~ /mingw|mswin/
208207
it "cannot be disabled" do
209-
stderr, $stderr = $stderr, StringIO.new
210-
211-
begin
212-
Mysql2::Client.new(DatabaseCredentials['root'].merge(:automatic_close => false))
213-
expect($stderr.string).to include('always closed by garbage collector')
214-
$stderr.reopen
215-
216-
client = Mysql2::Client.new(DatabaseCredentials['root'])
208+
expect do
209+
client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:automatic_close => false))
210+
expect(client.automatic_close?).to be(true)
211+
end.to output(/always closed by garbage collector/).to_stderr
212+
213+
expect do
214+
client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:automatic_close => true))
215+
expect(client.automatic_close?).to be(true)
216+
end.to_not output(/always closed by garbage collector/).to_stderr
217+
218+
expect do
219+
client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:automatic_close => true))
217220
client.automatic_close = false
218-
expect($stderr.string).to include('always closed by garbage collector')
219-
$stderr.reopen
220-
221-
expect { client.automatic_close = true }.to_not change { $stderr.string }
222-
ensure
223-
$stderr = stderr
224-
end
221+
expect(client.automatic_close?).to be(true)
222+
end.to output(/always closed by garbage collector/).to_stderr
225223
end
226224
else
227225
it "can be configured" do

0 commit comments

Comments
 (0)