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

Support for request specs in rspec-toggle-spec-and-target? #202

Open
powersurge360 opened this issue Jul 18, 2022 · 5 comments
Open

Support for request specs in rspec-toggle-spec-and-target? #202

powersurge360 opened this issue Jul 18, 2022 · 5 comments

Comments

@powersurge360
Copy link

powersurge360 commented Jul 18, 2022

Hello! I searched the source code and checked the documentation but I didn't see very much about request specs. Is there anyway to set rspec-toggle-spec-and-target to match something in spec/requests/{model-name}_spec.rb instead of spec/controllers/{model-name}_controller_spec.rb? Controller specs seem to be soft-deprecated and rspec stubs request specs instead of controller specs nowadays.

@powersurge360 powersurge360 changed the title Support for request specs? Support for request specs in rspec-toggle-test-and-target? Jul 18, 2022
@powersurge360 powersurge360 changed the title Support for request specs in rspec-toggle-test-and-target? Support for request specs in rspec-toggle-spec-and-target? Jul 18, 2022
@dgutov
Copy link
Collaborator

dgutov commented Jul 18, 2022

Hi!

Historically, I think, rspec specs never used a "fancy" naming scheme for directories. Unlike test-unit which is used with Rails by default.

And IIUC this didn't change. Looking at https://github.com/rspec/rspec-rails, it suggests specifying the spec type using the :type metadata. The recently merged new snippet desct allows you to have that value auto-filled.

@powersurge360
Copy link
Author

In the generators for controllers, it will generate a requests/{model-name}_spec.rb if the :request_specs option is set to true. There's a similar check for controllers but only :request_specs defaults to true.

On the official rspec blog back during the release of rspec 3.5, they mentioned that controller tests were soft deprecated in rails 5.

A relevant quote from that article:

For new Rails apps: we don't recommend adding the rails-controller-testing gem to your application. The official recommendation of the Rails team and the RSpec core team is to write request specs instead.

With these changes going back to rails 5 released back in 2016, I think it's pretty compelling to add at least an option to toggle to requests/ instead of controllers/ for this function. Folks working on rails apps after that time period are not likely to even have controller specs with the above deprecations and recommendations and project defaults.

@dgutov
Copy link
Collaborator

dgutov commented Jul 27, 2022

All right, then.

I suppose this will require some extra logic in rspec-spec-file-for and rspec-target-file-for.

Perhaps you'd like to try implementing that?

@powersurge360
Copy link
Author

powersurge360 commented Jul 29, 2022

Yea I can take a crack at it sometime! May take me a bit and it will be literally the first elisp I've written but I'll check it out sometime soon. I guess what I'd need to do is create a sort of special case for request specs because they, unlike most of the other conventions, don't map 1:1 with the file name and require a little massaging, right? Is there anything I ought to know or that you'd like to see to accept a PR?

@dgutov
Copy link
Collaborator

dgutov commented Jul 29, 2022

Things to know:

C-M-x re-evaluates a defun in the current session. So you can try out new changes right away.
C-u C-M-x instruments a defun for debugging.

And the functions that I mentioned in the previous message are most likely the only ones that need changing.

There are no "unusual" mappings supported by rspec-mode so far, so there is no existing setting or a list that can be added to.

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

2 participants