tiny_tds 2.1.5 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +590 -0
  3. data/.gitignore +2 -0
  4. data/CHANGELOG.md +32 -1
  5. data/Gemfile +1 -8
  6. data/ISSUE_TEMPLATE.md +1 -1
  7. data/README.md +75 -88
  8. data/Rakefile +44 -30
  9. data/VERSION +1 -1
  10. data/docker-compose.yml +20 -8
  11. data/ext/tiny_tds/client.c +10 -15
  12. data/ext/tiny_tds/extconf.rb +183 -66
  13. data/ext/tiny_tds/extconsts.rb +4 -11
  14. data/ext/tiny_tds/result.c +28 -35
  15. data/ext/tiny_tds/tiny_tds_ext.c +4 -1
  16. data/lib/tiny_tds/bin.rb +12 -26
  17. data/lib/tiny_tds/client.rb +38 -42
  18. data/lib/tiny_tds/error.rb +0 -2
  19. data/lib/tiny_tds/gem.rb +5 -14
  20. data/lib/tiny_tds/result.rb +0 -2
  21. data/lib/tiny_tds/version.rb +1 -1
  22. data/lib/tiny_tds.rb +28 -47
  23. data/setup_cimgruby_dev.sh +25 -0
  24. data/start_dev.sh +21 -0
  25. data/tasks/native_gem.rake +12 -10
  26. data/tasks/package.rake +1 -3
  27. data/tasks/ports.rake +14 -75
  28. data/tasks/test.rake +3 -5
  29. data/test/bin/install-freetds.sh +2 -4
  30. data/test/bin/install-mssql.ps1 +42 -0
  31. data/test/bin/install-mssqltools.sh +9 -0
  32. data/test/bin/restore-from-native-gem.ps1 +10 -0
  33. data/test/bin/setup_tinytds_db.sh +7 -0
  34. data/test/bin/setup_volume_permissions.sh +10 -0
  35. data/test/client_test.rb +111 -120
  36. data/test/gem_test.rb +32 -111
  37. data/test/result_test.rb +259 -365
  38. data/test/schema_test.rb +369 -395
  39. data/test/sql/db-create.sql +18 -0
  40. data/test/sql/db-login.sql +38 -0
  41. data/test/test_helper.rb +75 -102
  42. data/test/thread_test.rb +22 -31
  43. data/tiny_tds.gemspec +28 -27
  44. metadata +70 -57
  45. data/.travis.yml +0 -25
  46. data/appveyor.yml +0 -72
  47. data/tasks/ports/freetds.rb +0 -37
  48. data/tasks/ports/libiconv.rb +0 -43
  49. data/tasks/ports/openssl.rb +0 -62
  50. data/tasks/ports/recipe.rb +0 -52
  51. data/test/appveyor/dbsetup.ps1 +0 -27
  52. data/test/appveyor/dbsetup.sql +0 -9
  53. data/test/benchmark/query.rb +0 -77
  54. data/test/benchmark/query_odbc.rb +0 -106
  55. data/test/benchmark/query_tinytds.rb +0 -126
  56. data/test/bin/setup.sh +0 -19
  57. data/test/schema/sqlserver_2000.sql +0 -140
  58. data/test/schema/sqlserver_2005.sql +0 -140
  59. data/test/schema/sqlserver_2014.sql +0 -140
  60. data/test/schema/sqlserver_2016.sql +0 -140
  61. data/test/schema/sybase_ase.sql +0 -138
  62. /data/test/schema/{sqlserver_2008.sql → sqlserver_2017.sql} +0 -0
data/test/client_test.rb CHANGED
@@ -1,126 +1,123 @@
1
- # encoding: utf-8
2
- require 'test_helper'
1
+ require "test_helper"
3
2
 
4
3
  class ClientTest < TinyTds::TestCase
5
- describe 'with valid credentials' do
4
+ describe "with valid credentials" do
6
5
  before do
7
6
  @client = new_connection
8
7
  end
9
8
 
10
- it 'must not be closed' do
9
+ it "must not be closed" do
11
10
  assert !@client.closed?
12
11
  assert @client.active?
13
12
  end
