Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Jul 15, 2016
1 parent 42075f8 commit ba805ce
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions spec/mysql2/statement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
@client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => "utf8"))
end

def stmt_count
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
end

it "should create a statement" do
statement = nil
expect { statement = @client.prepare 'SELECT 1' }.to change {
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
}.by(1)
expect { statement = @client.prepare 'SELECT 1' }.to change(&method(:stmt_count)).by(1)
expect(statement).to be_an_instance_of(Mysql2::Statement)
end

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

it 'should raise an error on subsequent execution' do
Expand Down

0 comments on commit ba805ce

Please sign in to comment.