Break out testing library from ActiveSupport?

I followed down the path of why my app was bringing in ‘minitest’ in production and noticed that activesupport has a dependency on minitest. I wondered why it wasn’t a development dependency and then it dawned on me that it was necessary for ActiveSupport::TestCase.

What does the core team think about breaking the testing-related stuff out of activesupport into a separate gem? It would eliminate the dependency on minitest and could load (probably a trival amount) of less code for production Rails apps. Is this a good idea and a worthwhile thing for me to spend some time on? Is this much more work than I think it might be?

Thanks in advance!

Brian

Hi Brian,

I think to we start to consider doing this we will need a stronger reason than load less code for production Rails apps. AFAIK, we don’t require active_support/test_case in production environment so we are not loading minitest at production too.

If that is the case we should fix this, but I don’t think we need to extract a new library.

Minitest is already in the standard library, so you're not really
adding or removing any meaningful dependence.

I just found this thread after noticing the same dependency today and looking for a way to potentially remove this. I don’t quite see a dependency on minitest in the ‘standard library’ (by which I assume you mean the Rails gem itself). https://github.com/rails/rails/blob/master/rails.gemspec Or is there another dependency I’m missing?

As far as I can tell we would need to not autoload test_case.rb and then wrap the ‘require’ call to give a more meaningful error. It’s not clear to me if we expect consumers of the gem to use the ActiveSupport::TestCase class, or is that purely for testing the library itself? I don’t see any explicit examples for it in the documentation, but I’m also not that familiar with MiniTest.

Minitest is already in the standard library, so you’re not really
adding or removing any meaningful dependence.

I just found this thread after noticing the same dependency today and looking for a way to potentially remove this. I don’t quite see a dependency on minitest in the ‘standard library’ (by which I assume you mean the Rails gem itself). https://github.com/rails/rails/blob/master/rails.gemspec Or is there another dependency I’m missing?

When Steve wrote that sentence three+ years ago, minitest was still included as part of the Ruby standard library. It was removed in 2.2 - see this discussion for more details:

https://bugs.ruby-lang.org/issues/9711

As far as I can tell we would need to not autoload test_case.rb and then wrap the ‘require’ call to give a more meaningful error. It’s not clear to me if we expect consumers of the gem to use the ActiveSupport::TestCase class, or is that purely for testing the library itself? I don’t see any explicit examples for it in the documentation, but I’m also not that familiar with MiniTest.

ActiveSupport::TestCase can be used directly (see the example in the guides: http://guides.rubyonrails.org/testing.html#rails-meets-minitest ). The minitest plumbing is also used by Rspec (in at least some cases):

https://github.com/rspec/rspec-rails/blob/e8054a1cd03044f725030fe8315952cf3799a395/lib/rspec/rails/adapters.rb#L22

I’ll reiterate Rafael’s point from earlier in the thread: why is removing this dependency important?

—Matt Jones