Skip to main content

The MHCLG Way and its content is intended for internal use by the MHCLG community.

Ruby style guide

Code formatting

The GOV.UK programme publishes and maintains a gem, rubocop-govuk, which provides linting rules for Ruby projects. We have adopted this gem for use at MHCLG. These rules extend those described in rubystyle.guide.

rubocop-govuk also includes rules for Rake, RSpec and Ruby on Rails. The RSpec and Rails rules extend the respective styleguides, rspec.rubystyle.guide and rails.rubystyle.guide, where only rules that have proved problematic have been overridden.

Conventional tooling

The recommended tool for managing multiple Ruby installations is rbenv. For dependency management bundler should be used.

For small web applications, we advise using the Sinatra DSL due to its ease of use and extensibility.

For larger web applications, consider using Ruby on Rails, which enforces consistent organisation with its conventions.

Choose the Puma webserver for production use - it is fast and concurrent, unlike the default WEBrick.

Testing with RSpec

For testing, the RSpec framework is the conventional and preferred choice. RSpec provides an expressive syntax that lends itself to producing readable tests. For testing functionality from a user’s perspective it is preferred to implement tests in RSpec rather than adopt an abstraction such as Cucumber, this is due to us finding it easier to maintain tests where the definition and implementation are in the same file.

This page was last reviewed on 28 July 2025. It needs to be reviewed again on 28 July 2026 by the page owner #mhclg-way .