Test Locations in Rails 4

What do folks think about making changes to the default test locations? I would love to see the following changes made:

test/units -> test/models

test/units/helpers -> test/helpers

test/units/lib -> test/lib

test/functional -> test/controllers

test/functional -> test/mailers

test/integration -> test/acceptance

I’ve already done this in minitest-rails for Rails 3, but I thought I’d check here before creating a pull request for Rails 4.

Here is a blog I blogged on my blog explaining more about why I think this change is good.

http://blowmage.com/2012/07/12/rails-tests-placement

Thoughts?

~Mike

+0.5 :slight_smile:

I’m using minitest-rails on my newer projects and I liked the structure you picked. It makes it easy to add tests for things like serializers (test/serializers), commands, etc. I think this would be a more reasonable choice of naming for new projects. I just don’t know how this is going to impact existing projects and the rest of the ecosystem.

Godfrey

This is similar to rspec structure which I really like. I believe your proposal being less generic and better fitted to the rails use case is a very nice one.

One question though, where do routing tests go?

/test/routes

Yes, seems obvious. Just pointing that out. But the changes seem really nice and makes the placing of test files more obvious and semantic.

+1. I never saw the point of the existing naming scheme.

Hey Mike,

I'm personally in favor of what you've proposed. I'm starting a
discussion with other Rails core members about it.
In case we decide to accept the changes we should be keeping
compatibility with the old schema. Only new apps should be using this
and old apps should continue working. We can probably show a message
saying that there's a new directory schema for tests.
What do you think?. Will you be able to provide a patch for all that?.

Thank you very much for helping ;).

This is probably quite obvious, but I thought I’d point it out anyways. One big advantage of this schema is that there is a one-to-one corresponding between the content of the /app directory and the /test directory. This makes a lot of things very straightforward. For instance, when using guard to do automated testing, this is all you need in your Guardfile:

guard ‘minitest’, :rubygems => true do

watch(%r|^test/minitest_helper.rb$|) { “test” }

watch(%r|^test/(.*)_test.rb$|)

watch(%r|^app/(.*).rb$|) { |m| “test/#{m[1]}_test.rb” }

end

Also, this probably should be configurable, or at least query-able so other plugins/gems/generators can figure where things should be placed in.

Godfrey

Hey Mike,

Hey Santiago.

I'm personally in favor of what you've proposed. I'm starting a
discussion with other Rails core members about it.
In case we decide to accept the changes we should be keeping
compatibility with the old schema. Only new apps should be using this
and old apps should continue working. We can probably show a message
saying that there's a new directory schema for tests.
What do you think?. Will you be able to provide a patch for all that?.

Yep. The minitest-rails project has similar goals and is intended to
live side-by-side with existing tests. The biggest issue is the rake
tasks, but its certainly doable.

Mike,

We decided to do this for Rails 4.

Can you go ahead and provide a Pull Request?.

Mention me on it and I will merge.

Thanks again for putting all this ideas and for minitest-rails :slight_smile:

Awesome. Will do. Thanks!

Hey guys,

Is anyone already working on this task? If not, I would like to do it myself.

Francesco.

I'm working on it. Will submit a pull request "soon". :wink:

FYI: https://github.com/rails/rails/pull/7878