- Avoid the
privatekeyword in specs. - Avoid checking boolean equality directly. Instead, write predicate methods and use appropriate matchers. Example.
- Prefer
eqto==in RSpec. - Separate setup, exercise, verification, and teardown phases with newlines.
- Use RSpec's
expectsyntax. - Use RSpec's
allowsyntax for method stubs. - Use
not_toinstead ofto_notin RSpec expectations. - Prefer the
have_cssmatcher to thehave_selectormatcher in Capybara assertions.
- Avoid scenario titles that add no information, such as "successfully."
- Avoid scenario titles that repeat the feature title.
- Place helper methods for feature specs directly in a top-level
Featuresmodule. - Use Capybara's
feature/scenarioDSL. - Use names like
ROLE_ACTION_spec.rb, such asuser_changes_password_spec.rb, for feature spec file names. - Use only one
featureblock per feature spec file. - Use scenario titles that describe the success and failure paths.
- Use spec/features directory to store feature specs.
- Use spec/support/features for support code related to feature specs.
- Order
factories.rbcontents: sequences, traits, factory definitions. - Order factory attributes: implicit attributes, explicit attributes, child factory definitions. Each section's attributes are alphabetical.
- Order factory definitions alphabetically by factory name.
- Use one factories.rb file per project.
- Don't prefix
itblock descriptions withshould. Use Imperative mood instead. - Use
subjectblocks to define objects for use in one-line specs. Example. - Put one-liner specs at the beginning of the outer
describeblocks. - Use
.methodto describe class methods and#methodto describe instance methods. - Use
contextto describe testing preconditions. - Use
describe '#method_name'to group tests by method-under-test - Use a single, top-level
describe ClassNameblock. - Order validation, association, and method tests in the same order that they appear in the class.