Adds Rake tasks for testing packs using minitest.
Add the gem to your Gemfile
:
bundle add packs-rails-minitest --group development,test
Once installed, this gem provides the following Rake tasks:
packs:test:prepare
- ran before the next three taskspacks:test
- runs all tests in all packs except system testspacks:test:system
- runs all system tests in all packspacks:test:all
- runs all tests in all packs including system tests
For each pack, the following tasks are also added:
packs:test:<pack name>:prepare
- ran before the next three tasks (and as part ofpacks:test:prepare
)packs:test:<pack name>
- runs all tests in the pack except system testspacks:test:<pack name>:system
- runs all system tests in the packpacks:test:<pack name>:all
- runs all tests in the pack including system tests
rails test
and similar are defined using Thor, meaning they cannot be easily overridden by Rake tasks. There are two
ways to overcome this:
- Set the environment variables
DEFAULT_TEST
andDEFAULT_TEST_EXCLUDE
to appropriate globs - Create new Rake tasks and use
rake test
instead ofrails test
(recommended)
The environment variables should be set to values returned by the following Ruby code:
Variable | Ruby |
---|---|
DEFAULT_TEST | "{.,#{Packs.all.map(&:relative_path).join(",")}}/test/**/*_test.rb" |
DEFAULT_TEST_EXCLUDE | "{.,#{Packs.all.map(&:relative_path).join(",")}}/test/{system,dummy}/**/*_test.rb" |
How you set this up is up to you, there isn't really a standard place. In application.rb
or boot.rb
work, just make
sure you only set it if it is not already set, otherwise the Rake tasks defined in this package may not work.
You'll also need to make sure the prepare tasks are run as part of test:prepare
, e.g.:
Rake::Task["test:prepare"].enhance(["packs:test:prepare"])
Appropriate Rake tasks will be defined for you by setting config.packs_rails_minitest.override_tasks = true
in
your application.rb
. If you only include this gem in specific environments you will need to set it conditionally e.g.
config.packs_rails_minitest.override_tasks = true if Rails.env.development? || Rails.env.test?
Remember that you must use rake test
instead of rails test
for this to work.
Contributions are welcome, simply create a pull request or file an issue.
The gem is available as open source under the terms of the MIT License.