14
13
 
15
- it 'allows client connection to be closed' do
14
+ it "allows client connection to be closed" do
16
15
  assert @client.close
17
16
  assert @client.closed?
18
17
  assert !@client.active?
19
- action = lambda { @client.execute('SELECT 1 as [one]').each }
18
+ assert @client.dead?
19
+ action = lambda { @client.execute("SELECT 1 as [one]").each }
20
20
  assert_raise_tinytds_error(action) do |e|
21
- assert_match %r{closed connection}i, e.message, 'ignore if non-english test run'
21
+ assert_match %r{closed connection}i, e.message, "ignore if non-english test run"
22
22
  end
23
23
  end
24
24
 
25
- it 'has getters for the tds version information (brittle since conf takes precedence)' do
26
- if sybase_ase?
27
- assert_equal 7, @client.tds_version
28
- assert_equal 'DBTDS_5_0 - 5.0 SQL Server', @client.tds_version_info
29
- elsif @client.tds_73?
25
+ it "has getters for the tds version information (brittle since conf takes precedence)" do
26
+ if @client.tds_73?
30
27
  assert_equal 11, @client.tds_version
31
- assert_equal 'DBTDS_7_3 - Microsoft SQL Server 2008', @client.tds_version_info
28
+ assert_equal "DBTDS_7_3 - Microsoft SQL Server 2008", @client.tds_version_info
32
29
  else
33
30
  assert_equal 9, @client.tds_version
34
- assert_equal 'DBTDS_7_1/DBTDS_8_0 - Microsoft SQL Server 2000', @client.tds_version_info
31
+ assert_equal "DBTDS_7_1/DBTDS_8_0 - Microsoft SQL Server 2000", @client.tds_version_info
35
32
  end
36
33
  end
37
34
 
38
- it 'uses UTF-8 client charset/encoding by default' do
39
- assert_equal 'UTF-8', @client.charset
40
- assert_equal Encoding.find('UTF-8'), @client.encoding
35
+ it "uses UTF-8 client charset/encoding by default" do
36
+ assert_equal "UTF-8", @client.charset
37
+ assert_equal Encoding.find("UTF-8"), @client.encoding
41
38
  end
42
39
 
43
- it 'has a #escape method used for quote strings' do
40
+ it "has a #escape method used for quote strings" do
44
41
  assert_equal "''hello''", @client.escape("'hello'")
45
42
  end
46
43
 
47
- ['CP850', 'CP1252', 'ISO-8859-1'].each do |encoding|
44
+ ["CP850", "CP1252", "ISO-8859-1"].each do |encoding|
48
45
  it "allows valid iconv character set - #{encoding}" do
46
+ client = new_connection(encoding: encoding)
47
+ assert_equal encoding, client.charset
48
+ assert_equal Encoding.find(encoding), client.encoding
49
+ ensure
50
+ client&.close
51
+ end
52
+ end
53
+
54
+ unless sqlserver_azure?
55
+ it "must be able to use :host/:port connection" do
56
+ host = ENV["TINYTDS_UNIT_HOST_TEST"] || ENV["TINYTDS_UNIT_HOST"] || "localhost"
57
+ port = ENV["TINYTDS_UNIT_PORT_TEST"] || ENV["TINYTDS_UNIT_PORT"] || 1433
49
58
  begin
50
- client = new_connection(:encoding => encoding)
51
- assert_equal encoding, client.charset
52
- assert_equal Encoding.find(encoding), client.encoding
59
+ client = new_connection dataserver: nil, host: host, port: port
53
60
  ensure
54
- client.close if client
61
+ client&.close
55
62
  end
56
63
  end
57
64
  end
58
-
59
- it 'must be able to use :host/:port connection' do
60
- host = ENV['TINYTDS_UNIT_HOST_TEST'] || ENV['TINYTDS_UNIT_HOST'] || 'localhost'
61
- port = ENV['TINYTDS_UNIT_PORT_TEST'] || ENV['TINYTDS_UNIT_PORT'] || 1433
62
- begin
63
- client = new_connection dataserver: nil, host: host, port: port
64
- ensure
65
- client.close if client
66
- end
67
- end unless sqlserver_azure?
68
65
  end
