Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let :A edit requests spec #368

Open
sebastianhoitz opened this issue Nov 25, 2014 · 16 comments
Open

Let :A edit requests spec #368

sebastianhoitz opened this issue Nov 25, 2014 · 16 comments

Comments

@sebastianhoitz
Copy link

I have a controller that does not have controller unit tests but request integration tests.

When I am inside the controller I would like to be able to press :A to open the request test file. But instead it tries to open the controller unit test.

@tpope
Copy link
Owner

tpope commented Nov 25, 2014

Do request tests map cleanly to controllers?

@sebastianhoitz
Copy link
Author

Yes.

app/controllers/v1/users_controller.rb => spec/requests/v1/users_controller.rb

@tpope
Copy link
Owner

tpope commented Nov 26, 2014

Uh are you sure you didn't screw that up?

@sebastianhoitz
Copy link
Author

Sorry, I meant spec/requests/v1/users_controller.rb

@tpope
Copy link
Owner

tpope commented Nov 27, 2014

So the name of the spec doesn't have _spec in it?

@teoljungberg
Copy link
Contributor

Brining this issue back to life.

They usually map app/controllers/api/v1/users_controller.rb => spec/requests/api/v1/users_spec.rb

@tpope
Copy link
Owner

tpope commented May 7, 2015

@teoljungberg can you cite an OSS project or 2 that does this?

@teoljungberg
Copy link
Contributor

@tpope not from the top of my head. I've seen it in a few client projects though

@teoljungberg
Copy link
Contributor

Here's a projection I use to resolve this issue (for those interested).

let g:rails_projections = {
      \  "app/controllers/*_controller.rb": {
      \      "test": [
      \        "spec/requests/{}_spec.rb",
      \        "spec/controllers/{}_controller_spec.rb",
      \        "test/controllers/{}_controller_test.rb"
      \      ],
      \      "alternate": [
      \        "spec/requests/{}_spec.rb",
      \        "spec/controllers/{}_controller_spec.rb",
      \        "test/controllers/{}_controller_test.rb"
      \      ],
      \   },
      \   "spec/requests/*_spec.rb": {
      \      "command": "request",
      \      "alternate": "app/controllers/{}_controller.rb",
      \      "template": "require 'rails_helper'\n\n" .
      \        "RSpec.describe '{}' do\nend",
      \   },
      \ }

@jasonkarns
Copy link

FWIW, rspec-rails follows this convention.

Request specs are marked by :type => :request or if you have set
config.infer_spec_type_from_file_location! by placing them in spec/requests.

https://relishapp.com/rspec/rspec-rails/v/3-7/docs/request-specs/request-spec

@tpope
Copy link
Owner

tpope commented Mar 29, 2018

Seems irrelevant to a filename conversation but ok.

@eloyesp
Copy link

eloyesp commented Jul 10, 2019

It seems that there is no alternate defined on the request spec file so going from spec to controller does not work.

nickcharlton added a commit to nickcharlton/dotfiles that referenced this issue Oct 11, 2019
This also supports feature and system tests, by defining projections.

tpope/vim-rails#368 (comment)
@AaronRustad
Copy link

When using @teoljungberg rails projections placed in config/projections.json, I'm presented with the following error opening vim. I assume this has to do with non-standard(?)/unexpected JSON format and perhaps pre-processing of the file? Would anybody be able to provide pointers as to where I should be looking to ensure that the file is correctly used? I assume there must be something wrong with my environment.

Error detected while processing function rails#buffer_setup[14]..<SNR>47_BufProjectionCommands[14]..<SNR>47_app_commands[2]..<SNR>47_app_projections[37]..rails#json_parse:
line    3:
E474: Invalid argument
Press ENTER or type command to continue
Error detected while processing function rails#buffer_setup[14]..<SNR>47_BufProjectionCommands:
line   14:
E170: Missing :endfor

@eloyesp
Copy link

eloyesp commented May 20, 2020

It seems that requests specs are generated by default now by rspec-rails and the convention seems to be:

app/controllers/users_controller.rb => spec/requests/users_spec.rb
app/controllers/admin/users_controller.rb => spec/requests/admin/users_spec.rb

As far as I understand, it seems that requests specs should be first in the alternate list.

@heraldofsolace
Copy link

@eloyesp That seems like what is created when you generate a scaffold. When you generate a controller, it seems to be using a different format

app/controllers/some_controller.rb => spec/requests/some_request_spec.rb

@benoittgt
Copy link

The same can be done for rake tasks with RSpec.

let g:rails_projections = {
      \  'lib/tasks/*.rake': {
      \    'alternate': 'spec/lib/tasks/{}_spec.rb'
      \   },
      \  'spec/lib/tasks/*_spec.rb': {
      \     'alternate': 'lib/tasks/{}.rake'
      \   }
      \}

ShawnAukstak added a commit to ShawnAukstak/dotfiles that referenced this issue Jun 3, 2021
Adds support for rspec `requests/` default directory naming in addition
to `controllers/` and `intergration/`.

Based on tpope/vim-rails#368 (comment)
djpowers added a commit to djpowers/dotfiles that referenced this issue Dec 19, 2022
Enables using `alternate` and `test` between Rails controller files and
associated RSpec request specs.

Based on tpope/vim-rails#368 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants