data-migrate icon indicating copy to clipboard operation
data-migrate copied to clipboard

Feature: Add Rails generator and rake task support for creating data migration test coverage

Open joshmfrankel opened this issue 1 year ago • 2 comments

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_enabled which conditionally creates associated tests files upon rails 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_framework which can be set to :minitest or :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! 💎

joshmfrankel avatar Dec 12 '24 00:12 joshmfrankel

Just recycled all proposed changes / suggestions. Much simpler implementation while preserving the ability to generate test files alongside migrations 🚀

joshmfrankel avatar Sep 11 '25 15:09 joshmfrankel

I've made several updates in the latest commit: https://github.com/ilyakatz/data-migrate/pull/355/commits/b74b7f96fc188a73acee60d75e3c980d77352133

joshmfrankel avatar Sep 29 '25 13:09 joshmfrankel