69
66
 
70
- describe 'With in-valid options' do
67
+ describe "With in-valid options" do
71
68
  before(:all) do
72
69
  init_toxiproxy
73
70
  end
74
71
 
75
- it 'raises an argument error when no :host given and :dataserver is blank' do
76
- assert_raises(ArgumentError) { new_connection :dataserver => nil, :host => nil }
72
+ it "raises an argument error when no :host given and :dataserver is blank" do
73
+ assert_raises(ArgumentError) { new_connection dataserver: nil, host: nil }
77
74
  end
78
75
 
79
- it 'raises an argument error when no :username is supplied' do
80
- assert_raises(ArgumentError) { TinyTds::Client.new :username => nil }
76
+ it "raises an argument error when no :username is supplied" do
77
+ assert_raises(ArgumentError) { TinyTds::Client.new username: nil }
81
78
  end
82
79
 
83
- it 'raises TinyTds exception with undefined :dataserver' do
84
- options = connection_options :login_timeout => 1, :dataserver => 'DOESNOTEXIST'
80
+ it "raises TinyTds exception with undefined :dataserver" do
81
+ options = connection_options login_timeout: 1, dataserver: "DOESNOTEXIST"
85
82
  action = lambda { new_connection(options) }
86
83
  assert_raise_tinytds_error(action) do |e|
87
84
  # Not sure why tese are different.
88
85
  if ruby_darwin?
89
86
  assert_equal 20009, e.db_error_number
90
87
  assert_equal 9, e.severity
91
- assert_match %r{is unavailable or does not exist}i, e.message, 'ignore if non-english test run'
88
+ assert_match %r{is unavailable or does not exist}i, e.message, "ignore if non-english test run"
92
89
  else
93
90
  assert_equal 20012, e.db_error_number
94
91
  assert_equal 2, e.severity
95
- assert_match %r{server name not found in configuration files}i, e.message, 'ignore if non-english test run'
92
+ assert_match %r{server name not found in configuration files}i, e.message, "ignore if non-english test run"
96
93
  end
97
94
  end
98
95
  assert_new_connections_work
99
96
  end
100
97
 
101
- it 'raises TinyTds exception with long query past :timeout option' do
102
- client = new_connection :timeout => 1
98
+ it "raises TinyTds exception with long query past :timeout option" do
99
+ client = new_connection timeout: 1
103
100
  action = lambda { client.execute("WaitFor Delay '00:00:02'").do }
104
101
  assert_raise_tinytds_error(action) do |e|
105
102
  assert_equal 20003, e.db_error_number
106
103
  assert_equal 6, e.severity
107
- assert_match %r{timed out}i, e.message, 'ignore if non-english test run'
104
+ assert_match %r{timed out}i, e.message, "ignore if non-english test run"
108
105
  end
109
106
  assert_client_works(client)
110
107
  close_client(client)
111
108
  assert_new_connections_work
112
109
  end
113
110
 
114
- it 'must not timeout per sql batch when not under transaction' do
115
- client = new_connection :timeout => 2
111
+ it "must not timeout per sql batch when not under transaction" do
112
+ client = new_connection timeout: 2
116
113
  client.execute("WaitFor Delay '00:00:01'").do
117
114
  client.execute("WaitFor Delay '00:00:01'").do
118
115
  client.execute("WaitFor Delay '00:00:01'").do
119
116
  close_client(client)
120
117
  end
121
118
 
122
- it 'must not timeout per sql batch when under transaction' do
123
- client = new_connection :timeout => 2
119
+ it "must not timeout per sql batch when under transaction" do
120
+ client = new_connection timeout: 2
124
121
  begin
125
122
  client.execute("BEGIN TRANSACTION").do
126
123
  client.execute("WaitFor Delay '00:00:01'").do
@@ -132,32 +129,30 @@ class ClientTest < TinyTds::TestCase
132
129
  end
133
130
  end
134
131
 
135
- it 'raises TinyTds exception with tcp socket network failure' do
136
- skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
137
- begin
138
- client = new_connection timeout: 2, port: 1234
139
- assert_client_works(client)
140
- action = lambda { client.execute("waitfor delay '00:00:05'").do }
132
+ it "raises TinyTds exception with tcp socket network failure" do
133
+ client = new_connection timeout: 2, port: 1234, host: ENV["TOXIPROXY_HOST"]
134
+ assert_client_works(client)
135
+ action = lambda { client.execute("waitfor delay '00:00:05'").do }
141
136
 
142
- # Use toxiproxy to close the TCP socket after 1 second.
143
- # We want TinyTds to execute the statement, hit the timeout configured above, and then not be able to use the network to cancel
144
- # the network connection needs to close after the sql batch is sent and before the timeout above is hit
145
- Toxiproxy[:sqlserver_test].toxic(:slow_close, delay: 1000).apply do
146
- assert_raise_tinytds_error(action) do |e|
147
- assert_equal 20003, e.db_error_number
148
- assert_equal 6, e.severity
149
- assert_match %r{timed out}i, e.message, 'ignore if non-english test run'
150
- end
137
+ # Use toxiproxy to close the TCP socket after 1 second.
138
+ # We want TinyTds to execute the statement, hit the timeout configured above, and then not be able to use the network to cancel
139
+ # the network connection needs to close after the sql batch is sent and before the timeout above is hit
140
+ Toxiproxy[:sqlserver_test].toxic(:slow_close, delay: 1000).apply do
141
+ assert_raise_tinytds_error(action) do |e|
142
+ assert_equal 20003, e.db_error_number
143
+ assert_equal 6, e.severity
144
+ assert_match %r{timed out}i, e.message, "ignore if non-english test run"
151
145
  end
152
- ensure
153
- assert_new_connections_work
154
146
  end
147
+ ensure
148
+ assert_new_connections_work
155
149
  end
156
150
 
157
- it 'raises TinyTds exception with dead connection network failure' do
158
- skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
151
+ it "raises TinyTds exception with dead connection network failure" do
152
+ skip if ruby_windows?
153
+
159
154
  begin
160
- client = new_connection timeout: 2, port: 1234
155
+ client = new_connection timeout: 2, port: 1234, host: ENV["TOXIPROXY_HOST"]
161
156
  assert_client_works(client)
162
157
  action = lambda { client.execute("waitfor delay '00:00:05'").do }
163
158
 
@@ -167,8 +162,8 @@ class ClientTest < TinyTds::TestCase
167
162
  Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 1000).apply do
168
163
  assert_raise_tinytds_error(action) do |e|
169
164
  assert_equal 20047, e.db_error_number
170
- assert_includes [1,9], e.severity
171
- assert_match %r{dead or not enabled}i, e.message, 'ignore if non-english test run'
165
+ assert_includes [1, 9], e.severity
166
+ assert_match %r{dead or not enabled}i, e.message, "ignore if non-english test run"
172
167
  end
173
168
  end
174
169
  ensure
@@ -176,100 +171,96 @@ class ClientTest < TinyTds::TestCase
176
171
  end
177
172
  end
178
173
 
179
- it 'raises TinyTds exception with login timeout' do
180
- skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
181
- begin
182
- action = lambda do
183
- Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 0).apply do
184
- new_connection login_timeout: 1, port: 1234
185
- end
186
- end
187
- assert_raise_tinytds_error(action) do |e|
188
- assert_equal 20003, e.db_error_number
189
- assert_equal 6, e.severity
190
- assert_match %r{timed out}i, e.message, 'ignore if non-english test run'
174
+ it "raises TinyTds exception with login timeout" do
175
+ action = lambda do
176
+ Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 0).apply do
177
+ new_connection login_timeout: 1, port: 1234, host: ENV["TOXIPROXY_HOST"]
191
178
  end
192
- ensure
193
- assert_new_connections_work
194
179
  end
180
+ assert_raise_tinytds_error(action) do |e|
181
+ assert_equal 20003, e.db_error_number
182
+ assert_equal 6, e.severity
183
+ assert_match %r{timed out}i, e.message, "ignore if non-english test run"
184
+ end
185
+ ensure
186
+ assert_new_connections_work
195
187
  end
196
188
 
