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
Introduce Rspec/DescribeMethodFormat Cop #601
Conversation
Ensure that describe method name starts from hash for instance methods or dot for class methods.
Seems legit 👍 I'm curious whether you think this cop should complain or accept "sentences" as description strings? describe SomeClass do
describe 'the happy path' do
# ...
end
describe 'the way it works when things go wrong' do
# ...
end
end Thanks! |
it turns out DescribeMethod only covers the second argument of a describe |
👍 |
@Darhazer, re:
I think this cop should just be a configuration option for In favor of having a mechanism to enforce this though 👍 |
Thanks a lot for your feedback, everyone! I was operating under the SRP principle, but if you see that it fits into |
@Darhazer / @bquorning - Do you agree with my reasoning above? I think two cops would result in a worse / more confusing user experience, but if you think differently I'd be interested to hear what you think and why. |
@dgollahon I agree. I even thought that’s what DescribeMethod is handling |
What about the case that @mikegee asks about above, where I think merging the two cops makes sense, but it would be nice to still pass a sentence to |
@bquorning @mikegee What if I add two options instead:
My specific use case is to disallow pretty much anything except describe on methods and constants, so I'm happy as long as there is a way to turn sentences mode off. |
Personally, I very rarely use @bquorning Just out of curiosity, do you have any examples of how you would use
How would another option for allowing sentences be different from disabling the cop entirely? |
Truthfully, I'd use |
@dgollahon as earlier mentioned my use-case involves only strict
My thinking on sentences would purely be something simple: if there is just one word - make sure it is method name prefixed with I'm equally agree with e2e tests where you can't apply same set of rules due to their different nature. |
That sounds like a good rule of thumb, but I would be hesitant to enforce that as a rule for all users of rubocop-rspec. I don’t think that’s how most people use
That sounds reasonable, but I think there will be many false positives. |
What is the problem of providing this option disabled by default and allow people to enable it? |
Yeah, I'm sure it's not uniform for most RSpec users, though helping make things uniform is kind of the point of
I personally don't see any. What about extending the existing logic on the top level
If @bquorning is right and most people use |
We had @JonRowe from the RSpec team chime in on #226 (comment) and #228, warning that “rubocop tends to give the impression that something is "recommended best practise"”. Can we link to anyone (blog post, documentation, repositories) besides ourselves (me included, 70% of the time) saying that the suggested style is a “recommended best practise”? Even the RSpec repositories frequently use
|
BetterSpecs is not endorsed by the RSpec team. They do several things we think of as anti-patterns and have historically not been interested in any input. My 2¢ here is that this:
Is the best way to describe a class and its methods as unit specs, the |
@JonRowe, IMO if it works for them then they "don't have to" accept input. Also, if they have several things that are considered anti-pattern not necessarily mean they can't have something valuable we can use. What do you say? I'm just starting with Ruby, so I'm not aware of all lower level details and so if describe as a string for top level class node is preferred I'm totally supportive of that. What you say I think, you are in favour of having method-based |
@filakhtov If you're promoting a resource for writing better anything of course you have to accept input, as there is no golden standard but a process for improving what we do, things change :) When was the last time anyone accepted "works for me" as an acceptable metric for production code :p Method based describes are useful for unit level specs, I wouldn't recommend them for integration level. Again theres no one best practise here, its a process for figuring out what describes what you want to test best. |
Three quotes from betterspecs/betterspecs#2:
So, from the betterspecs discussion it doesn’t sound like there’s 100% agreement. I would say that |
@bquorning in my code provided it is disabled by default. And it was this way from the very beginning, because I know that people do all sorts of things to @JonRowe I have mixed feelings about this and it gets a bit philosophical at this stage, because it is "better" than no standard or recommendation at all and they don't claim it to be the "best". Back to the topic however, how would one tell Rubocop that certain spec file is a unit and therefore this rule should be applied vs this spec is an integration test? Is there even a way? I would think it will just be exclude pattern in configuration file, but again, my knowledge of Ruby/RSpec here isn't up to the scratch, so I'm open for suggestions. |
Rspec/DescribeMethodFormat
Ensure that describe method name starts from hash for instance methods or dot for class methods.
This Cop is disabled by default, so that backwards compatibility is preserved.
This Cop ignores root level
describe
blocks and blocks that use constants.Following: http://www.betterspecs.org/#describe
Bad:
Good:
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
.