mysql2 0.3.21-x86-mingw32 → 0.4.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,81 +2,82 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Mysql2::Error do
5
+ RSpec.describe Mysql2::Error do
6
6
  let(:client) { Mysql2::Client.new(DatabaseCredentials['root']) }
7
7
 
8
- let :error do
8
+ let(:error) do
9
9
  begin
10
10
  client.query("HAHAHA")
11
11
  rescue Mysql2::Error => e
12
12
  error = e
13
- ensure
14
- client.close
15
13
  end
16
14
 
17
15
  error
18
16
  end
19
17
 
20
18
  it "responds to error_number and sql_state, with aliases" do
21
- error.should respond_to(:error_number)
22
- error.should respond_to(:sql_state)
19
+ expect(error).to respond_to(:error_number)
20
+ expect(error).to respond_to(:sql_state)
23
21
 
24
22
  # Mysql gem compatibility
25
- error.should respond_to(:errno)
26
- error.should respond_to(:error)
23
+ expect(error).to respond_to(:errno)
24
+ expect(error).to respond_to(:error)
27
25
  end
28
26
 
29
- if "".respond_to? :encoding
30
- let :error do
31
- client = Mysql2::Client.new(DatabaseCredentials['root'])
27
+ context 'encoding' do
28
+ let(:valid_utf8) { '造字' }
29
+ let(:error) do
32
30
  begin
33
- client.query("\xE9\x80\xA0\xE5\xAD\x97")
31
+ client.query(valid_utf8)
34
32
  rescue Mysql2::Error => e
35
- error = e
36
- ensure
37
- client.close
33
+ e
38
34
  end
39
-
40
- error
41
35
  end
42
36
 
43
- let :bad_err do
44
- client = Mysql2::Client.new(DatabaseCredentials['root'])
37
+ let(:invalid_utf8) { "\xE5\xC6\x7D\x1F" }
38
+ let(:bad_err) do
45
39
  begin
46
- client.query("\xE5\xC6\x7D\x1F")
40
+ client.query(invalid_utf8)
47
41
  rescue Mysql2::Error => e
48
- error = e
49
- ensure
50
- client.close
42
+ e
51
43
  end
44
+ end
45
+
46
+ before do
47
+ pending('String#encoding is not defined') unless String.public_method_defined?(:encoding)
48
+
49
+ # sanity check
50
+ expect(valid_utf8.encoding).to eql(Encoding::UTF_8)
51
+ expect(valid_utf8).to be_valid_encoding
52
52
 
53
- error
53
+ expect(invalid_utf8.encoding).to eql(Encoding::UTF_8)
54
+ expect(invalid_utf8).to_not be_valid_encoding
54
55
  end
55
56
 
56
57
  it "returns error messages as UTF-8 by default" do
57
58
  with_internal_encoding nil do
58
- error.message.encoding.should eql(Encoding::UTF_8)
59
- error.message.valid_encoding?
59
+ expect(error.message.encoding).to eql(Encoding::UTF_8)
60
+ expect(error.message).to be_valid_encoding
60
61
 
61
- bad_err.message.encoding.should eql(Encoding::UTF_8)
62
- bad_err.message.valid_encoding?
62
+ expect(bad_err.message.encoding).to eql(Encoding::UTF_8)
63
+ expect(bad_err.message).to be_valid_encoding
63
64
 
64
- bad_err.message.should include("??}\u001F")
65
+ expect(bad_err.message).to include("??}\u001F")
65
66
  end
66
67
  end
67
68
 
68
69
  it "returns sql state as ASCII" do
69
- error.sql_state.encoding.should eql(Encoding::US_ASCII)
70
- error.sql_state.valid_encoding?
70
+ expect(error.sql_state.encoding).to eql(Encoding::US_ASCII)
71
+ expect(error.sql_state).to be_valid_encoding
71
72
  end
72
73
 
73
74
  it "returns error messages and sql state in Encoding.default_internal if set" do