197
- it 'raises TinyTds exception with wrong :username' do
198
- skip if ENV['CI'] && sqlserver_azure? # Some issue with db_error_number.
199
- options = connection_options :username => 'willnotwork'
189
+ it "raises TinyTds exception with wrong :username" do
190
+ skip if ENV["CI"] && sqlserver_azure? # Some issue with db_error_number.
191
+ options = connection_options username: "willnotwork"
200
192
  action = lambda { new_connection(options) }
201
193
  assert_raise_tinytds_error(action) do |e|
202
- assert_equal sybase_ase? ? 4002 : 18456, e.db_error_number
194
+ assert_equal 18456, e.db_error_number
203
195
  assert_equal 14, e.severity
204
- assert_match %r{login failed}i, e.message, 'ignore if non-english test run'
196
+ assert_match %r{login failed}i, e.message, "ignore if non-english test run"
205
197
  end
206
198
  assert_new_connections_work
207
199
  end
208
-
209
200
  end
210
201
 
211
- describe '#parse_username' do
202
+ describe "#parse_username" do
212
203
  let(:client) { @client = new_connection }
213
204
 
214
- it 'returns username if azure is not true' do
205
+ it "returns username if azure is not true" do
215
206
  _(
216
- client.send(:parse_username, username: 'user@abc123.database.windows.net')
217
- ).must_equal 'user@abc123.database.windows.net'
207
+ client.send(:parse_username, username: "user@abc123.database.windows.net")
208
+ ).must_equal "user@abc123.database.windows.net"
218
209
  end
219
210
 
220
- it 'returns short username if azure is true' do
211
+ it "returns short username if azure is true" do
221
212
  _(
222
213
  client.send(
223
214
  :parse_username,
224
- username: 'user@abc123.database.windows.net',
225
- host: 'abc123.database.windows.net',
226
- azure: true
215
+ username: "user@abc123.database.windows.net",
216
+ host: "abc123.database.windows.net",
217
+ azure: true
227
218
  )
228
- ).must_equal 'user@abc123'
219
+ ).must_equal "user@abc123"
229
220
  end
230
221
 
231
- it 'returns full username if azure is false' do
222
+ it "returns full username if azure is false" do
232
223
  _(
233
224
  client.send(
234
225
  :parse_username,
235
- username: 'user@abc123.database.windows.net',
236
- host: 'abc123.database.windows.net',
237
- azure: false
226
+ username: "user@abc123.database.windows.net",
227
+ host: "abc123.database.windows.net",
228
+ azure: false
238
229
  )
239
- ).must_equal 'user@abc123.database.windows.net'
230
+ ).must_equal "user@abc123.database.windows.net"
240
231
  end
241
232
 
242
- it 'returns short username if passed and azure is true' do
233
+ it "returns short username if passed and azure is true" do
243
234
  _(
244
235
  client.send(
245
236
  :parse_username,
246
- username: 'user@abc123',
247
- host: 'abc123.database.windows.net',
248
- azure: true
237
+ username: "user@abc123",
238
+ host: "abc123.database.windows.net",
239
+ azure: true
249
240
  )
250
- ).must_equal 'user@abc123'
241
+ ).must_equal "user@abc123"
251
242
  end
252
243
 
253
- it 'returns username with servername if passed and azure is true' do
244
+ it "returns username with servername if passed and azure is true" do
254
245
  _(
255
246
  client.send(
256
247
  :parse_username,
257
- username: 'user',
258
- host: 'abc123.database.windows.net',
259
- azure: true
248
+ username: "user",
249
+ host: "abc123.database.windows.net",
250
+ azure: true
260
251
  )
261
- ).must_equal 'user@abc123'
252
+ ).must_equal "user@abc123"
262
253
  end
263
254
 
264
- it 'returns username with servername if passed and azure is false' do
255
+ it "returns username with servername if passed and azure is false" do
265
256
  _(
266
257
  client.send(
267
258
  :parse_username,
268
- username: 'user',
269
- host: 'abc123.database.windows.net',
270
- azure: false
259
+ username: "user",
260
+ host: "abc123.database.windows.net",
261
+ azure: false
271
262
  )
272
- ).must_equal 'user'
263
+ ).must_equal "user"
273
264
  end
