Last Updated: February 25, 2016
·
797
· hopsoft

Test multiple local Rails engines together

If you're using multiple Rails engines to develop a complex modular app, it can be irritating to run your tests.

We keep our local engines under the lib directory so Code Climate will see & analyze them.

lib/engines/engine1
lib/engines/engine2
lib/engines/engine3

We've added a rake task to help run tests across all of them.

# lib/tasks/test.rake
namespace :test do

  desc "Tests engines under lib/engines"
  task :engines, [:engine] => [:environment] do |t, args|
    puts "Testing engines".ljust(80, ".")
    paths = Dir.glob(File.join(Rails.root, "lib/engines/*"))

    paths.each do |path|
      next unless path.split("/").last == args[:engine] if args[:engine]
      commands = []
      commands << "cd #{path}"
      commands << "bundle exec rake"
      command = commands.join("; ")
      puts "\n#{command}\n\n"
      exit 1 unless system(command)
    end

    exit 0
  end

end

This enables us to test our engines like so.

rake test:engines
rake test:engines[engine1]