Apply automatic rubocop fixes

This commit is contained in:
Sebastian Serth
2021-05-14 10:51:44 +02:00
parent fe4000916c
commit 6cbecb5b39
440 changed files with 2705 additions and 1853 deletions

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Assessor do
@@ -8,7 +10,7 @@ describe Assessor do
let(:stdout) { "Finished in 0.1 seconds (files took 0.1 seconds to load)\n2 examples, 1 failure" }
context 'when an error occurs' do
before(:each) do
before do
expect_any_instance_of(TestingFrameworkAdapter).to receive(:test_outcome).and_raise
end
@@ -22,7 +24,7 @@ describe Assessor do
end
context 'when no error occurs' do
after(:each) { assess }
after { assess }
it 'utilizes the testing framework adapter' do
expect(assessor.instance_variable_get(:@testing_framework_adapter)).to receive(:test_outcome)
@@ -40,7 +42,7 @@ describe Assessor do
let(:test_outcome) { {count: count, passed: passed} }
it 'returns the correct score' do
expect(assessor.send(:calculate_score, test_outcome)).to eq(passed.to_f / count.to_f)
expect(assessor.send(:calculate_score, test_outcome)).to eq(passed.to_f / count)
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe CodeOcean::Config do
@@ -10,8 +12,9 @@ describe CodeOcean::Config do
let(:read) { described_class.new(filename).read }
context 'when the file is present' do
before(:each) { File.write(path, {Rails.env.to_s => content}.to_yaml) }
after(:each) { FileUtils.rm(path) }
before { File.write(path, {Rails.env.to_s => content}.to_yaml) }
after { FileUtils.rm(path) }
it 'returns the environment-specific content' do
expect(read).to eq(content.with_indifferent_access)
@@ -30,8 +33,9 @@ describe CodeOcean::Config do
let(:read) { described_class.new(filename).read(erb: true) }
context 'when the file is present' do
before(:each) { File.write(path, {Rails.env.to_s => content}.to_yaml) }
after(:each) { FileUtils.rm(path) }
before { File.write(path, {Rails.env.to_s => content}.to_yaml) }
after { FileUtils.rm(path) }
it 'returns the environment-specific content' do
expect(read).to eq(content.with_indifferent_access)

View File

