-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Style guide #28
Comments
I'm happy to contribute to this because I think there's a need. For example, on Friday the topic of recommended RSpec style came up in a discussion at work. Someone pointed to http://betterspecs.org/, obviously having googled, and I recalled that @JonRowe had, some time ago, told me that the RSpec core team had disagreed with some of what the folks behind http://betterspecs.org/ were recommending. I agree that the guide should be brief. |
I definitely want the new site to expand to include more resources (I know @cupakromer has some ideas here) and I can see a style guide being part of that. My primary beef with betterspecs.org (and where I'd want us to do better) is that it presents things in a binary good/bad format without discussion of the tradeoffs involved of one over the other. It also seems to encourage users to use as many RSpec features as possible (with guidelines like "use subject", "use let and let!", "use contexts", "shared examples", etc) and while every RSpec feature has its place, I believe it's generally better to use fewer, simpler features until a situation warrants using the more advanced features. I also have a bit of a concern that an official style guide could be used to silence discussion ("the rspec team recommends this, end of story, let's move on...") and I don't want that. (If anything, I want it to foster discussion due to discussing the pros/cons and various things). This is a lower priority to me than the blog (which I have partially working locally, but haven't pushed yet) and the docs (which I think @JonRowe is working on?) which are the things I was hoping to have in place before launching the site in tandem with RSpec 3.2. I expect this to come sometime later. |
We've briefly discussed with @JonRowe, and those are some takeaways: https://rspec.rubystyle.guide/, "community RSpec style guide", "unofficial RSpec style guide" is a good starting point. It absorbed the useful parts of unmaintained betterspecs, and modernized them. Other interesting guides worth mentioning: https://about.lessonly.engineering/styleguide/testing/ and https://github.com/thoughtbot/guides/tree/master/best-practices#testing The unofficial RSpec style guide strives to be in harmony with I and Jon both agreed with Myron that guidelines should be less insisting and present the choice and implications of the options.
I see two options to approach the official RSpec style guide:
The amendments to the unofficial style guideJon proposed:
# bad
describe Article
# good
RSpec.describe "Article" It's a sane default, it will fit the community style guide quite well.
# bad
subject { … }
# good
subject(:name) { … }
#bad
subject(:name) { … }
let(:name) { … }
let(:name) { … }
#good
let(:name) { … }
let(:name) { … }
subject(:name) { … }
# bad
specify { … }
# good
it "does something" do
end
From me (mostly gathered from RSpec repos' discussions, Effective testing with RSpec 3, and RSpec source code comments):
# bad
subject { -> { perform } }
it { is_expected.to change { User.count } } The definitive list of things I'd personally love to update in the community guide https://github.com/rubocop-hq/rspec-style-guide/issues |
Ouhao 🙌🏻. Super happy to see this discussion. I am completely in favor of this. I love both options but I have a little preference for:
|
One guideline to add is to avoid stubbing Ruby core classes, as this may result in weird and hard to track down errors. We have |
It'd be nice for the RSpec website to include a brief "recommended" style guide, it's something that's been talked about before and occasionally pops up in discussion (today's via twitter). I know betterspecs.org exists but in the past we've disagreed over what constitutes "better" and I think it'd be nice to have a short synopsis of what we think are good practises to follow.
/cc @keithpitty
The text was updated successfully, but these errors were encountered: