Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Code Quality Matters in Rails

DZone's Guide to

Code Quality Matters in Rails

This might seem like an obvious statement, but more devs don't use tools to check their code's quality than you would think. Read on for a brief discussion.

· Web Dev Zone ·
Free Resource

Jumpstart your Angular applications with Indigo.Design, a unified platform for visual design, UX prototyping, code generation, and app development.

Alarmingly, 23% of participants in our 2018 Ruby on Rails survey reported not using any of the tools to check code quality.

Thankfully, 67% use Rubocop. Rubocop is a real gem (pun intended). It’s more than a style guide check. It also ensures all developers working on a project use the same set of guidelines for metrics like assignment branch condition (ABC) size to prohibit methods from getting too complex. Running Rubocop on a feature branch before submitting a PR is a great asset for new team members who are becoming acclimated to your team’s conventions.

Simplecov measures how well your tests are covering your code base. We defined "good" coverage as 80%, but many strive for higher. Looking at your overall coverage provided in the default Simplecov console output after tests are run is only part of the story.

Your tests could return an 85% test coverage score, but when you look at the breakdown, only 60% of the code in your models are actually getting tested. You can always set up your CI to measure the groupings (model, controllers, etc.) separately.

Rubocop and Simplecov are both great tools, but worthless if developers aren’t running them after they commit code. Using continuous integration (CI) services ensures this doesn’t happen. CI services like Circle CIJenkins, and Travis CI will run Rubcocop and Ssimplecov against code pushed to the repository and alert the team when code fails the checks configured for Rubocop or test coverage slips below the desired percentage.

From the 2018 Rails Survey, 75% of developers reported using some CI service in their development cycle. This is a promising number, but it could always be better – we think it’s key to a healthy, maintainable application. When a team uses code quality tools a healthier codebase is sure to result.

Take a look at the Indigo.Design sample applications to learn more about how apps are created with design to code software.

Topics:
high quality source code ,ruby on rails ,web dev ,code quality ,code coverage

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}