rspec-style-guide
rspec-style-guide copied to clipboard
Best practices for writing your specs!
While still useful outside of Rails, Timecop has its downsides, one is that it's not thread-safe. [AS already has](https://api.rubyonrails.org/v5.2.1/classes/ActiveSupport/Testing/TimeHelpers.html) what Timecop provides, `freeze_time`, `travel`, `travel_back`, `travel_to`.
DatabaseCleaner was never meant to be used in Rails apps, and while still allowing the `truncation` and `deletion` strategies that some may find useful (I can't imagine in which cases...
1. `shared_context` is undeservedly omitted from the style guide, and it's sometimes extremely useful. 2. It makes sense to add another rule at the same time to describe the difference...
E.g. ``` matcher :be_just_like do |expected| match {|actual| actual == expected} end ``` Related docs: https://relishapp.com/rspec/rspec-expectations/v/3-8/docs/custom-matchers/define-a-custom-matcher#scoped-in-a-module https://relishapp.com/rspec/rspec-expectations/v/3-8/docs/custom-matchers/define-a-custom-matcher#scoped-in-an-example-group ## Caveats I personally find it very confusing that those matchers don't have...
The difference between the two is that the former creates a context, while the latter includes the examples and groups together with the context defined in the `shared_examples` that may...
Something like > specify works well for cases where each example has its own subject
Fixtures as something created before suite might be useful, specifically e.g. for a list of countries that are later used by other records (via say, `user.country_id` especially when there's a...
There is no information which style is preferred. 1) ```ruby let :user do build(:user, profile: profile).tap do |user| user.save validate: false end end let :user do build(:user, profile: profile).tap do...
There is no information which style is preferred. 1) ```ruby let :user do build(:user, profile: profile).tap do |user| user.save validate: false end end ``` or 2) ```ruby let(:user) do build(:user,...
I had an interesting discussion on a PR just now. Lately I've taken to using assignment to indicate things that won't change between tests: ```rb describe Something do # This...