274
265
  end
275
266
  end
data/test/gem_test.rb CHANGED
@@ -1,67 +1,65 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
- require 'tiny_tds/gem'
1
+ require "test_helper"
2
+ require "tiny_tds/gem"
4
3
 
5
- class GemTest < MiniTest::Spec
6
- gem_root ||= File.expand_path '../..', __FILE__
4
+ class GemTest < Minitest::Spec
5
+ gem_root ||= File.expand_path "../..", __FILE__
7
6
 
8
7
  describe TinyTds::Gem do
9
-
10
8
  # We're going to muck with some system globals so lets make sure
11
9
  # they get set back later
12
- original_host = RbConfig::CONFIG['host']
10
+ original_platform = RbConfig::CONFIG["arch"]
13
11
  original_pwd = Dir.pwd
14
12
 
15
13
  after do
16
- RbConfig::CONFIG['host'] = original_host
14
+ RbConfig::CONFIG["arch"] = original_platform
17
15
  Dir.chdir original_pwd
18
16
  end
19
17
 
20
- describe '#root_path' do
18
+ describe "#root_path" do
21
19
  let(:root_path) { TinyTds::Gem.root_path }
22
20
 
23
- it 'should be the root path' do
21
+ it "should be the root path" do
24
22
  _(root_path).must_equal gem_root
25
23
  end
26
24
 
27
- it 'should be the root path no matter the cwd' do
28
- Dir.chdir '/'
25
+ it "should be the root path no matter the cwd" do
26
+ Dir.chdir "/"
29
27
 
30
28
  _(root_path).must_equal gem_root
31
29
  end
32
30
  end
33
31
 
34
- describe '#ports_root_path' do
32
+ describe "#ports_root_path" do
35
33
  let(:ports_root_path) { TinyTds::Gem.ports_root_path }
36
34
 
37
- it 'should be the ports path' do
38
- _(ports_root_path).must_equal File.join(gem_root,'ports')
35
+ it "should be the ports path" do
36
+ _(ports_root_path).must_equal File.join(gem_root, "ports")
39
37
  end
40
38
 
41
- it 'should be the ports path no matter the cwd' do
42
- Dir.chdir '/'
39
+ it "should be the ports path no matter the cwd" do
40
+ Dir.chdir "/"
43
41
 
44
- _(ports_root_path).must_equal File.join(gem_root,'ports')
42
+ _(ports_root_path).must_equal File.join(gem_root, "ports")
45
43
  end
46
44
  end
47
45
 
48
- describe '#ports_bin_paths' do
46
+ describe "#ports_bin_paths" do
49
47
  let(:ports_bin_paths) { TinyTds::Gem.ports_bin_paths }
50
48
 
51
- describe 'when the ports directories exist' do
49
+ describe "when the ports directories exist" do
52
50
  let(:fake_bin_paths) do
53
- ports_host_root = File.join(gem_root, 'ports', 'fake-host-with-dirs')
51
+ ports_host_root = File.join(gem_root, "ports", "fake-host-with-dirs")
54
52
  [
55
- File.join('a','bin'),
56
- File.join('a','inner','bin'),
57
- File.join('b','bin')
53
+ File.join("a", "bin"),
54
+ File.join("a", "inner", "bin"),
55
+ File.join("b", "bin")
58
56
  ].map do |p|
59
57
  File.join(ports_host_root, p)
60
58
  end
61
59
  end
62
60
 
63
61
  before do
64
- RbConfig::CONFIG['host'] = 'fake-host-with-dirs'
62
+ RbConfig::CONFIG["arch"] = "fake-host-with-dirs"
65
63
  fake_bin_paths.each do |path|
66
64
  FileUtils.mkdir_p(path)
67
65
  end
@@ -69,111 +67,34 @@ class GemTest < MiniTest::Spec
69
67
 
70
68
  after do
71
69
  FileUtils.remove_entry_secure(
72
- File.join(gem_root, 'ports', 'fake-host-with-dirs'), true
70
+ File.join(gem_root, "ports", "fake-host-with-dirs"), true
73
71
  )
74
72
  end
75
73
 
76
- it 'should return all the bin directories' do
74
+ it "should return all the bin directories" do
77
75
  _(ports_bin_paths.sort).must_equal fake_bin_paths.sort
78
76
  end
79
77
 
80
- it 'should return all the bin directories regardless of cwd' do
81
- Dir.chdir '/'
78
+ it "should return all the bin directories regardless of cwd" do
79
+ Dir.chdir "/"
82
80
  _(ports_bin_paths.sort).must_equal fake_bin_paths.sort
83
81
  end
84
82
  end
85
83
 
86
- describe 'when the ports directories are missing' do
84
+ describe "when the ports directories are missing" do
87
85
  before do
88
- RbConfig::CONFIG['host'] = 'fake-host-without-dirs'
86
+ RbConfig::CONFIG["arch"] = "fake-host-without-dirs"
89
87
  end
90
88
 
91
- it 'should return no directories' do
89
+ it "should return no directories" do
92
90
  _(ports_bin_paths).must_be_empty
93
91
  end
94
92
 
95
- it 'should return no directories regardless of cwd' do
96
- Dir.chdir '/'
93
+ it "should return no directories regardless of cwd" do
94
+ Dir.chdir "/"
97
95
  _(ports_bin_paths).must_be_empty
98
96
  end
99
97
  end
100
98
  end
101
-
102
- describe '#ports_lib_paths' do
103
- let(:ports_lib_paths) { TinyTds::Gem.ports_lib_paths }
104
-
105
- describe 'when the ports directories exist' do
106
- let(:fake_lib_paths) do
107
- ports_host_root = File.join(gem_root, 'ports', 'fake-host-with-dirs')
108
- [
109
- File.join('a','lib'),
110
- File.join('a','inner','lib'),
111
- File.join('b','lib')
112
- ].map do |p|
113
- File.join(ports_host_root, p)
114
- end
115
- end
116
-
117
- before do
118
- RbConfig::CONFIG['host'] = 'fake-host-with-dirs'
119
- fake_lib_paths.each do |path|
120
- FileUtils.mkdir_p(path)
121
- end
122
- end
123
-
124
- after do
125
- FileUtils.remove_entry_secure(
126
- File.join(gem_root, 'ports', 'fake-host-with-dirs'), true
127
- )
128
- end
129
-
130
- it 'should return all the lib directories' do
131
- _(ports_lib_paths.sort).must_equal fake_lib_paths.sort
132
- end
133
-
134
- it 'should return all the lib directories regardless of cwd' do
135
- Dir.chdir '/'
136
- _(ports_lib_paths.sort).must_equal fake_lib_paths.sort
137
- end
138
- end
139
-
140
- describe 'when the ports directories are missing' do
141
- before do
142
- RbConfig::CONFIG['host'] = 'fake-host-without-dirs'
143
- end
144
-
145
-
146
- it 'should return no directories' do
147
- _(ports_lib_paths).must_be_empty
148
- end
149
-
150
- it 'should return no directories regardless of cwd' do
151
- Dir.chdir '/'
152
- _(ports_lib_paths).must_be_empty
153
- end
154
- end
155
- end
156
-
157
- describe '#ports_host' do
158
- {
159
- 'i686-pc-linux-gnu' => 'i686-pc-linux-gnu',
160
- 'x86_64-pc-linux-gnu' => 'x86_64-pc-linux-gnu',
161
- 'i686-w64-mingw32' => 'i686-w64-mingw32',
162
- 'x86_64-w64-mingw32' => 'x86_64-w64-mingw32',
163
- # consolidate this host to our build w64-mingw32 arch
164
- 'i686-pc-mingw32' => 'i686-w64-mingw32'
165
- }.each do |host,expected|
166
- describe "on a #{host} architecture" do
167
- before do
168
- RbConfig::CONFIG['host'] = host
169
- end
170
-
171
- it "should return a #{expected} ports host" do
172
- _(TinyTds::Gem.ports_host).must_equal expected
173
- end
174
- end
175
- end
176
- end
177
99
  end
178
100
  end
179
-