-
Notifications
You must be signed in to change notification settings - Fork 14
rb_minitest test wrapper helper #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@noahkawasakigoogle In my projects, I don't pass |
Unfortunately, Minitest just doesn't have that type of "magic" built in with any sort of test runner CLI tooling, its just barebones ruby CLI execution. Rake tasks + minitest makes this type of stuff possible, but minitest alone cannot do it. And using rake tasks with bazel just doesnt make sense, because Bazel should be the layer at which all the srcs/deps declarations are set for best caching behavior. Luckily it's pretty easy to wrap in pure ruby, here are among the resources I dug through to figure this out.
|
Would you be up to open a PR adding this? |
Additional details discussed in bazel-contrib/rules_ruby#233 and bazel-contrib/rules_ruby#223 Restoring tests revealed latent bug in JRuby's `RubyMessage#convert` that was exposed by the introduction `test_to_hash` while tests were not running; fix included. Closes #21733 COPYBARA_INTEGRATE_REVIEW=#21733 from protocolbuffers:fix_rb_test 3f8418f PiperOrigin-RevId: 758470283
Additional details discussed in bazel-contrib/rules_ruby#233 and bazel-contrib/rules_ruby#223 Restoring tests revealed latent bug in JRuby's `RubyMessage#convert` that was exposed by the introduction `test_to_hash` while tests were not running; fix included. Closes #21733 COPYBARA_INTEGRATE_REVIEW=#21733 from protocolbuffers:fix_rb_test 3f8418f PiperOrigin-RevId: 758470283
) Additional details discussed in bazel-contrib/rules_ruby#233 and bazel-contrib/rules_ruby#223 Restoring tests revealed latent bug in JRuby's `RubyMessage#convert` that was exposed by the introduction `test_to_hash` while tests were not running; fix included. Closes protocolbuffers#21733 COPYBARA_INTEGRATE_REVIEW=protocolbuffers#21733 from protocolbuffers:fix_rb_test 3f8418f PiperOrigin-RevId: 758470283
Just wanted to contribute how I've gotten minitest to work well with rules_ruby in case others also need to use minitest.
The current rb_test() rule works well for RSpec, which supports glob syntax for test file inputs as well as multiple arguments: https://stackoverflow.com/questions/48778373/how-to-run-multiple-specific-rspec-tests
Suppose this is our test directory:
This will run both test files with rspec.
Unfortunately minitest (Ruby's default test framework) has zero glob support nor the ability to run multiple files as arguments.
This target will run
ruby spec/test_file.rb spec/another_test_file.rb
however, the second argument will be ignored and left out completely. Onlyspec/test_file.rb
will actually execute.Here is a minitest wrapper that works well with Bazel glob syntax and providing multiple test files to a single target:
BUILD.bazel example:
A few things to note:
-I.
to the ruby execution adds.
to the $LOAD_PATH, meaning the root of the bazel workspace. For this reason its good to change allrequire
statements to use absolute paths for all ruby imports besides (external gems from the bundle repo).test_files
abstracts away the need to provide both srcs and args, which typically will be the same exact file set but with different string values. srcs will be relative file paths from the package path, while args will be full paths from the root of the repo.The text was updated successfully, but these errors were encountered: