Apply manual rubocop fixes
This commit is contained in:
@@ -11,7 +11,7 @@ describe Assessor do
|
||||
|
||||
context 'when an error occurs' do
|
||||
before do
|
||||
expect_any_instance_of(TestingFrameworkAdapter).to receive(:test_outcome).and_raise
|
||||
allow_any_instance_of(TestingFrameworkAdapter).to receive(:test_outcome).and_raise
|
||||
end
|
||||
|
||||
it 'catches the error' do
|
||||
|
@@ -4,7 +4,7 @@ require 'rails_helper'
|
||||
|
||||
describe CodeOcean::Config do
|
||||
describe '#read' do
|
||||
let(:content) { {foo: 'bar'} }
|
||||
let(:content) { {'foo' => 'bar'} }
|
||||
let(:filename) { :foo }
|
||||
|
||||
context 'with a .yml file' do
|
||||
|
@@ -3,8 +3,6 @@
|
||||
require 'rails_helper'
|
||||
require 'seeds_helper'
|
||||
|
||||
# rubocop:disable RSpec/MultipleMemoizedHelpers
|
||||
|
||||
WORKSPACE_PATH = Rails.root.join('tmp', 'files', Rails.env, 'code_ocean_test')
|
||||
|
||||
describe DockerClient, docker: true do
|
||||
@@ -26,14 +24,14 @@ describe DockerClient, docker: true do
|
||||
describe '.check_availability!' 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))
|
||||
allow(Docker).to receive(:version).and_raise(Excon::Errors::SocketError.new(StandardError.new))
|
||||
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)
|
||||
allow(Docker).to receive(:version).and_raise(Timeout::Error)
|
||||
expect { described_class.check_availability! }.to raise_error(DockerClient::Error)
|
||||
end
|
||||
end
|
||||
@@ -115,7 +113,7 @@ describe DockerClient, docker: true do
|
||||
|
||||
context 'when retries are left' do
|
||||
before do
|
||||
expect(described_class).to receive(:mapped_directories).and_raise(error).and_call_original
|
||||
allow(described_class).to receive(:mapped_directories).and_raise(error).and_call_original
|
||||
end
|
||||
|
||||
it 'retries to create a container' do
|
||||
@@ -125,7 +123,7 @@ describe DockerClient, docker: true do
|
||||
|
||||
context 'when no retries are left' do
|
||||
before do
|
||||
expect(described_class).to receive(:mapped_directories).exactly(DockerClient::RETRY_COUNT + 1).times.and_raise(error)
|
||||
allow(described_class).to receive(:mapped_directories).exactly(DockerClient::RETRY_COUNT + 1).times.and_raise(error)
|
||||
end
|
||||
|
||||
it 'raises the error' do
|
||||
@@ -140,7 +138,7 @@ describe DockerClient, docker: true do
|
||||
let(:container) { double }
|
||||
|
||||
before do
|
||||
expect(container).to receive(:binds).at_least(:once).and_return(["#{workspace_path}:#{DockerClient::CONTAINER_WORKSPACE_PATH}"])
|
||||
allow(container).to receive(:binds).at_least(:once).and_return(["#{workspace_path}:#{DockerClient::CONTAINER_WORKSPACE_PATH}"])
|
||||
end
|
||||
|
||||
after { docker_client.send(:create_workspace_files, container, submission) }
|
||||
@@ -183,11 +181,11 @@ describe DockerClient, docker: true do
|
||||
after { described_class.destroy_container(container) }
|
||||
|
||||
it 'kills running processes' do
|
||||
expect(container).to receive(:kill).and_return(container)
|
||||
allow(container).to receive(:kill).and_return(container)
|
||||
end
|
||||
|
||||
it 'releases allocated ports' do
|
||||
expect(container).to receive(:port_bindings).at_least(:once).and_return(foo: [{'HostPort' => '42'}])
|
||||
allow(container).to receive(:port_bindings).at_least(:once).and_return(foo: [{'HostPort' => '42'}])
|
||||
expect(PortPool).to receive(:release)
|
||||
end
|
||||
|
||||
@@ -211,7 +209,7 @@ describe DockerClient, docker: true do
|
||||
end
|
||||
|
||||
it 'sends the command' do
|
||||
expect(docker_client).to receive(:send_command).with(command, kind_of(Docker::Container)).and_return({})
|
||||
allow(docker_client).to receive(:send_command).with(command, kind_of(Docker::Container)).and_return({})
|
||||
execute_arbitrary_command
|
||||
end
|
||||
|
||||
@@ -222,7 +220,7 @@ describe DockerClient, docker: true do
|
||||
let(:result) { {status: 'ok', stdout: 42} }
|
||||
|
||||
before do
|
||||
expect(docker_client).to receive(:send_command).and_raise(error).and_return(result)
|
||||
allow(docker_client).to receive(:send_command).and_raise(error).and_return(result)
|
||||
end
|
||||
|
||||
it 'retries to execute the command' do
|
||||
@@ -232,13 +230,13 @@ describe DockerClient, docker: true do
|
||||
|
||||
context 'when no retries are left' do
|
||||
before do
|
||||
expect(docker_client).to receive(:send_command).exactly(DockerClient::RETRY_COUNT + 1).times.and_raise(error)
|
||||
allow(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)
|
||||
# TODO: Retries is disabled
|
||||
expect { execute_arbitrary_command }.to raise_error(error)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -250,12 +248,10 @@ describe DockerClient, docker: true do
|
||||
after { docker_client.send(:execute_run_command, submission, filename) }
|
||||
|
||||
it 'takes a container from the pool' do
|
||||
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')
|
||||
expect(docker_client).to receive(:create_workspace_files)
|
||||
end
|
||||
|
||||
@@ -281,7 +277,7 @@ describe DockerClient, docker: true do
|
||||
|
||||
it 'executes the test command' do
|
||||
expect(submission.execution_environment).to receive(:test_command).and_call_original
|
||||
expect(docker_client).to receive(:send_command).with(kind_of(String), kind_of(Docker::Container)).and_return({})
|
||||
allow(docker_client).to receive(:send_command).with(kind_of(String), kind_of(Docker::Container)).and_return({})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -305,7 +301,7 @@ describe DockerClient, docker: true do
|
||||
end
|
||||
|
||||
context 'with incomplete configuration' do
|
||||
before { expect(described_class).to receive(:config).at_least(:once).and_return({}) }
|
||||
before { allow(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)
|
||||
@@ -357,7 +353,7 @@ describe DockerClient, docker: true do
|
||||
end
|
||||
|
||||
describe '#send_command' do
|
||||
let(:block) { proc {} }
|
||||
let(:block) { proc { nil } }
|
||||
let(:container) { described_class.create_container(execution_environment) }
|
||||
let(:send_command) { docker_client.send(:send_command, command, container, &block) }
|
||||
|
||||
@@ -379,8 +375,13 @@ describe DockerClient, docker: true do
|
||||
|
||||
context 'when a timeout occurs' do
|
||||
before do
|
||||
expect(container).to receive(:exec).once.and_raise(Timeout::Error)
|
||||
expect(container).to receive(:exec).twice.and_return([[], []])
|
||||
exec_called = 0
|
||||
allow(container).to receive(:exec) do
|
||||
exec_called += 1
|
||||
raise Timeout::Error if exec_called == 1
|
||||
|
||||
[[], []]
|
||||
end
|
||||
end
|
||||
|
||||
it 'destroys the container asynchronously' do
|
||||
@@ -410,5 +411,3 @@ describe DockerClient, docker: true do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:enable RSpec/MultipleMemoizedHelpers
|
||||
|
@@ -11,7 +11,7 @@ describe DockerContainerMixin do
|
||||
end
|
||||
|
||||
it 'returns the correct information' do
|
||||
expect(CONTAINER).to receive(:json).and_return('HostConfig' => {'Binds' => binds})
|
||||
allow(CONTAINER).to receive(:json).and_return('HostConfig' => {'Binds' => binds})
|
||||
expect(CONTAINER.binds).to eq(binds)
|
||||
end
|
||||
end
|
||||
@@ -25,7 +25,7 @@ describe DockerContainerMixin do
|
||||
end
|
||||
|
||||
it 'returns the correct information' do
|
||||
expect(CONTAINER).to receive(:json).and_return('HostConfig' => {'PortBindings' => port_bindings})
|
||||
allow(CONTAINER).to receive(:json).and_return('HostConfig' => {'PortBindings' => port_bindings})
|
||||
expect(CONTAINER.port_bindings).to eq(port => port)
|
||||
end
|
||||
end
|
||||
|
@@ -8,8 +8,8 @@ describe FileTree do
|
||||
describe '#file_icon' do
|
||||
let(:file_icon) { file_tree.send(:file_icon, file) }
|
||||
|
||||
context 'for a media file' do
|
||||
context 'for an audio file' do
|
||||
context 'with a media file' do
|
||||
context 'with an audio file' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_mp3)) }
|
||||
|
||||
it 'is an audio file icon' do
|
||||
@@ -17,7 +17,7 @@ describe FileTree do
|
||||
end
|
||||
end
|
||||
|
||||
context 'for an image file' do
|
||||
context 'with an image file' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_jpg)) }
|
||||
|
||||
it 'is an image file icon' do
|
||||
@@ -25,7 +25,7 @@ describe FileTree do
|
||||
end
|
||||
end
|
||||
|
||||
context 'for a video file' do
|
||||
context 'with a video file' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_mp4)) }
|
||||
|
||||
it 'is a video file icon' do
|
||||
@@ -34,8 +34,8 @@ describe FileTree do
|
||||
end
|
||||
end
|
||||
|
||||
context 'for other files' do
|
||||
context 'for a read-only file' do
|
||||
context 'with other files' do
|
||||
context 'with a read-only file' do
|
||||
let(:file) { FactoryBot.build(:file, read_only: true) }
|
||||
|
||||
it 'is a lock icon' do
|
||||
@@ -43,7 +43,7 @@ describe FileTree do
|
||||
end
|
||||
end
|
||||
|
||||
context 'for an executable file' do
|
||||
context 'with an executable file' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_py)) }
|
||||
|
||||
it 'is a code file icon' do
|
||||
@@ -51,7 +51,7 @@ describe FileTree do
|
||||
end
|
||||
end
|
||||
|
||||
context 'for a renderable file' do
|
||||
context 'with a renderable file' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_svg)) }
|
||||
|
||||
it 'is a text file icon' do
|
||||
@@ -59,7 +59,7 @@ describe FileTree do
|
||||
end
|
||||
end
|
||||
|
||||
context 'for all other files' do
|
||||
context 'with all other files' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_md)) }
|
||||
|
||||
it 'is a generic file icon' do
|
||||
@@ -100,7 +100,7 @@ describe FileTree do
|
||||
let!(:leaf) { root.add(Tree::TreeNode.new('', file)) }
|
||||
let(:root) { Tree::TreeNode.new('', file) }
|
||||
|
||||
context 'for a leaf node' do
|
||||
context 'with a leaf node' do
|
||||
let(:node) { leaf }
|
||||
|
||||
it 'produces the required attributes' do
|
||||
@@ -116,7 +116,7 @@ describe FileTree do
|
||||
end
|
||||
end
|
||||
|
||||
context 'for a non-leaf node' do
|
||||
context 'with a non-leaf node' do
|
||||
let(:node) { root }
|
||||
|
||||
it "traverses the node's children" do
|
||||
@@ -144,7 +144,7 @@ describe FileTree do
|
||||
let(:node_icon) { file_tree.send(:node_icon, node) }
|
||||
let(:root) { Tree::TreeNode.new('') }
|
||||
|
||||
context 'for the root node' do
|
||||
context 'with the root node' do
|
||||
let(:node) { root }
|
||||
|
||||
it 'is a folder icon' do
|
||||
@@ -152,7 +152,7 @@ describe FileTree do
|
||||
end
|
||||
end
|
||||
|
||||
context 'for leaf nodes' do
|
||||
context 'with leaf nodes' do
|
||||
let(:node) { root.add(Tree::TreeNode.new('')) }
|
||||
|
||||
it 'is a file icon' do
|
||||
@@ -161,7 +161,7 @@ describe FileTree do
|
||||
end
|
||||
end
|
||||
|
||||
context 'for intermediary nodes' do
|
||||
context 'with intermediary nodes' do
|
||||
let(:node) do
|
||||
root.add(Tree::TreeNode.new('').tap {|node| node.add(Tree::TreeNode.new('')) })
|
||||
end
|
||||
|
@@ -27,7 +27,7 @@ describe TestingFrameworkAdapterGenerator do
|
||||
|
||||
it 'builds a correct class skeleton' do
|
||||
file_content = File.new(path, 'r').read
|
||||
expect(file_content).to start_with("class #{name}Adapter < TestingFrameworkAdapter")
|
||||
expect(file_content&.strip).to start_with("class #{name}Adapter < TestingFrameworkAdapter")
|
||||
end
|
||||
|
||||
it 'generates a corresponding test' do
|
||||
|
@@ -5,6 +5,10 @@ require 'rails_helper'
|
||||
describe NonceStore do
|
||||
let(:nonce) { SecureRandom.hex }
|
||||
|
||||
before do
|
||||
stub_const('Lti::MAXIMUM_SESSION_AGE', 1)
|
||||
end
|
||||
|
||||
describe '.add' do
|
||||
it 'stores a nonce in the cache' do
|
||||
expect(Rails.cache).to receive(:write)
|
||||
@@ -28,8 +32,6 @@ describe NonceStore do
|
||||
end
|
||||
|
||||
it 'returns false for expired nonces' do
|
||||
Lti.send(:remove_const, 'MAXIMUM_SESSION_AGE')
|
||||
Lti::MAXIMUM_SESSION_AGE = 1
|
||||
described_class.add(nonce)
|
||||
expect(described_class.has?(nonce)).to be true
|
||||
sleep(Lti::MAXIMUM_SESSION_AGE)
|
||||
|
@@ -42,7 +42,7 @@ describe TestingFrameworkAdapter do
|
||||
|
||||
describe '#test_outcome' do
|
||||
it 'calls the framework-specific implementation' do
|
||||
expect(adapter).to receive(:parse_output).and_return(count: count, failed: failed, passed: passed)
|
||||
allow(adapter).to receive(:parse_output).and_return(count: count, failed: failed, passed: passed)
|
||||
adapter.test_outcome('')
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user