File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -247,10 +247,41 @@ A developer should be able to view any `it` block in isolation --without its
247247DSL methods, it's probably fine.
248248
249249- Avoid ` let ` , and ` subject ` (prefer factory methods)
250+ - Omit parenthesis with ` #to ` and ` #not_to `
251+
252+ ``` rb
253+ # Good
254+ expect(x).to eq(y)
255+
256+ # Bad, interrupts the English "to equal" phrase
257+ expect(x).to(eq(y))
258+
259+ # Bad, doesn't always parse correctly
260+ expect(x).to eq y
261+ ```
262+
250263- Place ` describe ` within the namespace(s) for inner classes
251264- Prefer ` expect ` syntax when possible
265+ - Prefer predicate matchers when it reads well
266+
267+ ``` rb
268+ # Good
269+ expect(config).to be_valid_for_analysis
270+
271+ # Bad
272+ expect(config.valid_for_analysis?).to be true
273+
274+ # But sometimes required
275+ expect(presenter.show_the_thing?).to be true
276+
277+ # Because this doesn't work
278+ expect(presenter).to be_show_the_thing
279+ ```
280+
252281- Prefer spies to mocks when possible (mocks put assertion before action)
253282- Test only one thing per example in unit specs
283+ - Use ` match_array ` when order doesn't matter
284+ - Use ` not_to ` (not ` to_not ` , which creates a split-infinitive)
254285- Use a nested ` describe ` for each method (named as ` "#foo" ` , or ` ".foo" ` )
255286- Write 4-phase tests with whitespace separating each phase
256287
You can’t perform that action at this time.
0 commit comments