Feature: Add Rails generator and rake task support for creating data migration test coverage
Why
Implements: https://github.com/ilyakatz/data-migrate/issues/148
I recently needed well-factored test coverage for a complex data migration, so I thought I'd take an attempt at implementing test suite support for both RSpec and Minitest.
What
- Adds new Config setting
config.test_generator_enabledwhich conditionally creates associated tests files uponrails g data_migration add_this_to_that. (Default: false) - Adds basic support for inferring test suite based on available helper file
- Adds new config setting
config.test_generator_frameworkwhich can be set to:minitestor:rspec
Notes
I read the comment here: https://github.com/ilyakatz/data-migrate/pull/162#issuecomment-745586543 regarding using Rails.configuration.generators.options[:rails]. That returns a very clear: Rails.configuration.generators.options[:rails][:test_framework] #=> :rspec. While testing Minitest and RSpec, I noticed that this comes from having the rspec-rails gem installed. It doesn't necessarily check for valid installation. I attempted a valid installation check by looking for the framework specific files test/test_helper.rb and spec/rails_helper.rb.
Resources
- https://github.com/ilyakatz/data-migrate/pull/162
Also, kudos on a great gem! 💎
Just recycled all proposed changes / suggestions. Much simpler implementation while preserving the ability to generate test files alongside migrations 🚀
I've made several updates in the latest commit: https://github.com/ilyakatz/data-migrate/pull/355/commits/b74b7f96fc188a73acee60d75e3c980d77352133