74
- with_internal_encoding 'UTF-16LE' do
75
- error.message.encoding.should eql(Encoding.default_internal)
76
- error.message.valid_encoding?
75
+ with_internal_encoding Encoding::UTF_16LE do
76
+ expect(error.message.encoding).to eql(Encoding.default_internal)
77
+ expect(error.message).to be_valid_encoding
77
78
 
78
- bad_err.message.encoding.should eql(Encoding.default_internal)
79
- bad_err.message.valid_encoding?
79
+ expect(bad_err.message.encoding).to eql(Encoding.default_internal)
80
+ expect(bad_err.message).to be_valid_encoding
80
81
  end
81
82
  end
82
83
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require 'spec_helper'
3
3
 
4
- describe Mysql2::Result do
4
+ RSpec.describe Mysql2::Result do
5
5
  before(:each) do
6
6
  @result = @client.query "SELECT 1"
7
7
  end
@@ -15,33 +15,33 @@ describe Mysql2::Result do
15
15
  end
16
16
 
17
17
  it "should have included Enumerable" do
18
- Mysql2::Result.ancestors.include?(Enumerable).should be_true
18
+ expect(Mysql2::Result.ancestors.include?(Enumerable)).to be true
19
19
  end
20
20
 
21
21
  it "should respond to #each" do
22
- @result.should respond_to(:each)
22
+ expect(@result).to respond_to(:each)
23
23
  end
24
24
 
25
25
  it "should raise a Mysql2::Error exception upon a bad query" do
26
- lambda {
26
+ expect {
27
27
  @client.query "bad sql"
28
- }.should raise_error(Mysql2::Error)
28
+ }.to raise_error(Mysql2::Error)
29
29
 
30
- lambda {
30
+ expect {
31
31
  @client.query "SELECT 1"
32
- }.should_not raise_error(Mysql2::Error)
32
+ }.not_to raise_error
33
33
  end
34
34
 
35
35
  it "should respond to #count, which is aliased as #size" do
36
36
  r = @client.query "SELECT 1"
37
- r.should respond_to :count
38
- r.should respond_to :size
37
+ expect(r).to respond_to :count
38
+ expect(r).to respond_to :size
39
39
  end
40
40
 
41
41
  it "should be able to return the number of rows in the result set" do
42
42
  r = @client.query "SELECT 1"
43
- r.count.should eql(1)
44
- r.size.should eql(1)
43
+ expect(r.count).to eql(1)
44
+ expect(r.size).to eql(1)
45
45
  end
46
46
 
47
47
  context "metadata queries" do
@@ -53,44 +53,39 @@ describe Mysql2::Result do
53
53
  context "#each" do
54
54
  it "should yield rows as hash's" do
55
55
  @result.each do |row|
56
- row.class.should eql(Hash)
56
+ expect(row.class).to eql(Hash)
57
57
  end
58
58
  end
59
59
 
60
60
  it "should yield rows as hash's with symbol keys if :symbolize_keys was set to true" do
61
61
  @result.each(:symbolize_keys => true) do |row|
62
- row.keys.first.class.should eql(Symbol)
62
+ expect(row.keys.first.class).to eql(Symbol)
63
63
  end
64
64
  end
65
65
 
66
66
  it "should be able to return results as an array" do
67
67
  @result.each(:as => :array) do |row|
68
- row.class.should eql(Array)
68
+ expect(row.class).to eql(Array)
69
69
  end
70
70
  end
71
71
 
72
72
  it "should cache previously yielded results by default" do
73
- @result.first.object_id.should eql(@result.first.object_id)
73
+ expect(@result.first.object_id).to eql(@result.first.object_id)
74
74
  end
75
75
 
76
76
  it "should not cache previously yielded results if cache_rows is disabled" do
77
77
  result = @client.query "SELECT 1", :cache_rows => false
