@@ -198,11 +198,25 @@ def test_execute_batch2
198
198
199
199
def test_new
200
200
db = SQLite3 ::Database . new ( ':memory:' )
201
- assert db
201
+ assert_instance_of ( SQLite3 :: Database , db )
202
202
ensure
203
203
db . close if db
204
204
end
205
205
206
+ def test_open
207
+ db = SQLite3 ::Database . open ( ':memory:' )
208
+ assert_instance_of ( SQLite3 ::Database , db )
209
+ ensure
210
+ db . close if db
211
+ end
212
+
213
+ def test_open_returns_block_result
214
+ result = SQLite3 ::Database . open ( ':memory:' ) do |db |
215
+ :foo
216
+ end
217
+ assert_equal :foo , result
218
+ end
219
+
206
220
def test_new_yields_self
207
221
thing = nil
208
222
SQLite3 ::Database . new ( ':memory:' ) do |db |
@@ -211,6 +225,14 @@ def test_new_yields_self
211
225
assert_instance_of ( SQLite3 ::Database , thing )
212
226
end
213
227
228
+ def test_open_yields_self
229
+ thing = nil
230
+ SQLite3 ::Database . open ( ':memory:' ) do |db |
231
+ thing = db
232
+ end
233
+ assert_instance_of ( SQLite3 ::Database , thing )
234
+ end
235
+
214
236
def test_new_with_options
215
237
# determine if Ruby is running on Big Endian platform
216
238
utf16 = ( [ 1 ] . pack ( "I" ) == [ 1 ] . pack ( "N" ) ) ? "UTF-16BE" : "UTF-16LE"
@@ -221,7 +243,7 @@ def test_new_with_options
221
243
db = SQLite3 ::Database . new ( Iconv . conv ( utf16 , 'UTF-8' , ':memory:' ) ,
222
244
:utf16 => true )
223
245
end
224
- assert db
246
+ assert_instance_of ( SQLite3 :: Database , db )
225
247
ensure
226
248
db . close if db
227
249
end
@@ -241,6 +263,15 @@ def test_block_closes_self
241
263
assert thing . closed?
242
264
end
243
265
266
+ def test_open_with_block_closes_self
267
+ thing = nil
268
+ SQLite3 ::Database . open ( ':memory:' ) do |db |
269
+ thing = db
270
+ assert !thing . closed?
271
+ end
272
+ assert thing . closed?
273
+ end
274
+
244
275
def test_block_closes_self_even_raised
245
276
thing = nil
246
277
begin
@@ -253,6 +284,18 @@ def test_block_closes_self_even_raised
253
284
assert thing . closed?
254
285
end
255
286
287
+ def test_open_with_block_closes_self_even_raised
288
+ thing = nil
289
+ begin
290
+ SQLite3 ::Database . open ( ':memory:' ) do |db |
291
+ thing = db
292
+ raise
293
+ end
294
+ rescue
295
+ end
296
+ assert thing . closed?
297
+ end
298
+
256
299
def test_prepare
257
300
db = SQLite3 ::Database . new ( ':memory:' )
258
301
stmt = db . prepare ( 'select "hello world"' )
0 commit comments