Skip to main content

The GDS Way and its content is intended for internal use by the GDS and CO CDIO communities.

Ruby style guide

Code formatting

The GOV.UK programme publishes and maintains a gem, rubocop-govuk, which provides linting rules for Ruby projects. These rules extend those described in The rubocop-govuk project has overriden rules to either match GDS style precedence or to handle scenarios where rules were problematic to adopt.

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

Conventional tooling

GDS uses the MRI implementation of Ruby in projects. You should not adopt a different one (such as jRuby) for projects without clear justification. The recommended tool for managing multiple Ruby installations is rbenv. For dependendency management bundler should be used.

For web applications, the de facto approach is to use Ruby on Rails due to its stability, broad adoption and large community. For smaller web applications we have chosen Sinatra before - however this should be approached with caution as these can easily become large applications over time that are less conventionally organised than Rails applications.

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.

Further reading

This page was last reviewed on 13 January 2021. It needs to be reviewed again on 13 July 2021 by the page owner #gds-way .
This page was set to be reviewed before 13 July 2021 by the page owner #gds-way. This might mean the content is out of date.