Update bundle (with newest rubocop version) and fix offenses

This commit is contained in:
Sebastian Serth
2022-01-03 18:11:17 +01:00
parent 57e32611ed
commit ea85519163
93 changed files with 968 additions and 985 deletions

View File

@ -4,8 +4,8 @@ require 'rails_helper'
require 'pathname'
describe Runner::Strategy::DockerContainerPool do
let(:runner_id) { FactoryBot.attributes_for(:runner)[:runner_id] }
let(:execution_environment) { FactoryBot.create :ruby }
let(:runner_id) { attributes_for(:runner)[:runner_id] }
let(:execution_environment) { create :ruby }
let(:container_pool) { described_class.new(runner_id, execution_environment) }
let(:docker_container_pool_url) { 'http://localhost:1234' }
let(:config) { {url: docker_container_pool_url, unused_runner_expiration_time: 180} }
@ -112,22 +112,20 @@ describe Runner::Strategy::DockerContainerPool do
context 'when receiving a normal file' do
let(:file_content) { 'print("Hello World!")' }
let(:files) { [FactoryBot.build(:file, content: file_content)] }
let(:files) { [build(:file, content: file_content)] }
it 'writes the file to disk' do
file = instance_double(File)
allow(File).to receive(:open).and_yield(file)
expect(file).to receive(:write).with(file_content)
expect(File).to receive(:write).with(local_path.join(files.first.filepath), file_content)
container_pool.copy_files(files)
end
it 'creates the file inside the workspace' do
expect(File).to receive(:open).with(local_path.join(files.first.filepath), 'w')
expect(File).to receive(:write).with(local_path.join(files.first.filepath), files.first.content)
container_pool.copy_files(files)
end
it 'raises an error in case of an IOError' do
allow(File).to receive(:open).and_raise(IOError)
allow(File).to receive(:write).and_raise(IOError)
expect { container_pool.copy_files(files) }.to raise_error(Runner::Error::WorkspaceError, /#{files.first.filepath}/)
end
@ -137,10 +135,10 @@ describe Runner::Strategy::DockerContainerPool do
context 'when the file is inside a directory' do
let(:directory) { 'temp/dir' }
let(:files) { [FactoryBot.build(:file, path: directory)] }
let(:files) { [build(:file, path: directory)] }
before do
allow(File).to receive(:open)
allow(File).to receive(:write)
allow(FileUtils).to receive(:mkdir_p).with(local_path)
allow(FileUtils).to receive(:mkdir_p).with(local_path.join(directory))
end
@ -159,7 +157,7 @@ describe Runner::Strategy::DockerContainerPool do
end
context 'when receiving a binary file' do
let(:files) { [FactoryBot.build(:file, :image)] }
let(:files) { [build(:file, :image)] }
it 'copies the file inside the workspace' do
expect(FileUtils).to receive(:cp).with(files.first.native_file.path, local_path.join(files.first.filepath))
@ -168,11 +166,11 @@ describe Runner::Strategy::DockerContainerPool do
end
context 'when receiving multiple files' do
let(:files) { FactoryBot.build_list(:file, 3) }
let(:files) { build_list(:file, 3) }
it 'creates all files' do
files.each do |file|
expect(File).to receive(:open).with(local_path.join(file.filepath), 'w')
expect(File).to receive(:write).with(local_path.join(file.filepath), file.content)
end
container_pool.copy_files(files)
end

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe Runner::Strategy::Poseidon do
let(:runner_id) { FactoryBot.attributes_for(:runner)[:runner_id] }
let(:execution_environment) { FactoryBot.create :ruby }
let(:runner_id) { attributes_for(:runner)[:runner_id] }
let(:execution_environment) { create :ruby }
let(:poseidon) { described_class.new(runner_id, execution_environment) }
let(:error_message) { 'test error message' }
let(:response_body) { nil }
@ -128,7 +128,7 @@ describe Runner::Strategy::Poseidon do
describe '::sync_environment' do
let(:action) { -> { described_class.sync_environment(execution_environment) } }
let(:execution_environment) { FactoryBot.create(:ruby) }
let(:execution_environment) { create(:ruby) }
it 'makes the correct request to Poseidon' do
faraday_connection = instance_double 'Faraday::Connection'
@ -321,7 +321,7 @@ describe Runner::Strategy::Poseidon do
describe '#copy_files' do
let(:file_content) { 'print("Hello World!")' }
let(:file) { FactoryBot.build(:file, content: file_content) }
let(:file) { build(:file, content: file_content) }
let(:action) { -> { poseidon.copy_files([file]) } }
let(:encoded_file_content) { Base64.strict_encode64(file.content) }
let!(:copy_files_stub) do