How do I write a Rake task to run specs in multiple Rails apps?

Hi everyone

I’ve got an app consisting solely of Rails engines (implementing a component-based architectural design).

I’m trying to write a Rake task to run tests across all of them in my wrapper app.

Here’s the kind of thing I have for my other projects, which allow me to run RSpec unit specs and Cucumber features independently so that failures don’t cause either one to stop running:

desc "Run all test suites"
task :test do
  ENV["SPEC_OPTS"] = "--format progress"
  ENV["CUCUMBER_OPTS"] = ENV["SPEC_OPTS"]

  %w(spec:units cucumber).each do |task_name|
    run_independently(task_name)
  end
  puts "Finished running all test suites"
end

Rake::Task["default"].clear
task default: "spec:units"

def run_independently(task_name)
  sh "rake #{task_name}" do
    # Do nothing if a suite fails, allowing us to see the results for all of
    # them, even if some of the suites have failing tests
  end
end

I’ve been trying to adapt this to suit my new use case, but I keep having issues with Bundler not finding the rspec task.

Any ideas would be awesome!

Do you perhaps need to run rake #{task_name} via Bundler ?

Each component has its own Rakefile with its default task set to run all specs, so I was hoping to be able to cd to each component directory and run rake.