Skip to content

Commit c33ebc2

Browse files
committed
Silence structure dumps to avoid TinyTDS binstub puts.
1 parent 19e2432 commit c33ebc2

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

test/cases/helper_sqlserver.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ def with_use_output_inserted_disabled
3333
klass.use_output_inserted = true
3434
end
3535

36+
def silence_stream(stream)
37+
old_stream = stream.dup
38+
stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
39+
stream.sync = true
40+
yield
41+
ensure
42+
stream.reopen(old_stream)
43+
old_stream.close
44+
end
45+
46+
def quietly
47+
silence_stream(STDOUT) { silence_stream(STDERR) { yield } }
48+
end
49+
3650
end
3751
end
3852

test/cases/migration_test_sqlserver.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,4 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
5858

5959
end
6060

61-
62-
def quietly
63-
silence_stream(STDOUT) { silence_stream(STDERR) { yield } }
64-
end
65-
6661
end

test/cases/rake_test_sqlserver.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
122122
it 'dumps structure and accounts for defncopy oddities' do
123123
# CHANGED: [TinyTDS] When utilities are available http://git.io/v3tBk
124124
skip if host_windows?
125-
structure_dump configuration, filename
125+
quietly { db_tasks.structure_dump configuration, filename }
126126
filedata.wont_match %r{\AUSE.*\z}
127127
filedata.wont_match %r{\AGO.*\z}
128128
filedata.must_match %r{email\s+nvarchar\(4000\)}
@@ -133,22 +133,12 @@ class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
133133
it 'can load dumped structure' do
134134
# CHANGED: [TinyTDS] When utilities are available http://git.io/v3tBk
135135
skip if host_windows?
136-
structure_dump configuration, filename
136+
quietly { db_tasks.structure_dump configuration, filename }
137137
filedata.must_match %r{CREATE TABLE dbo\.users}
138138
db_tasks.purge(configuration)
139139
connection.tables.wont_include 'users'
140140
db_tasks.load_schema_for configuration, :sql, filename
141141
connection.tables.must_include 'users'
142142
end
143143

144-
private
145-
146-
def structure_dump(configuration, filename)
147-
original_stdout = $stdout
148-
$stdout = StringIO.new
149-
db_tasks.structure_dump(configuration, filename)
150-
ensure
151-
$stdout = original_stdout
152-
end
153-
154144
end

0 commit comments

Comments
 (0)