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

@ -3,7 +3,7 @@
require 'rails_helper'
describe Assessor do
let(:assessor) { described_class.new(execution_environment: FactoryBot.build(:ruby)) }
let(:assessor) { described_class.new(execution_environment: build(:ruby)) }
describe '#assess' do
let(:assess) { assessor.assess(stdout: stdout) }
@ -55,7 +55,7 @@ describe Assessor do
context 'with an execution environment without a testing framework adapter' do
it 'raises an error' do
expect { described_class.new(execution_environment: FactoryBot.build(:ruby, testing_framework: nil)) }.to raise_error(Assessor::Error)
expect { described_class.new(execution_environment: build(:ruby, testing_framework: nil)) }.to raise_error(Assessor::Error)
end
end
end

View File

@ -7,14 +7,14 @@ WORKSPACE_PATH = Rails.root.join('tmp', 'files', Rails.env, 'code_ocean_test')
describe DockerClient do
let(:command) { 'whoami' }
let(:docker_client) { described_class.new(execution_environment: FactoryBot.build(:java), user: FactoryBot.build(:admin)) }
let(:execution_environment) { FactoryBot.build(:java) }
let(:docker_client) { described_class.new(execution_environment: build(:java), user: build(:admin)) }
let(:execution_environment) { build(:java) }
let(:image) { double }
let(:submission) { FactoryBot.create(:submission) }
let(:submission) { create(:submission) }
let(:workspace_path) { WORKSPACE_PATH }
before do
docker_image = Docker::Image.new(Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex, 'RepoTags' => [FactoryBot.attributes_for(:java)[:docker_image]])
docker_image = Docker::Image.new(Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex, 'RepoTags' => [attributes_for(:java)[:docker_image]])
allow(described_class).to receive(:find_image_by_tag).and_return(docker_image)
described_class.initialize_environment
allow(described_class).to receive(:container_creation_options).and_wrap_original do |original_method, *args, &block|
@ -177,7 +177,7 @@ describe DockerClient do
describe '#create_workspace_file' do
let(:container) { Docker::Container.send(:new, Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex) }
let(:file) { FactoryBot.build(:file, content: 'puts 42') }
let(:file) { build(:file, content: 'puts 42') }
let(:file_path) { File.join(workspace_path, file.name_with_extension) }
after { File.delete(file_path) }

View File

@ -10,7 +10,7 @@ describe FileTree do
context 'with a media file' do
context 'with an audio file' do
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_mp3)) }
let(:file) { build(:file, file_type: build(:dot_mp3)) }
it 'is an audio file icon' do
expect(file_icon).to include('fa-file-audio-o')
@ -18,7 +18,7 @@ describe FileTree do
end
context 'with an image file' do
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_jpg)) }
let(:file) { build(:file, file_type: build(:dot_jpg)) }
it 'is an image file icon' do
expect(file_icon).to include('fa-file-image-o')
@ -26,7 +26,7 @@ describe FileTree do
end
context 'with a video file' do
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_mp4)) }
let(:file) { build(:file, file_type: build(:dot_mp4)) }
it 'is a video file icon' do
expect(file_icon).to include('fa-file-video-o')
@ -36,7 +36,7 @@ describe FileTree do
context 'with other files' do
context 'with a read-only file' do
let(:file) { FactoryBot.build(:file, read_only: true) }
let(:file) { build(:file, read_only: true) }
it 'is a lock icon' do
expect(file_icon).to include('fa-lock')
@ -44,7 +44,7 @@ describe FileTree do
end
context 'with an executable file' do
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_py)) }
let(:file) { build(:file, file_type: build(:dot_py)) }
it 'is a code file icon' do
expect(file_icon).to include('fa-file-code-o')
@ -52,7 +52,7 @@ describe FileTree do
end
context 'with a renderable file' do
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_svg)) }
let(:file) { build(:file, file_type: build(:dot_svg)) }
it 'is a text file icon' do
expect(file_icon).to include('fa-file-text-o')
@ -60,7 +60,7 @@ describe FileTree do
end
context 'with all other files' do
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_md)) }
let(:file) { build(:file, file_type: build(:dot_md)) }
it 'is a generic file icon' do
expect(file_icon).to include('fa-file-o')
@ -77,7 +77,7 @@ describe FileTree do
describe '#initialize' do
let(:file_tree) { described_class.new(files) }
let(:files) { FactoryBot.build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
let(:files) { build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
it 'creates a root node' do
# Instead of checking #initialize on the parent, we validate #set_as_root!
@ -95,7 +95,7 @@ describe FileTree do
end
describe '#map_to_js_tree' do
let(:file) { FactoryBot.build(:file) }
let(:file) { build(:file) }
let(:js_tree) { file_tree.send(:map_to_js_tree, node) }
let!(:leaf) { root.add(Tree::TreeNode.new('', file)) }
let(:root) { Tree::TreeNode.new('', file) }
@ -186,7 +186,7 @@ describe FileTree do
end
context 'with files' do
let(:files) { FactoryBot.build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
let(:files) { build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
let(:file_tree) { described_class.new(files) }
let(:js_tree) { file_tree.to_js_tree }

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