Introduction

Role models are important.

— Officer Alex J. Murphy / RoboCop

This Capybara style guide outlines the recommended best practices for real-world programmers to write code that can be maintained by other real-world programmers.

RuboCop, a static code analyzer (linter) and formatter, has a rubocop-capybara extension, provides a way to enforce the rules outlined in this guide.

You can generate a PDF copy of this guide using AsciiDoctor PDF, and an HTML copy with AsciiDoctor using the following commands:

# Generates README.pdf
asciidoctor-pdf -a allow-uri-read README.adoc

# Generates README.html
asciidoctor README.adoc
Tip

Install the rouge gem to get nice syntax highlighting in the generated document.

gem install rouge

A Living Document

This guide is work in progress - trying to fill in the arguments by which the rubocop-capbyara cops were written so that users can understand the tradeoffs on different approaches (whether to configure, enable or disable different cops) and understand where it’s a question of consistency and/or style, or are there other issues at play.

Using Capybara

(corresponds to Capybara/ClickLinkOrButtonStyle)

But if you do use a generic click then use a consistent method

(also corresponds to Capybara/ClickLinkOrButtonStyle)

Don’t set expectations on Capybara current_path

(corresponds to Capybara/CurrentPathExpectation)

Don’t use deprecated style methods

(corresponds to Capybara/MatchStyle)

Be concise: don’t use redundant withins

(corresponds to Capybara/RedundantWithinFind)

Using Capybara with RSpec

Use have_css or have_xpath instead of have_selector

(corresponds to Capybara/RSpec/HaveSelector)

Prefer using predicate matcher over using predicate method directly

(corresponds to Capybara/RSpec/PredicateMatcher)

Contributing

Nothing written in this guide is set in stone. Everyone is welcome to contribute, so that we could ultimately create a resource that will be beneficial to the entire Ruby community.

Feel free to open tickets or send pull requests with improvements. Thanks in advance for your help!

You can also support the project (and RuboCop) with financial contributions via Patreon.

How to Contribute?

It’s easy, just follow the contribution guidelines below:

License

Credit

TBC!