0
0
Fork 0

Fix Lint/ConstantDefinitionInBlock cop (#24763)

This commit is contained in:
Matt Jankowski 2023-05-03 04:32:30 -04:00 committed by GitHub
parent 8b636a29c6
commit 3df665fd23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 120 additions and 118 deletions

View file

@ -3,30 +3,32 @@
require 'rails_helper'
describe ConnectionPool::SharedTimedStack do
class MiniConnection
attr_reader :site
subject { described_class.new(5) { |site| mini_connection_class.new(site) } }
def initialize(site)
@site = site
let(:mini_connection_class) do
Class.new do
attr_reader :site
def initialize(site)
@site = site
end
end
end
subject { described_class.new(5) { |site| MiniConnection.new(site) } }
describe '#push' do
it 'keeps the connection in the stack' do
subject.push(MiniConnection.new('foo'))
subject.push(mini_connection_class.new('foo'))
expect(subject.size).to eq 1
end
end
describe '#pop' do
it 'returns a connection' do
expect(subject.pop('foo')).to be_a MiniConnection
expect(subject.pop('foo')).to be_a mini_connection_class
end
it 'returns the same connection that was pushed in' do
connection = MiniConnection.new('foo')
connection = mini_connection_class.new('foo')
subject.push(connection)
expect(subject.pop('foo')).to be connection
end
@ -36,8 +38,8 @@ describe ConnectionPool::SharedTimedStack do
end
it 'repurposes a connection for a different site when maximum amount is reached' do
5.times { subject.push(MiniConnection.new('foo')) }
expect(subject.pop('bar')).to be_a MiniConnection
5.times { subject.push(mini_connection_class.new('foo')) }
expect(subject.pop('bar')).to be_a mini_connection_class
end
end
@ -47,14 +49,14 @@ describe ConnectionPool::SharedTimedStack do
end
it 'returns false when there are connections on the stack' do
subject.push(MiniConnection.new('foo'))
subject.push(mini_connection_class.new('foo'))
expect(subject.empty?).to be false
end
end
describe '#size' do
it 'returns the number of connections on the stack' do
2.times { subject.push(MiniConnection.new('foo')) }
2.times { subject.push(mini_connection_class.new('foo')) }
expect(subject.size).to eq 2
end
end