Skip to content

Commit ba805ce

Browse files
committed
DRY
1 parent 42075f8 commit ba805ce

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

spec/mysql2/statement_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
@client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => "utf8"))
77
end
88

9+
def stmt_count
10+
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
11+
end
12+
913
it "should create a statement" do
1014
statement = nil
11-
expect { statement = @client.prepare 'SELECT 1' }.to change {
12-
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
13-
}.by(1)
15+
expect { statement = @client.prepare 'SELECT 1' }.to change(&method(:stmt_count)).by(1)
1416
expect(statement).to be_an_instance_of(Mysql2::Statement)
1517
end
1618

@@ -689,9 +691,7 @@
689691
context 'close' do
690692
it 'should free server resources' do
691693
stmt = @client.prepare 'SELECT 1'
692-
expect { stmt.close }.to change {
693-
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
694-
}.by(-1)
694+
expect { stmt.close }.to change(&method(:stmt_count)).by(-1)
695695
end
696696

697697
it 'should raise an error on subsequent execution' do

0 commit comments

Comments
 (0)