Fix 17 previously failing specs

This commit is contained in:
Felix Auringer
2021-06-08 12:36:49 +02:00
committed by Sebastian Serth
parent 0280c0282e
commit cf58be97ee
8 changed files with 66 additions and 71 deletions

View File

@ -2,36 +2,34 @@
require 'rails_helper'
class Controller < AnonymousController
include SubmissionScoring
end
# This is broken since the Runner was added.
describe SubmissionScoring, skip: true do
let(:controller) { Controller.new }
describe SubmissionScoring do
let(:submission) { FactoryBot.create(:submission, cause: 'submit') }
before do
controller.instance_variable_set(:@current_user, FactoryBot.create(:external_user))
controller.instance_variable_set(:@_params, {})
end
describe '#collect_test_results' do
after { controller.send(:collect_test_results, submission) }
let(:runner) { FactoryBot.create :runner }
before do
allow(Runner).to receive(:for).and_return(runner)
allow(runner).to receive(:copy_files)
allow(runner).to receive(:execute_interactively).and_return(1.0)
end
after { submission.calculate_score }
it 'executes every teacher-defined test file' do
allow(submission).to receive(:score_submission)
submission.collect_files.select(&:teacher_defined_assessment?).each do |file|
allow(controller).to receive(:execute_test_file).with(file, submission).and_return({})
allow(submission).to receive(:test_result).with(any_args, file).and_return({})
end
end
it 'scores the submission' do
allow(submission).to receive(:score_submission).and_return([])
end
end
describe '#score_submission', cleaning_strategy: :truncation do
after { controller.score_submission(submission) }
it 'collects the test results' do
allow(controller).to receive(:collect_test_results).and_return([])
end
after { submission.score_submission([]) }
it 'assigns a score to the submissions' do
expect(submission).to receive(:update).with(score: anything)

View File

@ -236,17 +236,35 @@ describe ExercisesController do
expect_template(:statistics)
end
# This is broken since the Runner was added.
describe 'POST #submit', skip: true do
describe 'POST #submit' do
let(:output) { {} }
let(:perform_request) { post :submit, format: :json, params: {id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id}} }
let(:user) { FactoryBot.create(:external_user) }
let(:scoring_response) do
[{
status: 'ok',
stdout: '',
stderr: '',
waiting_for_container_time: 0,
container_execution_time: 0,
file_role: 'teacher_defined_test',
count: 1,
failed: 0,
error_messages: [],
passed: 1,
score: 1.0,
filename: 'index.html_spec.rb',
message: 'Well done.',
weight: 2.0,
}]
end
before do
FactoryBot.create(:lti_parameter, external_user: user, exercise: exercise)
allow_any_instance_of(Submission).to receive(:normalized_score).and_return(1)
allow(controller).to receive(:collect_test_results).and_return([{score: 1, weight: 1}])
allow(controller).to receive(:score_submission).and_call_original
submission = FactoryBot.build(:submission, exercise: exercise, user: user)
allow(submission).to receive(:normalized_score).and_return(1)
allow(submission).to receive(:calculate_score).and_return(JSON.dump(scoring_response))
allow(Submission).to receive(:create).and_return(submission)
end
context 'when LTI outcomes are supported' do

View File

@ -94,10 +94,9 @@ describe 'Editor', js: true do
end
it 'contains a button for submitting the exercise' do
# This is broken since the Runner was added.
skip
allow_any_instance_of(SubmissionsController).to receive(:score_submission).and_return(scoring_response)
submission = FactoryBot.build(:submission, user: user, exercise: exercise)
allow(submission).to receive(:calculate_score).and_return(JSON.dump(scoring_response))
allow(Submission).to receive(:find).and_return(submission)
click_button(I18n.t('exercises.editor.score'))
expect(page).not_to have_css('#submit_outdated')
expect(page).to have_css('#submit')