use #described_class, as suggested by RuboCop

This commit is contained in:
Hauke Klement
2015-02-16 17:04:28 +01:00
parent 0bb5dae334
commit 8e374c6914
37 changed files with 119 additions and 119 deletions

View File

@ -3,27 +3,27 @@ require 'rails_helper'
describe PortPool do
describe '.available_port' do
it 'is synchronized' do
expect(PortPool.instance_variable_get(:@mutex)).to receive(:synchronize)
PortPool.available_port
expect(described_class.instance_variable_get(:@mutex)).to receive(:synchronize)
described_class.available_port
end
context 'when a port is available' do
it 'returns the port' do
expect(PortPool.available_port).to be_a(Numeric)
expect(described_class.available_port).to be_a(Numeric)
end
it 'removes the port from the list of available ports' do
port = PortPool.available_port
expect(PortPool.instance_variable_get(:@available_ports)).not_to include(port)
port = described_class.available_port
expect(described_class.instance_variable_get(:@available_ports)).not_to include(port)
end
end
context 'when no port is available' do
it 'returns the port' do
available_ports = PortPool.instance_variable_get(:@available_ports)
PortPool.instance_variable_set(:@available_ports, [])
expect(PortPool.available_port).to be_nil
PortPool.instance_variable_set(:@available_ports, available_ports)
available_ports = described_class.instance_variable_get(:@available_ports)
described_class.instance_variable_set(:@available_ports, [])
expect(described_class.available_port).to be_nil
described_class.instance_variable_set(:@available_ports, available_ports)
end
end
end
@ -31,24 +31,24 @@ describe PortPool do
describe '.release' do
context 'when the port has been obtained earlier' do
it 'adds the port to the list of available ports' do
port = PortPool.available_port
expect(PortPool.instance_variable_get(:@available_ports)).not_to include(port)
PortPool.release(port)
expect(PortPool.instance_variable_get(:@available_ports)).to include(port)
port = described_class.available_port
expect(described_class.instance_variable_get(:@available_ports)).not_to include(port)
described_class.release(port)
expect(described_class.instance_variable_get(:@available_ports)).to include(port)
end
end
context 'when the port has not been obtained earlier' do
it 'does not add the port to the list of available ports' do
port = PortPool.instance_variable_get(:@available_ports).sample
expect { PortPool.release(port) }.not_to change { PortPool.instance_variable_get(:@available_ports).length }
port = described_class.instance_variable_get(:@available_ports).sample
expect { described_class.release(port) }.not_to change { described_class.instance_variable_get(:@available_ports).length }
end
end
context 'when the port is not included in the port range' do
it 'does not add the port to the list of available ports' do
port = nil
expect { PortPool.release(port) }.not_to change { PortPool.instance_variable_get(:@available_ports).length }
expect { described_class.release(port) }.not_to change { described_class.instance_variable_get(:@available_ports).length }
end
end
end