diff --git a/spec/controllers/execution_environments_controller_spec.rb b/spec/controllers/execution_environments_controller_spec.rb index dfaa24e9..b6787c67 100644 --- a/spec/controllers/execution_environments_controller_spec.rb +++ b/spec/controllers/execution_environments_controller_spec.rb @@ -225,8 +225,6 @@ describe ExecutionEnvironmentsController do let(:runner_management_config) { {runner_management: {enabled: true, strategy: :poseidon}} } before do - # Ensure to reset the memorized helper - Runner.instance_variable_set :@strategy_class, nil allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) allow(codeocean_config).to receive(:read).and_return(runner_management_config) end diff --git a/spec/lib/runner/strategy/poseidon_spec.rb b/spec/lib/runner/strategy/poseidon_spec.rb index ee7bcd03..9b37910f 100644 --- a/spec/lib/runner/strategy/poseidon_spec.rb +++ b/spec/lib/runner/strategy/poseidon_spec.rb @@ -13,8 +13,6 @@ describe Runner::Strategy::Poseidon do let(:runner_management_config) { {runner_management: {enabled: true, strategy: :poseidon, url: 'https://runners.example.org', unused_runner_expiration_time: 180}} } before do - # Ensure to reset the memorized helper - Runner.instance_variable_set :@strategy_class, nil allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) allow(codeocean_config).to receive(:read).and_return(runner_management_config) end diff --git a/spec/models/runner_spec.rb b/spec/models/runner_spec.rb index 79cafce4..af3dd8f7 100644 --- a/spec/models/runner_spec.rb +++ b/spec/models/runner_spec.rb @@ -34,8 +34,6 @@ describe Runner do let(:runner_management_config) { {runner_management: {enabled: true, strategy:}} } before do - # Ensure to reset the memorized helper - described_class.instance_variable_set :@strategy_class, nil allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) allow(codeocean_config).to receive(:read).and_return(runner_management_config) end diff --git a/spec/support/runner.rb b/spec/support/runner.rb new file mode 100644 index 00000000..008f1547 --- /dev/null +++ b/spec/support/runner.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +def reset_runner_strategy + Runner.instance_variable_set :@strategy_class, nil + Runner.instance_variable_set :@management_active, nil +end + +RSpec.configure do |config| + # When starting the application, the environment is initialized with the default runner strategy: + # `Runner.strategy_class.initialize_environment` is called in `config/application.rb`. + config.before(:suite) do + reset_runner_strategy + end + + # After each test, we reset the memorized runner strategy to the default (similar to the database cleaner). + config.append_after do + reset_runner_strategy + end +end