I have some tests located in an engine called "Blorgh". I simply test my engine by running the following command in the root directory of my engine's repository.
rails test
...
19 runs, 8 assertions, 0 failures, 0 errors, 11 skips
Simple. Now, Blorgh is mounted in an app.
gem blorgh
This app is deployed using a pipeline that includes a test step. I want the test step to execute the mounted engine's tests so that the pipeline stops deployment if it finds a problem with the tests in the Blorgh engine.
The problem is that when rails test
is executed in the root directory of the host app, it only looks for tests specific to the host app.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
How can I execute the tests for my Blorgh engine when it is mounted? I've searched high and low. I'm willing to make my own task by crawling Blorgh::Engine.root
, but I'm not even sure what rails test
is doing under the hood.
You can set up a rake task to load just the necessary tests. Main app test directory should be in your load path, because test/test_helper.rb loads the environment:
A quick test:
Use
RAILS_ENV=test
, otherwise, it's loading test environment twice, causing fixtures to load twice as well.https://github.com/rails/rails/blob/v7.0.2.3/railties/lib/rails/commands/test/test_command.rb#L29
https://github.com/rails/rails/blob/v7.0.2.3/railties/lib/rails/test_unit/runner.rb#L39