Skip to content

Commit c118d26

Browse files
committed
Clean up some ugly rescues
1 parent 52a6d2d commit c118d26

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

spec/mysql2/client_spec.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ def connect *args
9696
first_conn_id = result.first['CONNECTION_ID()']
9797

9898
# break the current connection
99-
begin
100-
client.query("KILL #{first_conn_id}")
101-
rescue Mysql2::Error
102-
end
99+
expect { client.query("KILL #{first_conn_id}") }.to raise_error(Mysql2::Error)
103100

104101
client.ping # reconnect now
105102

@@ -404,13 +401,7 @@ def connect *args
404401
thr = Thread.new { @client.query("SELECT 1", :async => true) }
405402

406403
thr.join
407-
begin
408-
@client.query("SELECT 1")
409-
rescue Mysql2::Error => e
410-
message = e.message
411-
end
412-
re = Regexp.escape(thr.inspect)
413-
message.should match(Regexp.new(re))
404+
expect { @client.query('SELECT 1') }.to raise_error(Mysql2::Error, Regexp.new(Regexp.escape(thr.inspect)))
414405
end
415406

416407
it "should timeout if we wait longer than :read_timeout" do
@@ -461,7 +452,6 @@ def connect *args
461452
}.should raise_error(Mysql2::Error)
462453
end
463454

464-
465455
it 'should be impervious to connection-corrupting timeouts ' do
466456
pending('`Thread.handle_interrupt` is not defined') unless Thread.respond_to?(:handle_interrupt)
467457
# attempt to break the connection

spec/mysql2/result_spec.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,8 @@
338338
end
339339

340340
it "should raise an error given an invalid DATETIME" do
341-
begin
342-
@client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each
343-
rescue Mysql2::Error => e
344-
error = e
345-
end
346-
347-
error.message.should eql("Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
341+
expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \
342+
raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
348343
end
349344

350345
if defined? Encoding

0 commit comments

Comments
 (0)