From 8f446c04a9e44bd943aacf7bbe28fc76f5f4c135 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 31 Jul 2023 08:39:14 +0200 Subject: [PATCH] Fix Rubocop offenses --- spec/controllers/exercises_controller_spec.rb | 4 +--- spec/controllers/internal_users_controller_spec.rb | 6 ++---- spec/controllers/sessions_controller_spec.rb | 6 ++---- spec/helpers/yaml_spec.rb | 4 +--- spec/models/execution_environment_spec.rb | 3 +-- spec/models/runner_spec.rb | 9 +++------ 6 files changed, 10 insertions(+), 22 deletions(-) diff --git a/spec/controllers/exercises_controller_spec.rb b/spec/controllers/exercises_controller_spec.rb index c3feaa38..9cc5b0a5 100644 --- a/spec/controllers/exercises_controller_spec.rb +++ b/spec/controllers/exercises_controller_spec.rb @@ -314,9 +314,7 @@ describe ExercisesController do before do create(:lti_parameter, external_user: user, exercise:) submission = build(:submission, exercise:, user:) - allow(submission).to receive(:normalized_score).and_return(1) - allow(submission).to receive(:calculate_score).and_return(scoring_response) - allow(submission).to receive(:redirect_to_feedback?).and_return(false) + allow(submission).to receive_messages(normalized_score: 1, calculate_score: scoring_response, redirect_to_feedback?: false) allow(Submission).to receive(:create).and_return(submission) end diff --git a/spec/controllers/internal_users_controller_spec.rb b/spec/controllers/internal_users_controller_spec.rb index d928f523..589d02ff 100644 --- a/spec/controllers/internal_users_controller_spec.rb +++ b/spec/controllers/internal_users_controller_spec.rb @@ -178,9 +178,8 @@ describe InternalUsersController do describe 'GET #forgot_password' do context 'when no user is logged in' do before do - allow(controller).to receive(:set_sentry_context).and_return(nil) + allow(controller).to receive_messages(set_sentry_context: nil, current_user: nil) - allow(controller).to receive(:current_user).and_return(nil) get :forgot_password end @@ -190,9 +189,8 @@ describe InternalUsersController do context 'when a user is already logged in' do before do - allow(controller).to receive(:set_sentry_context).and_return(nil) + allow(controller).to receive_messages(set_sentry_context: nil, current_user: user) - allow(controller).to receive(:current_user).and_return(user) get :forgot_password end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 4212ccb5..cf727914 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -227,9 +227,8 @@ describe SessionsController do describe 'GET #new' do context 'when no user is logged in' do before do - allow(controller).to receive(:set_sentry_context).and_return(nil) + allow(controller).to receive_messages(set_sentry_context: nil, current_user: nil) - allow(controller).to receive(:current_user).and_return(nil) get :new end @@ -239,9 +238,8 @@ describe SessionsController do context 'when a user is already logged in' do before do - allow(controller).to receive(:set_sentry_context).and_return(nil) + allow(controller).to receive_messages(set_sentry_context: nil, current_user: build(:teacher)) - allow(controller).to receive(:current_user).and_return(build(:teacher)) get :new end diff --git a/spec/helpers/yaml_spec.rb b/spec/helpers/yaml_spec.rb index 1abd544e..90632c05 100644 --- a/spec/helpers/yaml_spec.rb +++ b/spec/helpers/yaml_spec.rb @@ -9,10 +9,8 @@ describe 'yaml config files' do next unless /.*.\.yml/.match?(path) before do - allow(Rails).to receive(:root).and_return(Pathname.new('/tmp')) - app = instance_double Rails::Application - allow(Rails).to receive(:application).and_return app + allow(Rails).to receive_messages(root: Pathname.new('/tmp'), application: app) allow(app).to receive(:credentials).and_return({}) end diff --git a/spec/models/execution_environment_spec.rb b/spec/models/execution_environment_spec.rb index 636cd61f..cb607827 100644 --- a/spec/models/execution_environment_spec.rb +++ b/spec/models/execution_environment_spec.rb @@ -6,8 +6,7 @@ describe ExecutionEnvironment do let(:execution_environment) { described_class.create.tap {|execution_environment| execution_environment.update(network_enabled: nil, privileged_execution: nil) } } it 'validates that the Docker image works' do - allow(execution_environment).to receive(:validate_docker_image?).and_return(true) - allow(execution_environment).to receive(:working_docker_image?).and_return(true) + allow(execution_environment).to receive_messages(validate_docker_image?: true, working_docker_image?: true) execution_environment.update(build(:ruby).attributes) expect(execution_environment).to have_received(:working_docker_image?) end diff --git a/spec/models/runner_spec.rb b/spec/models/runner_spec.rb index af3dd8f7..646d246c 100644 --- a/spec/models/runner_spec.rb +++ b/spec/models/runner_spec.rb @@ -56,8 +56,7 @@ describe Runner do let(:runner) { described_class.create } before do - allow(strategy_class).to receive(:request_from_management).and_return(runner_id) - allow(strategy_class).to receive(:new).and_return(strategy) + allow(strategy_class).to receive_messages(request_from_management: runner_id, new: strategy) end it 'delegates to its strategy' do @@ -73,8 +72,7 @@ describe Runner do let(:connection) { instance_double(Runner::Connection) } before do - allow(strategy_class).to receive(:request_from_management).and_return(runner_id) - allow(strategy_class).to receive(:new).and_return(strategy) + allow(strategy_class).to receive_messages(request_from_management: runner_id, new: strategy) allow(event_loop).to receive(:wait) allow(connection).to receive(:error).and_return(nil) allow(Runner::EventLoop).to receive(:new).and_return(event_loop) @@ -128,8 +126,7 @@ describe Runner do let(:runner) { described_class.create } before do - allow(strategy_class).to receive(:request_from_management).and_return(runner_id) - allow(strategy_class).to receive(:new).and_return(strategy) + allow(strategy_class).to receive_messages(request_from_management: runner_id, new: strategy) end it 'delegates to its strategy' do