@@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
require 'seeds_helper'
@@ -85,7 +86,7 @@ describe DockerClient, docker: true do
FileUtils.mkdir_p(workspace_path)
allow(described_class).to receive(:generate_local_workspace_path).and_return(local_workspace_path)
expect(described_class).to receive(:container_creation_options).with(execution_environment, local_workspace_path)
.and_wrap_original do |original_method, *args, &block|
.and_wrap_original do |original_method, *args, &block|
result = original_method.call(*args, &block)
result['NanoCPUs'] = 2 * 1_000_000_000 # CPU quota in units of 10^-9 CPUs.
result
@@ -113,7 +114,7 @@ describe DockerClient, docker: true do
let(:error) { Docker::Error::NotFoundError.new }
context 'when retries are left' do
before(:each) do
before do
expect(described_class).to receive(:mapped_directories).and_raise(error).and_call_original
end
@@ -123,7 +124,7 @@ describe DockerClient, docker: true do
end
context 'when no retries are left' do
before(:each) do
before do
expect(described_class).to receive(:mapped_directories).exactly(DockerClient::RETRY_COUNT + 1).times.and_raise(error)
end
@@ -138,24 +139,24 @@ describe DockerClient, docker: true do
describe '#create_workspace_files' do
let(:container) { double }
before(:each) do
before do
expect(container).to receive(:binds).at_least(:once).and_return(["#{workspace_path}:#{DockerClient::CONTAINER_WORKSPACE_PATH}"])
end
after(:each) { docker_client.send(:create_workspace_files, container, submission) }
after { docker_client.send(:create_workspace_files, container, submission) }
it 'creates submission-specific directories' do
expect(Dir).to receive(:mkdir).at_least(:once).and_call_original
end
it 'copies binary files' do
submission.collect_files.select { |file| file.file_type.binary? }.each do |file|
submission.collect_files.select {|file| file.file_type.binary? }.each do |file|
expect(docker_client).to receive(:copy_file_to_workspace).with(container: container, file: file)
end
end
it 'creates non-binary files' do
submission.collect_files.reject { |file| file.file_type.binary? }.each do |file|
submission.collect_files.reject {|file| file.file_type.binary? }.each do |file|
expect(docker_client).to receive(:create_workspace_file).with(container: container, file: file)
end
end
@@ -164,7 +165,8 @@ describe DockerClient, docker: true do
describe '#create_workspace_file' do
let(:file) { FactoryBot.build(:file, content: 'puts 42') }
let(:file_path) { File.join(workspace_path, file.name_with_extension) }
after(:each) { File.delete(file_path) }
after { File.delete(file_path) }
it 'creates a file' do
expect(described_class).to receive(:local_workspace_path).at_least(:once).and_return(workspace_path)
@@ -177,7 +179,8 @@ describe DockerClient, docker: true do
describe '.destroy_container' do
let(:container) { described_class.create_container(execution_environment) }
after(:each) { described_class.destroy_container(container) }
after { described_class.destroy_container(container) }
it 'kills running processes' do
expect(container).to receive(:kill).and_return(container)
@@ -190,8 +193,8 @@ describe DockerClient, docker: true do
it 'removes the mapped directory' do
expect(described_class).to receive(:local_workspace_path).at_least(:once).and_return(workspace_path)
#!TODO Fix this
#expect(PathName).to receive(:rmtree).with(workspace_path)
# !TODO Fix this
# expect(PathName).to receive(:rmtree).with(workspace_path)
end
it 'deletes the container' do
@@ -216,9 +219,9 @@ describe DockerClient, docker: true do
let(:error) { Excon::Errors::SocketError.new(SocketError.new) }
context 'when retries are left' do
let(:result) { {status: "ok", stdout: 42} }
let(:result) { {status: 'ok', stdout: 42} }
before(:each) do
before do
expect(docker_client).to receive(:send_command).and_raise(error).and_return(result)
end
@@ -228,43 +231,45 @@ describe DockerClient, docker: true do
end
context 'when no retries are left' do
before(:each) do
before do
expect(docker_client).to receive(:send_command).exactly(DockerClient::RETRY_COUNT + 1).times.and_raise(error)
end
it 'raises the error' do
pending("retries are disabled")
#!TODO Retries is disabled
#expect { execute_arbitrary_command }.to raise_error(error)
pending('retries are disabled')
# !TODO Retries is disabled
# expect { execute_arbitrary_command }.to raise_error(error)
end
end
end
end
describe '#execute_run_command' do
let(:filename) { submission.exercise.files.detect { |file| file.role == 'main_file' }.name_with_extension }
after(:each) { docker_client.send(:execute_run_command, submission, filename) }
let(:filename) { submission.exercise.files.detect {|file| file.role == 'main_file' }.name_with_extension }
after { docker_client.send(:execute_run_command, submission, filename) }
it 'takes a container from the pool' do
pending("todo in the future")
pending('todo in the future')
expect(DockerContainerPool).to receive(:get_container).with(submission.execution_environment).and_call_original
end
it 'creates the workspace files' do
pending("todo in the future")
pending('todo in the future')
expect(docker_client).to receive(:create_workspace_files)
end
it 'executes the run command' do
pending("todo in the future")
pending('todo in the future')
expect(submission.execution_environment).to receive(:run_command).and_call_original
expect(docker_client).to receive(:send_command).with(kind_of(String), kind_of(Docker::Container))
end
end
describe '#execute_test_command' do
let(:filename) { submission.exercise.files.detect { |file| file.role == 'teacher_defined_test' || file.role == 'teacher_defined_linter' }.name_with_extension }
after(:each) { docker_client.send(:execute_test_command, submission, filename) }
let(:filename) { submission.exercise.files.detect {|file| file.role == 'teacher_defined_test' || file.role == 'teacher_defined_linter' }.name_with_extension }
after { docker_client.send(:execute_test_command, submission, filename) }
it 'takes a container from the pool' do
expect(DockerContainerPool).to receive(:get_container).with(submission.execution_environment).and_call_original
@@ -300,7 +305,7 @@ describe DockerClient, docker: true do
end
context 'with incomplete configuration' do
before(:each) { expect(described_class).to receive(:config).at_least(:once).and_return({}) }
before { expect(described_class).to receive(:config).at_least(:once).and_return({}) }
it 'raises an error' do
expect { described_class.initialize_environment }.to raise_error(DockerClient::Error)
@@ -331,7 +336,7 @@ describe DockerClient, docker: true do
describe '.mapped_ports' do
context 'with exposed ports' do
before(:each) { execution_environment.exposed_ports = '3000' }
before { execution_environment.exposed_ports = '3000' }
it 'returns a mapping' do
expect(described_class.mapped_ports(execution_environment)).to be_a(Hash)
@@ -355,30 +360,31 @@ describe DockerClient, docker: true do
let(:block) { proc {} }
let(:container) { described_class.create_container(execution_environment) }
let(:send_command) { docker_client.send(:send_command, command, container, &block) }
after(:each) { send_command }
after { send_command }
it 'limits the execution time' do
expect(Timeout).to receive(:timeout).at_least(:once).with(kind_of(Numeric)).and_call_original
end
it 'provides the command to be executed as input' do
pending("we are currently not using any input and for output server send events instead of attach.")
pending('we are currently not using any input and for output server send events instead of attach.')
expect(container).to receive(:attach).with(stdin: kind_of(StringIO))
end
it 'calls the block' do
pending("block is no longer called, see revision 4cbf9970b13362efd4588392cafe4f7fd7cb31c3 to get information how it was done before.")
pending('block is no longer called, see revision 4cbf9970b13362efd4588392cafe4f7fd7cb31c3 to get information how it was done before.')
expect(block).to receive(:call)
end
context 'when a timeout occurs' do
before(:each) do
before do
expect(container).to receive(:exec).once.and_raise(Timeout::Error)
expect(container).to receive(:exec).twice.and_return([[], []])
end
it 'destroys the container asynchronously' do
pending("Container is destroyed, but not as expected in this test. ToDo update this test.")
pending('Container is destroyed, but not as expected in this test. ToDo update this test.')
expect(Concurrent::Future).to receive(:execute)
end
@@ -389,7 +395,7 @@ describe DockerClient, docker: true do
context 'when the container terminates timely' do
it 'destroys the container asynchronously' do
pending("Container is destroyed, but not as expected in this test. ToDo update this test.")
pending('Container is destroyed, but not as expected in this test. ToDo update this test.')
expect(Concurrent::Future).to receive(:execute)
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe DockerContainerMixin do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe FileTree do
@@ -161,7 +163,7 @@ describe FileTree do
context 'for intermediary nodes' do
let(:node) do
root.add(Tree::TreeNode.new('').tap { |node| node.add(Tree::TreeNode.new('')) })
root.add(Tree::TreeNode.new('').tap {|node| node.add(Tree::TreeNode.new('')) })
end
it 'is a folder icon' do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails/generators'
require 'generators/testing_framework_adapter_generator'
require 'rails_helper'
@@ -10,11 +12,11 @@ describe TestingFrameworkAdapterGenerator do
let(:path) { Rails.root.join('lib', "#{name.underscore}_adapter.rb") }
let(:spec_path) { Rails.root.join('spec', 'lib', "#{name.underscore}_adapter_spec.rb") }
before(:each) do
before do
silenced { Rails::Generators.invoke('testing_framework_adapter', [name]) }
end
after(:each) do
after do
File.delete(path)
File.delete(spec_path)
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe JunitAdapter do

View File

@@ -1,10 +1,12 @@
# frozen_string_literal: true
require 'rails_helper'
describe MochaAdapter do
let(:adapter) { described_class.new }
let(:count) { 42 }
let(:failed) { 25 }
let(:stdout) { "#{count-failed} passing (20ms)\n\n#{failed} failing" }
let(:stdout) { "#{count - failed} passing (20ms)\n\n#{failed} failing" }
describe '#parse_output' do
it 'returns the correct numbers' do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe NonceStore do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe PortPool do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe PyUnitAdapter do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe RspecAdapter do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe SqlResultSetComparatorAdapter do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe TestingFrameworkAdapter do