From bc7e36d68592536113a75717d18b5b514b080604 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 2 Aug 2024 10:34:25 +0200 Subject: [PATCH] CI: Tests failed with undefined Rake --- lib/railsless_rake_task_runner.rb | 46 ++++++++++++++++--------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/railsless_rake_task_runner.rb b/lib/railsless_rake_task_runner.rb index a1f17a72..94aae135 100644 --- a/lib/railsless_rake_task_runner.rb +++ b/lib/railsless_rake_task_runner.rb @@ -10,35 +10,37 @@ def self.load_rails end end -# Try to run no-rails tasks first. Fallback to rails if none is found. -Rake.application.instance_eval do - module Rake - class Task - alias :old_lookup_prerequisite :lookup_prerequisite +if defined?(Rake) + # Try to run no-rails tasks first. Fallback to rails if none is found. + Rake.application.instance_eval do + module Rake + class Task + alias :old_lookup_prerequisite :lookup_prerequisite - def lookup_prerequisite(prerequisite_name) - if prerequisite_name == "environment" && !Rake.application.lookup(prerequisite_name) - RailslessRakeTaskRunner.load_rails + def lookup_prerequisite(prerequisite_name) + if prerequisite_name == "environment" && !Rake.application.lookup(prerequisite_name) + RailslessRakeTaskRunner.load_rails + end + old_lookup_prerequisite(prerequisite_name) end - old_lookup_prerequisite(prerequisite_name) end end - end - def top_level - if running_a_task? && requested_tasks_exist? - super - else - RailslessRakeTaskRunner.load_rails - super + def top_level + if running_a_task? && requested_tasks_exist? + super + else + RailslessRakeTaskRunner.load_rails + super + end end - end - def running_a_task? - !(options.show_tasks || options.show_prereqs) - end + def running_a_task? + !(options.show_tasks || options.show_prereqs) + end - def requested_tasks_exist? - top_level_tasks.any? { |task| lookup(task) } + def requested_tasks_exist? + top_level_tasks.any? { |task| lookup(task) } + end end end