other.nvim
other.nvim copied to clipboard
[Feature] Add test patterns to default rails mappings
First of; many thanks for this plugin, I'm so glad that I have discovered this! I used to use the AltN8 plugin when I was on Intellij. Now that I'm back on (Neo)Vim again full-time this is a plugin that I've been missing!
For the feature request;
It would be great to have built-in mappings for a test
context for rails as well.
I have the following mappings below that lets you me from test
to src
in a rails app using Minitest. I'm sure some of the rules e.g. unit
ones could be expressed with fewer entries, but I wanted to make sure that I really get the expected files.
Maybe these could be a starter/inspiration for adding mappings for test files to the plugin built-in rails mappings. As another popular testing framework for Rails is rspec with different paths, maybe the plugin could provide two built-in mappings for the user to chose: "rails-minitest"
& "rails-rspec"
.
-- custom mappings: rails src->test
{
pattern = "/app/models/(.*).rb",
target = "/test/unit/models/%1_test.rb",
context = "test"
},
{
pattern = "/app/controllers/(.*).rb",
target = "/test/integration/%1_test.rb",
context = "test"
},
{
pattern = "/app/controllers/(.*).rb",
target = "/test/functional/%1_test.rb",
context = "test"
},
{
pattern = "/app/controllers/(.*).rb",
target = "/test/unit/controllers/%1_test.rb",
context = "test"
},
{
pattern = "/app/channels/(.*).rb",
target = "/test/channels/%1_test.rb",
context = "test"
},
{
pattern = "/app/mailers/(.*).rb",
target = "/test/unit/mailers/%1_test.rb",
context = "test"
},
{
pattern = "/app/serializers/(.*).rb",
target = "/test/unit/serializers/%1_test.rb",
context = "test"
},
{
pattern = "/app/services/(.*).rb",
target = "/test/unit/services/%1_test.rb",
context = "test"
},
{
pattern = "/app/workers/(.*).rb",
target = "/test/unit/workers/%1_test.rb",
context = "test"
},
{
pattern = "/lib/(.*).rb",
target = "/test/unit/lib/%1_test.rb",
context = "test"
},
-- custom mappings: rails test->src
{
pattern = "/test/unit/models/(.*)_test.rb",
target = "/app/models/%1.rb",
context = "src"
},
{
pattern = "/test/integration/(.*)_test.rb",
target = "/app/controllers/%1.rb",
context = "src"
},
{
pattern = "/test/functional/(.*)_test.rb",
target = "/app/controllers/%1.rb",
context = "src"
},
{
pattern = "/test/unit/controllers/(.*)_test.rb",
target = "/app/controllers/%1.rb",
context = "src"
},
{
pattern = "/test/channels/(.*)_test.rb",
target = "/app/channels/%1.rb",
context = "src"
},
{
pattern = "/test/unit/mailers/(.*)_test.rb",
target = "/app/mailers/%1.rb",
context = "src"
},
{
pattern = "/test/unit/serializers/(.*)_test.rb",
target = "/app/serializers/%1.rb",
context = "src"
},
{
pattern = "/test/unit/services/(.*)_test.rb",
target = "/app/services/%1.rb",
context = "src"
},
{
pattern = "/test/unit/workers/(.*)_test.rb",
target = "/app/workers/%1.rb",
context = "src"
},
{
pattern = "/test/unit/lib/(.*)_test.rb",
target = "/lib/%1.rb",
context = "src"
},
Thanks for the kind words! Sometimes I am still surprised that people besides myself actually use the plugin 😄
Also thank you for the mappings you suggest - I like to add them. The only thing is, as I am not a rails developer myself I would like to write some tests along with it to make sure everything works as expected.
For that I would need some info for the typical rails-app structure and specifically for the directory structure using rails-minitest
and optimally also rails-rspec
.
Maybe you can provide the info here in the issue, or even better you could add a pull-request and create a dummy file structure under lua/spec/fixtures
along with a version of lua/other-nvim/builtin/mappings.lua
containing your mappings.
That way we could work together on getting this integrated. Thanks again for contributing!
It's an awesome plugin, I wish I had known about it earlier. Many thanks for creating it!
Some more info below:
References on recommended test file naming convention:
- Minitest:
_test
suffix https://github.com/rubocop/minitest-style-guide#file-naming - RSpec:
_spec
suffix https://github.com/rubocop/rspec-style-guide#view-spec-file-name
Example repos of the file structure:
- Minitest: https://github.com/awesome/minitest-rails-example
- RSpec: https://github.com/eliotsykes/rspec-rails-examples
I've created a collaborative pr at #16
Implemented with #16