78
- result.first.object_id.should_not eql(result.first.object_id)
79
- end
80
-
81
- it "should be able to iterate a second time even if cache_rows is disabled" do
82
- result = @client.query "SELECT 1 UNION SELECT 2", :cache_rows => false
83
- result.to_a.should eql(result.to_a)
78
+ expect(result.first.object_id).not_to eql(result.first.object_id)
84
79
  end
85
80
 
86
81
  it "should yield different value for #first if streaming" do
87
82
  result = @client.query "SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false
88
- result.first.should_not eql(result.first)
83
+ expect(result.first).not_to eql(result.first)
89
84
  end
90
85
 
91
86
  it "should yield the same value for #first if streaming is disabled" do
92
87
  result = @client.query "SELECT 1 UNION SELECT 2", :stream => false
93
- result.first.should eql(result.first)
88
+ expect(result.first).to eql(result.first)
94
89
  end
95
90
 
96
91
  it "should throw an exception if we try to iterate twice when streaming is enabled" do
@@ -109,42 +104,43 @@ describe Mysql2::Result do
109
104
  end
110
105
 
111
106
  it "method should exist" do
112
- @test_result.should respond_to(:fields)
107
+ expect(@test_result).to respond_to(:fields)
113
108
  end
114
109
 
115
110
  it "should return an array of field names in proper order" do
116
111
  result = @client.query "SELECT 'a', 'b', 'c'"
117
- result.fields.should eql(['a', 'b', 'c'])
112
+ expect(result.fields).to eql(['a', 'b', 'c'])
118
113
  end
119
114
  end
120
115
 
121
116
  context "streaming" do
122
117
  it "should maintain a count while streaming" do
123
118
  result = @client.query('SELECT 1', :stream => true, :cache_rows => false)
124
- result.count.should eql(0)
119
+ expect(result.count).to eql(0)
125
120
  result.each.to_a
126
- result.count.should eql(1)
121
+ expect(result.count).to eql(1)
127
122
  end
128
123
 
129
124
  it "should retain the count when mixing first and each" do
130
125
  result = @client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false)
131
- result.count.should eql(0)
126
+ expect(result.count).to eql(0)
132
127
  result.first
133
- result.count.should eql(1)
128
+ expect(result.count).to eql(1)
134
129
  result.each.to_a
135
- result.count.should eql(2)
130
+ expect(result.count).to eql(2)
136
131
  end
137
132
 
138
133
  it "should not yield nil at the end of streaming" do
139
134
  result = @client.query('SELECT * FROM mysql2_test', :stream => true, :cache_rows => false)
140
- result.each { |r| r.should_not be_nil}
135
+ result.each { |r| expect(r).not_to be_nil}
141
136
  end
142
137
 
143
138
  it "#count should be zero for rows after streaming when there were no results" do
139
+ @client.query "USE test"
144
140
  result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", :stream => true, :cache_rows => false)
145
- result.count.should eql(0)
141
+ expect(result.count).to eql(0)
146
142
  result.each.to_a
147
- result.count.should eql(0)
143
+ expect(result.count).to eql(0)
148
144
  end
149
145
 
150
146
  it "should raise an exception if streaming ended due to a timeout" do
@@ -161,12 +157,12 @@ describe Mysql2::Result do
161
157
  client.query "SET net_write_timeout = 1"
162
158
  res = client.query "SELECT * FROM streamingTest", :stream => true, :cache_rows => false
163
159
 
164
- lambda {
160
+ expect {
165
161
  res.each_with_index do |row, i|
166
162
  # Exhaust the first result packet then trigger a timeout
167
163
  sleep 2 if i > 0 && i % 1000 == 0
168
164
  end
169
- }.should raise_error(Mysql2::Error, /Lost connection/)
165
+ }.to raise_error(Mysql2::Error, /Lost connection/)
170
166
  end
171
167
  end
172
168
 
@@ -177,32 +173,32 @@ describe Mysql2::Result do
177
173
 
178
174
  it "should return nil values for NULL and strings for everything else when :cast is false" do
179
175
  result = @client.query('SELECT null_test, tiny_int_test, bool_cast_test, int_test, date_test, enum_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast => false).first
180
- result["null_test"].should be_nil
181
- result["tiny_int_test"].should eql("1")
182
- result["bool_cast_test"].should eql("1")
183
- result["int_test"].should eql("10")
184
- result["date_test"].should eql("2010-04-04")
185
- result["enum_test"].should eql("val1")
176
+ expect(result["null_test"]).to be_nil
177
+ expect(result["tiny_int_test"]).to eql("1")
178
+ expect(result["bool_cast_test"]).to eql("1")
179
+ expect(result["int_test"]).to eql("10")
180
+ expect(result["date_test"]).to eql("2010-04-04")
181
+ expect(result["enum_test"]).to eql("val1")
186
182
  end
187
183
 
188
184
  it "should return nil for a NULL value" do
189
- @test_result['null_test'].class.should eql(NilClass)
190
- @test_result['null_test'].should eql(nil)
185
+ expect(@test_result['null_test'].class).to eql(NilClass)
186
+ expect(@test_result['null_test']).to eql(nil)
191
187
  end
192
188
 
193
189
  it "should return String for a BIT(64) value" do
194
- @test_result['bit_test'].class.should eql(String)
195
- @test_result['bit_test'].should eql("\000\000\000\000\000\000\000\005")
190
+ expect(@test_result['bit_test'].class).to eql(String)
191
+ expect(@test_result['bit_test']).to eql("\000\000\000\000\000\000\000\005")
196
192
  end
197
193
 
198
194
  it "should return String for a BIT(1) value" do
199
- @test_result['single_bit_test'].class.should eql(String)
200
- @test_result['single_bit_test'].should eql("\001")
195
+ expect(@test_result['single_bit_test'].class).to eql(String)
196
+ expect(@test_result['single_bit_test']).to eql("\001")
201
197
  end
202
198
 
203
199
  it "should return Fixnum for a TINYINT value" do
204
- [Fixnum, Bignum].should include(@test_result['tiny_int_test'].class)
205
- @test_result['tiny_int_test'].should eql(1)
200
+ expect([Fixnum, Bignum]).to include(@test_result['tiny_int_test'].class)
201
+ expect(@test_result['tiny_int_test']).to eql(1)
206
202
  end
207
203
 
208
204
  it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
@@ -216,9 +212,9 @@ describe Mysql2::Result do
216
212
  result1 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast_booleans => true
217
213
  result2 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 0 LIMIT 1', :cast_booleans => true
218
214
  result3 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = -1 LIMIT 1', :cast_booleans => true
219
- result1.first['bool_cast_test'].should be_true
220
- result2.first['bool_cast_test'].should be_false
221
- result3.first['bool_cast_test'].should be_true
215
+ expect(result1.first['bool_cast_test']).to be true
216
+ expect(result2.first['bool_cast_test']).to be false
217
+ expect(result3.first['bool_cast_test']).to be true
222
218
 
223
219
  @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})"
224
220
  end
@@ -231,55 +227,55 @@ describe Mysql2::Result do
231
227
 
232
228
  result1 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id1}", :cast_booleans => true
233
229
  result2 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id2}", :cast_booleans => true
234
- result1.first['single_bit_test'].should be_true
235
- result2.first['single_bit_test'].should be_false
230
+ expect(result1.first['single_bit_test']).to be true
231
+ expect(result2.first['single_bit_test']).to be false
236
232
 
237
233
  @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
238
234
  end
239
235
 
240
236
  it "should return Fixnum for a SMALLINT value" do
241
- [Fixnum, Bignum].should include(@test_result['small_int_test'].class)
242
- @test_result['small_int_test'].should eql(10)
237
+ expect([Fixnum, Bignum]).to include(@test_result['small_int_test'].class)
238
+ expect(@test_result['small_int_test']).to eql(10)
243
239
  end
244
240
 
245
241
  it "should return Fixnum for a MEDIUMINT value" do
