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
Encourage users to customize the permitted word list in RSpec/ContextWording
(was: Add before
and after
to default list)
#861
Conversation
Can you please provide a full example group for which 'before the record is saved' is a good title? Just for the reference, similar request: #757 We're trying to stick to https://rspec.rubystyle.guide/#context-descriptions (https://github.com/rubocop-hq/rspec-style-guide#context-descriptions) for defaults. |
Thanks for the pointers to other PRs. I've opened rubocop/rspec-style-guide#108 which seems like a better place for the discussion. An example where the suggested change improves readability. Suppose an application has a user creation flow with several stages:
A high-level behavioral spec may want to examine the situation at intermediate points in the process. describe 'User creation' do
context 'when the user has not yet confirmed their email address' do
end
context 'when the user has confirmed their email address' do
# alternatively, 'when an admin has not yet approved the user'
end
context 'when an admin has approved the user' do
end
end This is adequate, but it does not do a good job communicating the flow of time—The groups are not alternative states, but a sequence of states. Words like before and after let the descriptions convey that more naturally: describe 'User creation' do
context 'before the user confirms their email address' do
end
context 'after the user has confirmed their email address' do
# alternatively, 'before an admin approves the user'
end
context 'after an admin has approved the user' do
end
end |
Basing on the discussion in #757, and keeping in mind that:
do you think there's a way to suggest the users relax this cop in a way that lets them move forward with their style of choice without making it completely useless by default because it's too permissive? |
7b16ba3
to
aa7a998
Compare
In light of rubocop/rspec-style-guide#108, a documentation-only change to the ContextWording cop seems in order. Changes pushed to this PR. Context descriptions are written in freeform human language, so it is impossible to foresee all acceptable cases. This change adds text to the documentation encouraging users to configure the list of permitted prefixes to meet their needs. This change may also resolve #510. |
before
and after
to RSpec/ContextWording
default listRSpec/ContextWording
(was: Add before
and after
to default list)
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.
Looks good, thank you!
aa7a998
to
53a10c0
Compare
# the configuration to meet project needs. Other acceptable prefixes may | ||
# include `if`, `unless`, `for`, `before`, `after`, or `during`. | ||
# | ||
# @see https://rspec.rubystyle.guide/#context-descriptions | ||
# @see https://github.com/reachlocal/rspec-style-guide#context-descriptions |
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.
If you're up for making another correction, the namespace has changed from reachlocal
to rubocop-hq
.
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.
If it's the same content as https://rspec.rubystyle.guide, maybe it's better to have only one?
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.
Fair enough.
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 removed the github.com link, since the rubystyle.guide link has the same content in a better form. Changes pushed.
Context descriptions are written in freeform human language, so it is impossible to foresee all acceptable cases. Add text to the documentation encouraging users to configure the list of permitted prefixes to meet their needs. on-behalf-of: @Cofense <oss@cofense.com>
53a10c0
to
85536ea
Compare
Add
before
andafter
to theRSpec/ContextWording
default list. This allows for more expressive context descriptions.Example:
Also add items that are mentioned in the documentation but not included in the default config:
if
,unless
,for
.on-behalf-of: @Cofense oss@cofense.com
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml
.