use #described_class, as suggested by RuboCop
This commit is contained in:
@ -3,7 +3,7 @@ require 'seeds_helper'
|
||||
|
||||
describe DockerClient, docker: true do
|
||||
let(:command) { 'whoami' }
|
||||
let(:docker_client) { DockerClient.new(execution_environment: FactoryGirl.build(:ruby), user: FactoryGirl.build(:admin)) }
|
||||
let(:docker_client) { described_class.new(execution_environment: FactoryGirl.build(:ruby), user: FactoryGirl.build(:admin)) }
|
||||
let(:execution_environment) { FactoryGirl.build(:ruby) }
|
||||
let(:image) { double }
|
||||
let(:submission) { FactoryGirl.create(:submission) }
|
||||
@ -13,27 +13,27 @@ describe DockerClient, docker: true do
|
||||
context 'when a socket error occurs' do
|
||||
it 'raises an error' do
|
||||
expect(Docker).to receive(:version).and_raise(Excon::Errors::SocketError.new(StandardError.new))
|
||||
expect { DockerClient.check_availability! }.to raise_error(DockerClient::Error)
|
||||
expect { described_class.check_availability! }.to raise_error(DockerClient::Error)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a timeout occurs' do
|
||||
it 'raises an error' do
|
||||
expect(Docker).to receive(:version).and_raise(Timeout::Error)
|
||||
expect { DockerClient.check_availability! }.to raise_error(DockerClient::Error)
|
||||
expect { described_class.check_availability! }.to raise_error(DockerClient::Error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.create_container' do
|
||||
after(:each) { DockerClient.create_container(execution_environment) }
|
||||
after(:each) { described_class.create_container(execution_environment) }
|
||||
|
||||
it 'uses the correct Docker image' do
|
||||
expect(DockerClient).to receive(:find_image_by_tag).with(execution_environment.docker_image).and_call_original
|
||||
expect(described_class).to receive(:find_image_by_tag).with(execution_environment.docker_image).and_call_original
|
||||
end
|
||||
|
||||
it 'creates a unique directory' do
|
||||
expect(DockerClient).to receive(:generate_local_workspace_path).and_call_original
|
||||
expect(described_class).to receive(:generate_local_workspace_path).and_call_original
|
||||
expect(FileUtils).to receive(:mkdir).with(kind_of(String)).and_call_original
|
||||
end
|
||||
|
||||
@ -46,12 +46,12 @@ describe DockerClient, docker: true do
|
||||
end
|
||||
|
||||
it 'configures mapped directories' do
|
||||
expect(DockerClient).to receive(:mapped_directories).and_call_original
|
||||
expect(described_class).to receive(:mapped_directories).and_call_original
|
||||
expect_any_instance_of(Docker::Container).to receive(:start).with(hash_including('Binds' => kind_of(Array)))
|
||||
end
|
||||
|
||||
it 'configures mapped ports' do
|
||||
expect(DockerClient).to receive(:mapped_ports).with(execution_environment).and_call_original
|
||||
expect(described_class).to receive(:mapped_ports).with(execution_environment).and_call_original
|
||||
expect_any_instance_of(Docker::Container).to receive(:start).with(hash_including('PortBindings' => kind_of(Hash)))
|
||||
end
|
||||
end
|
||||
@ -89,7 +89,7 @@ describe DockerClient, docker: true do
|
||||
after(:each) { File.delete(file_path) }
|
||||
|
||||
it 'creates a file' do
|
||||
expect(DockerClient).to receive(:local_workspace_path).at_least(:once).and_return(workspace_path)
|
||||
expect(described_class).to receive(:local_workspace_path).at_least(:once).and_return(workspace_path)
|
||||
docker_client.send(:create_workspace_file, container: CONTAINER, file: file)
|
||||
expect(File.exist?(file_path)).to be true
|
||||
expect(File.new(file_path, 'r').read).to eq(file.content)
|
||||
@ -97,8 +97,8 @@ describe DockerClient, docker: true do
|
||||
end
|
||||
|
||||
describe '.destroy_container' do
|
||||
let(:container) { DockerClient.create_container(execution_environment) }
|
||||
after(:each) { DockerClient.destroy_container(container) }
|
||||
let(:container) { described_class.create_container(execution_environment) }
|
||||
after(:each) { described_class.destroy_container(container) }
|
||||
|
||||
it 'stops the container' do
|
||||
expect(container).to receive(:stop).and_return(container)
|
||||
@ -114,7 +114,7 @@ describe DockerClient, docker: true do
|
||||
end
|
||||
|
||||
it 'removes the mapped directory' do
|
||||
expect(DockerClient).to receive(:local_workspace_path).and_return(workspace_path)
|
||||
expect(described_class).to receive(:local_workspace_path).and_return(workspace_path)
|
||||
expect(FileUtils).to receive(:rm_rf).with(workspace_path)
|
||||
end
|
||||
|
||||
@ -173,12 +173,12 @@ describe DockerClient, docker: true do
|
||||
|
||||
describe '.generate_local_workspace_path' do
|
||||
it 'includes the correct workspace root' do
|
||||
expect(DockerClient.generate_local_workspace_path).to start_with(DockerClient::LOCAL_WORKSPACE_ROOT.to_s)
|
||||
expect(described_class.generate_local_workspace_path).to start_with(DockerClient::LOCAL_WORKSPACE_ROOT.to_s)
|
||||
end
|
||||
|
||||
it 'includes a UUID' do
|
||||
expect(SecureRandom).to receive(:uuid).and_call_original
|
||||
DockerClient.generate_local_workspace_path
|
||||
described_class.generate_local_workspace_path
|
||||
end
|
||||
end
|
||||
|
||||
@ -186,22 +186,22 @@ describe DockerClient, docker: true do
|
||||
context 'with complete configuration' do
|
||||
it 'creates the file directory' do
|
||||
expect(FileUtils).to receive(:mkdir_p).with(DockerClient::LOCAL_WORKSPACE_ROOT)
|
||||
DockerClient.initialize_environment
|
||||
described_class.initialize_environment
|
||||
end
|
||||
end
|
||||
|
||||
context 'with incomplete configuration' do
|
||||
before(:each) { expect(DockerClient).to receive(:config).at_least(:once).and_return({}) }
|
||||
before(:each) { expect(described_class).to receive(:config).at_least(:once).and_return({}) }
|
||||
|
||||
it 'raises an error' do
|
||||
expect { DockerClient.initialize_environment }.to raise_error(DockerClient::Error)
|
||||
expect { described_class.initialize_environment }.to raise_error(DockerClient::Error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.local_workspace_path' do
|
||||
let(:container) { DockerClient.create_container(execution_environment) }
|
||||
let(:local_workspace_path) { DockerClient.local_workspace_path(container) }
|
||||
let(:container) { described_class.create_container(execution_environment) }
|
||||
let(:local_workspace_path) { described_class.local_workspace_path(container) }
|
||||
|
||||
it 'returns a path' do
|
||||
expect(local_workspace_path).to be_a(Pathname)
|
||||
@ -214,7 +214,7 @@ describe DockerClient, docker: true do
|
||||
|
||||
describe '.mapped_directories' do
|
||||
it 'returns a unique mapping' do
|
||||
mapping = DockerClient.mapped_directories(workspace_path).first
|
||||
mapping = described_class.mapped_directories(workspace_path).first
|
||||
expect(mapping).to start_with(workspace_path)
|
||||
expect(mapping).to end_with(DockerClient::CONTAINER_WORKSPACE_PATH)
|
||||
end
|
||||
@ -225,26 +225,26 @@ describe DockerClient, docker: true do
|
||||
before(:each) { execution_environment.exposed_ports = '3000' }
|
||||
|
||||
it 'returns a mapping' do
|
||||
expect(DockerClient.mapped_ports(execution_environment)).to be_a(Hash)
|
||||
expect(DockerClient.mapped_ports(execution_environment).length).to eq(1)
|
||||
expect(described_class.mapped_ports(execution_environment)).to be_a(Hash)
|
||||
expect(described_class.mapped_ports(execution_environment).length).to eq(1)
|
||||
end
|
||||
|
||||
it 'retrieves available ports' do
|
||||
expect(PortPool).to receive(:available_port)
|
||||
DockerClient.mapped_ports(execution_environment)
|
||||
described_class.mapped_ports(execution_environment)
|
||||
end
|
||||
end
|
||||
|
||||
context 'without exposed ports' do
|
||||
it 'returns an empty mapping' do
|
||||
expect(DockerClient.mapped_ports(execution_environment)).to eq({})
|
||||
expect(described_class.mapped_ports(execution_environment)).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#send_command' do
|
||||
let(:block) { Proc.new {} }
|
||||
let(:container) { DockerClient.create_container(execution_environment) }
|
||||
let(:container) { described_class.create_container(execution_environment) }
|
||||
let(:send_command) { docker_client.send(:send_command, command, container, &block) }
|
||||
after(:each) { send_command }
|
||||
|
||||
|
Reference in New Issue
Block a user