A simple gem that allow developers using minitest to specify tags for their classes and tests, and run their test suite based on these tags.
This gem should be framework agnostic, let me know if you encounter any problems running this within the framework of your choice.
Add this line to your application's Gemfile:
gem 'minitag'
Or install it yourself as:
$ gem install minitag
We can tag specific classes or tests with one or more tags.
It is important to point out that tags associated with a class or test have no concept of being inclusive or exclusive. This distinction is only valid for tag filters.
class MyTest < Minitest::Test
# Every test within this class will inherit this tag
tag_namespace 'my_namespace_tag'
# Only the test below will have this tag
tag 'my_tag', 'another_tag'
def test_hello_minitest
# ...
end
end
We can now run our test suite with specific tags:
$ bundle exec rake test --tag 'unit'
or even multiple tags:
$ bundle exec rake test --tag 'unit' --tag 'services' --tag '~model'
Tag filters can be:
inclusive
exclusive
with the~
prefix:
# Only run tests that are tagged with 'unit'
$ bundle exec rake test --tag 'unit'
# Only run tests that are NOT tagged with 'unit'
$ bundle exec rake test --tag '~unit'
# Only run tests that are tagged with 'unit' and are NOT 'parallel'
$ bundle exec rake test --tag 'unit' --tag '~parallel'
Yes. Found any problems? Please open an issue or reach out to me.
For the most part yes, but tagging describe
blocks are not supported.
- When there's a need to split a test suite into different CI steps.
- During development, it's helpful to have extra flexibility when running a big test suite.
- When there are tests that you want to run only occasionality. For example, tests that perform network calls or have expensive side effects.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/bernardoamc/minitag. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Minitag project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.