-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add the ability to run specs filtered by tags #217
base: master
Are you sure you want to change the base?
Conversation
This commit adds two functions: rspec-verify-tagged and rspec-verify-all-tagged, that prompt the user for one or more tags following the rspec syntax and appends them to the rspec command. See https://rspec.info/features/3-12/rspec-core/command-line/tag/
Hi! Filtering by tags should indeed be a useful addition. Thanks. Before I merge this, though, have you considered the following alterations:
|
This commit: - Renames functions from `-tagged` to `verify-tags-*` -- this avoids confusion in dired mode with dired `-tagged` functions, and is clearer too, imho - Saves previous tags to `rspec-tags-history` - Persists `rspec-tags-history` to savehist if `savehist-mode` is on - Adds `C-c , g` prefix for all tag function keymaps (`t` clashes with current keymap)
Thanks for taking the time to review this, and thanks for your input, which I believe improves the PR. 🙏 I don't think I want to go for 1. I feel it is too slow indeed, when coding / running tests, I want commands to be straightforward and get out of the way, so I decided to go for 2. So I have added a I also decided to rename functions from I finally added the |
"Run the specified spec, or the spec file for the current buffer, filtered by one or multiple tags." | ||
(interactive) | ||
(rspec--autosave-buffer-maybe) | ||
(let* ((tags-string (completing-read-multiple "Select tags (separated by comma): " rspec-tags-history)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to use the history variable as the HIST argument in completing-read-multiple
. It's the argument number 6. Doing that would automatically add the selected input to history as well (so rspec-add-tags-to-history
won't be needed, I think).
I guess you could pass rspec-tags-history
as TABLE
and 'rspec-tags-history
(quoted) as the history variable, so both saving to history works, and completion works as well.
"Run the `spec' rake task for the project of the current file, filtered by one or multiple tags." | ||
(interactive) | ||
(let* ((tags-string (completing-read-multiple "Select tags (separated by comma): " rspec-tags-history)) | ||
(tags-list (if (stringp tags-string) (split-string tags-string ",\\s-*") tags-string))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docstring, completing-read-multiple
always returns a list. So (stringp tags-string)
should always be nil, and tags-string
can be renamed to tags
.
(let* ((tags-string (completing-read-multiple "Select tags (separated by comma): " rspec-tags-history)) | ||
(tags-list (if (stringp tags-string) (split-string tags-string ",\\s-*") tags-string))) | ||
(rspec-add-tags-to-history tags-list) | ||
(rspec-compile (dired-get-marked-files) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a way to make this shorter: change the value of rspec-command-options
locally (in the let
form) and then call the "base" function. Like this:
(defun rspec-dired-verify-tags-single ()
"Run marked specs or spec at point, filtered by one or multiple tags (works with directories too)."
(interactive)
(let* ((tags (completing-read-multiple "Select tags (separated by comma): " rspec-tags-history))
(rspec-command-options (concat rspec-command-options
" "
(mapconcat (lambda (tag) (format " --tag %s" tag)) tags " "))))
(rspec-dired-verify-single)))
Same with the other commands.
This PR proposes to add the ability to run specs filtered by tag(s).
It adds four functions:
rspec-verify-tagged
: only verify the tag(s) in the current filerspec-verify-all-tagged
: only verify the tag(s) in the whole suiterspec-dired-verify-tagged
: only verify the tag(s) in the current dired scoperspec-dired-verify-single-tagged
: only verify the tag(s) in the currently marked filesIt also adds the corresponding key bindings
The functions prompt the user for one or more tags following the rspec syntax and appends them to the rspec command.
See https://rspec.info/features/3-12/rspec-core/command-line/tag/