246
- [Fixnum, Bignum].should include(@test_result['medium_int_test'].class)
247
- @test_result['medium_int_test'].should eql(10)
242
+ expect([Fixnum, Bignum]).to include(@test_result['medium_int_test'].class)
243
+ expect(@test_result['medium_int_test']).to eql(10)
248
244
  end
249
245
 
250
246
  it "should return Fixnum for an INT value" do
251
- [Fixnum, Bignum].should include(@test_result['int_test'].class)
252
- @test_result['int_test'].should eql(10)
247
+ expect([Fixnum, Bignum]).to include(@test_result['int_test'].class)
248
+ expect(@test_result['int_test']).to eql(10)
253
249
  end
254
250
 
255
251
  it "should return Fixnum for a BIGINT value" do
256
- [Fixnum, Bignum].should include(@test_result['big_int_test'].class)
257
- @test_result['big_int_test'].should eql(10)
252
+ expect([Fixnum, Bignum]).to include(@test_result['big_int_test'].class)
253
+ expect(@test_result['big_int_test']).to eql(10)
258
254
  end
259
255
 
260
256
  it "should return Fixnum for a YEAR value" do
261
- [Fixnum, Bignum].should include(@test_result['year_test'].class)
262
- @test_result['year_test'].should eql(2009)
257
+ expect([Fixnum, Bignum]).to include(@test_result['year_test'].class)
258
+ expect(@test_result['year_test']).to eql(2009)
263
259
  end
264
260
 
265
261
  it "should return BigDecimal for a DECIMAL value" do
266
- @test_result['decimal_test'].class.should eql(BigDecimal)
267
- @test_result['decimal_test'].should eql(10.3)
262
+ expect(@test_result['decimal_test'].class).to eql(BigDecimal)
263
+ expect(@test_result['decimal_test']).to eql(10.3)
268
264
  end
269
265
 
270
266
  it "should return Float for a FLOAT value" do
271
- @test_result['float_test'].class.should eql(Float)
272
- @test_result['float_test'].should eql(10.3)
267
+ expect(@test_result['float_test'].class).to eql(Float)
268
+ expect(@test_result['float_test']).to eql(10.3)
273
269
  end
274
270
 
275
271
  it "should return Float for a DOUBLE value" do
276
- @test_result['double_test'].class.should eql(Float)
277
- @test_result['double_test'].should eql(10.3)
272
+ expect(@test_result['double_test'].class).to eql(Float)
273
+ expect(@test_result['double_test']).to eql(10.3)
278
274
  end
279
275
 
280
276
  it "should return Time for a DATETIME value when within the supported range" do
281
- @test_result['date_time_test'].class.should eql(Time)
282
- @test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S").should eql('2010-04-04 11:44:00')
277
+ expect(@test_result['date_time_test'].class).to eql(Time)
278
+ expect(@test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
283
279
  end
284
280
 
285
281
  if 1.size == 4 # 32bit
@@ -292,158 +288,153 @@ describe Mysql2::Result do
292
288
  it "should return DateTime when timestamp is < 1901-12-13 20:45:52" do
293
289
  # 1901-12-13T20:45:52 is the min for 32bit Ruby 1.8
294
290
  r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
295
- r.first['test'].class.should eql(klass)
291
+ expect(r.first['test'].class).to eql(klass)
296
292
  end
297
293
 
298
294
  it "should return DateTime when timestamp is > 2038-01-19T03:14:07" do
299
295
  # 2038-01-19T03:14:07 is the max for 32bit Ruby 1.8
300
296
  r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
301
- r.first['test'].class.should eql(klass)
297
+ expect(r.first['test'].class).to eql(klass)
302
298
  end
303
299
  elsif 1.size == 8 # 64bit
304
300
  unless RUBY_VERSION =~ /1.8/
305
301
  it "should return Time when timestamp is < 1901-12-13 20:45:52" do
306
302
  r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
307
- r.first['test'].class.should eql(Time)
303
+ expect(r.first['test'].class).to eql(Time)
308
304
  end
309
305
 
310
306
  it "should return Time when timestamp is > 2038-01-19T03:14:07" do
311
307
  r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
312
- r.first['test'].class.should eql(Time)
308
+ expect(r.first['test'].class).to eql(Time)
313
309
  end
314
310
  else
315
311
  it "should return Time when timestamp is > 0138-12-31 11:59:59" do
316
312
  r = @client.query("SELECT CAST('0139-1-1 00:00:00' AS DATETIME) as test")
317
- r.first['test'].class.should eql(Time)
313
+ expect(r.first['test'].class).to eql(Time)
318
314
  end
319
315
 
320
316
  it "should return DateTime when timestamp is < 0139-1-1T00:00:00" do
321
317
  r = @client.query("SELECT CAST('0138-12-31 11:59:59' AS DATETIME) as test")
322
- r.first['test'].class.should eql(DateTime)
318
+ expect(r.first['test'].class).to eql(DateTime)
323
319
  end
324
320
 
325
321
  it "should return Time when timestamp is > 2038-01-19T03:14:07" do
326
322
  r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
327
- r.first['test'].class.should eql(Time)
323
+ expect(r.first['test'].class).to eql(Time)
328
324
  end
329
325
  end
330
326
  end
331
327
 
332
328
  it "should return Time for a TIMESTAMP value when within the supported range" do
333
- @test_result['timestamp_test'].class.should eql(Time)
334
- @test_result['timestamp_test'].strftime("%Y-%m-%d %H:%M:%S").should eql('2010-04-04 11:44:00')
329
+ expect(@test_result['timestamp_test'].class).to eql(Time)
330
+ expect(@test_result['timestamp_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
335
331
  end
336
332
 
337
333
  it "should return Time for a TIME value" do
338
- @test_result['time_test'].class.should eql(Time)
339
- @test_result['time_test'].strftime("%Y-%m-%d %H:%M:%S").should eql('2000-01-01 11:44:00')
334
+ expect(@test_result['time_test'].class).to eql(Time)
335
+ expect(@test_result['time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2000-01-01 11:44:00')
340
336
  end
341
337
 
342
338
  it "should return Date for a DATE value" do
343
- @test_result['date_test'].class.should eql(Date)
344
- @test_result['date_test'].strftime("%Y-%m-%d").should eql('2010-04-04')
339
+ expect(@test_result['date_test'].class).to eql(Date)
340
+ expect(@test_result['date_test'].strftime("%Y-%m-%d")).to eql('2010-04-04')
345
341
  end
346
342
 
347
343
  it "should return String for an ENUM value" do
348
- @test_result['enum_test'].class.should eql(String)
349
- @test_result['enum_test'].should eql('val1')
344
+ expect(@test_result['enum_test'].class).to eql(String)
345
+ expect(@test_result['enum_test']).to eql('val1')
350
346
  end
351
347
 
352
348
  it "should raise an error given an invalid DATETIME" do
353
- begin
354
- @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each
355
- rescue Mysql2::Error => e
356
- error = e
357
- end
358
-
359
- error.message.should eql("Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
349
+ expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \
350
+ raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
360
351
  end
361
352
 
362
- if defined? Encoding
363
- context "string encoding for ENUM values" do
364
- it "should default to the connection's encoding if Encoding.default_internal is nil" do
365
- with_internal_encoding nil do
366
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
367
- result['enum_test'].encoding.should eql(Encoding.find('utf-8'))
353
+ context "string encoding for ENUM values" do
354
+ before { pending('Encoding is undefined') unless defined?(Encoding) }
368
355
 
369
- client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
370
- result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
371
- result['enum_test'].encoding.should eql(Encoding.find('us-ascii'))
372
- client2.close
373
- end
356
+ it "should default to the connection's encoding if Encoding.default_internal is nil" do
357
+ with_internal_encoding nil do
358
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
359
+ expect(result['enum_test'].encoding).to eql(Encoding::UTF_8)
360
+
361
+ client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
362
+ result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
363
+ expect(result['enum_test'].encoding).to eql(Encoding::ASCII)
364
+ client2.close
374
365
  end
366
+ end
375
367
 
376
- it "should use Encoding.default_internal" do
377
- with_internal_encoding 'utf-8' do
378
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
379
- result['enum_test'].encoding.should eql(Encoding.default_internal)
380
- end
368
+ it "should use Encoding.default_internal" do
369
+ with_internal_encoding Encoding::UTF_8 do
370
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
371
+ expect(result['enum_test'].encoding).to eql(Encoding.default_internal)
372
+ end
381
373
 
382
- with_internal_encoding 'us-ascii' do
383
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
384
- result['enum_test'].encoding.should eql(Encoding.default_internal)
385
- end
374
+ with_internal_encoding Encoding::ASCII do
375
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
376
+ expect(result['enum_test'].encoding).to eql(Encoding.default_internal)
386
377
  end
387
378
  end
388
379
  end
389
380
 
390
381
  it "should return String for a SET value" do
391
- @test_result['set_test'].class.should eql(String)
392
- @test_result['set_test'].should eql('val1,val2')
382
+ expect(@test_result['set_test'].class).to eql(String)
383
+ expect(@test_result['set_test']).to eql('val1,val2')
393
384
  end
394
385
 
395
- if defined? Encoding
396
- context "string encoding for SET values" do
397
- it "should default to the connection's encoding if Encoding.default_internal is nil" do
398
- with_internal_encoding nil do
399
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
400
- result['set_test'].encoding.should eql(Encoding.find('utf-8'))
386
+ context "string encoding for SET values" do
387
+ before { pending('Encoding is undefined') unless defined?(Encoding) }
401
388
 
402
- client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
403
- result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
404
- result['set_test'].encoding.should eql(Encoding.find('us-ascii'))
405
- client2.close
406
- end
389
+ it "should default to the connection's encoding if Encoding.default_internal is nil" do
390
+ with_internal_encoding nil do
391
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
392
+ expect(result['set_test'].encoding).to eql(Encoding::UTF_8)
393
+
394
+ client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
395
+ result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
396
+ expect(result['set_test'].encoding).to eql(Encoding::ASCII)
397
+ client2.close
407
398
  end
399
+ end
408
400
 
409
- it "should use Encoding.default_internal" do
410
- with_internal_encoding 'utf-8' do
411
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
412
- result['set_test'].encoding.should eql(Encoding.default_internal)
413
- end
401
+ it "should use Encoding.default_internal" do
402
+ with_internal_encoding Encoding::UTF_8 do
403
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
404
+ expect(result['set_test'].encoding).to eql(Encoding.default_internal)
405
+ end
414
406
 
415
- with_internal_encoding 'us-ascii' do
416
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
417
- result['set_test'].encoding.should eql(Encoding.default_internal)
418
- end
407
+ with_internal_encoding Encoding::ASCII do
408
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
409
+ expect(result['set_test'].encoding).to eql(Encoding.default_internal)
419
410
  end
420
411
  end
421
412
  end
422
413
 
423
414
  it "should return String for a BINARY value" do
424
- @test_result['binary_test'].class.should eql(String)
425
- @test_result['binary_test'].should eql("test#{"\000"*6}")
415
+ expect(@test_result['binary_test'].class).to eql(String)
416
+ expect(@test_result['binary_test']).to eql("test#{"\000"*6}")
426
417
  end
427
418
 
428
- if defined? Encoding
429
- context "string encoding for BINARY values" do
430
- it "should default to binary if Encoding.default_internal is nil" do
431
- with_internal_encoding nil do
432
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
433
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
434
- end
419
+ context "string encoding for BINARY values" do
420
+ before { pending('Encoding is undefined') unless defined?(Encoding) }
421
+
422
+ it "should default to binary if Encoding.default_internal is nil" do
423
+ with_internal_encoding nil do
424
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
425
+ expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
435
426
  end
427
+ end
436
428
 
437
- it "should not use Encoding.default_internal" do
438
- with_internal_encoding 'utf-8' do
439
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
440
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
441
- end
429
+ it "should not use Encoding.default_internal" do
430
+ with_internal_encoding Encoding::UTF_8 do
431
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
432
+ expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
433
+ end
442
434
 
443
- with_internal_encoding 'us-ascii' do
444
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
445
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
446
- end
435
+ with_internal_encoding Encoding::ASCII do
436
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
437
+ expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
447
438
  end
448
439
  end
449
440
  end
@@ -462,54 +453,54 @@ describe Mysql2::Result do
462
453
  'long_text_test' => 'LONGTEXT'
463
454
  }.each do |field, type|
464
455
  it "should return a String for #{type}" do
465
- @test_result[field].class.should eql(String)
466
- @test_result[field].should eql("test")
456
+ expect(@test_result[field].class).to eql(String)
457
+ expect(@test_result[field]).to eql("test")
467
458
  end
468
459
 
469
- if defined? Encoding
470
- context "string encoding for #{type} values" do
471
- if ['VARBINARY', 'TINYBLOB', 'BLOB', 'MEDIUMBLOB', 'LONGBLOB'].include?(type)
472
- it "should default to binary if Encoding.default_internal is nil" do
473
- with_internal_encoding nil do
474
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
475
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
476
- end
460
+ context "string encoding for #{type} values" do
461
+ before { pending('Encoding is undefined') unless defined?(Encoding) }
462
+
463
+ if ['VARBINARY', 'TINYBLOB', 'BLOB', 'MEDIUMBLOB', 'LONGBLOB'].include?(type)
464
+ it "should default to binary if Encoding.default_internal is nil" do
465
+ with_internal_encoding nil do
466
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
467
+ expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
477
468
  end
469
+ end
478
470
 
479
- it "should not use Encoding.default_internal" do
480
- with_internal_encoding 'utf-8' do
481
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
482
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
483
- end
471
+ it "should not use Encoding.default_internal" do
472
+ with_internal_encoding Encoding::UTF_8 do
473
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
474
+ expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
475
+ end
484
476
 
485
- with_internal_encoding 'us-ascii' do
486
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
487
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
488
- end
477
+ with_internal_encoding Encoding::ASCII do
478
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
479
+ expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
489
480
  end
490
- else
491
- it "should default to utf-8 if Encoding.default_internal is nil" do
492
- with_internal_encoding nil do
493
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
494
- result[field].encoding.should eql(Encoding.find('utf-8'))
495
-
496
- client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
497
- result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
498
- result[field].encoding.should eql(Encoding.find('us-ascii'))
499
- client2.close
500
- end
481
+ end
482
+ else
483
+ it "should default to utf-8 if Encoding.default_internal is nil" do
484
+ with_internal_encoding nil do
485
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
486
+ expect(result[field].encoding).to eql(Encoding::UTF_8)
487
+
488
+ client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
489
+ result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
490
+ expect(result[field].encoding).to eql(Encoding::ASCII)
491
+ client2.close
501
492
  end
493
+ end
502
494
 
503
- it "should use Encoding.default_internal" do
504
- with_internal_encoding 'utf-8' do
505
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
506
- result[field].encoding.should eql(Encoding.default_internal)
507
- end
495
+ it "should use Encoding.default_internal" do
496
+ with_internal_encoding Encoding::UTF_8 do
497
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
498
+ expect(result[field].encoding).to eql(Encoding.default_internal)
499
+ end
508
500
 
509
- with_internal_encoding 'us-ascii' do
510
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
511
- result[field].encoding.should eql(Encoding.default_internal)
512
- end
501
+ with_internal_encoding Encoding::ASCII do
502
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
503
+ expect(result[field].encoding).to eql(Encoding.default_internal)
513
504
  end
514
505
  end
515
506
  end