<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: hix.dev</title>
    <description>The latest articles on Forem by hix.dev (@hixdevs).</description>
    <link>https://forem.com/hixdevs</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F313598%2Fea874a16-1562-46b0-bc34-c49f63a23397.png</url>
      <title>Forem: hix.dev</title>
      <link>https://forem.com/hixdevs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hixdevs"/>
    <language>en</language>
    <item>
      <title>Ruby Environment Management 101</title>
      <dc:creator>hix.dev</dc:creator>
      <pubDate>Fri, 20 Mar 2020 12:40:17 +0000</pubDate>
      <link>https://forem.com/hixdevs/ruby-environment-management-101-1in5</link>
      <guid>https://forem.com/hixdevs/ruby-environment-management-101-1in5</guid>
      <description>&lt;p&gt;An automated Ruby environment management is necessary for developers to easily work on multiple Ruby programs on the same machine.&lt;/p&gt;

&lt;p&gt;You can read this whole article from our &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-environment-management/"&gt;original blog post&lt;/a&gt;. It's a bit prettier.&lt;/p&gt;

&lt;p&gt;In the Ruby community, there are two popular managers responsible for installing and maintaining multiple Ruby versions - &lt;a href="https://github.com/rvm/rvm"&gt;RVM&lt;/a&gt; and &lt;a href="https://github.com/rvm/rvm"&gt;Rbenv&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This tutorial will guide you on choosing the best one and configuring your own environment. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is Ruby Environment Management?
&lt;/h2&gt;

&lt;p&gt;If you are actively working on programs written in Ruby, at some point you are going to install multiple versions of the language on your system.&lt;/p&gt;

&lt;p&gt;Ruby environment managers such as RVM and Rbenv allow you to do just that.&lt;/p&gt;

&lt;p&gt;It is a generally accepted practice to include the .ruby-version file in the root of Ruby-written programs and applications, such as Ruby on Rails projects. The version file includes a specific Ruby version with which the program is supposed to work.&lt;/p&gt;

&lt;p&gt;'.ruby-version'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="mf"&gt;2.6&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both RVM and Rbenv respect the aforementioned Ruby version, and upon navigating to the root of Ruby program that includes the file, they inform you that a particular Ruby version has to be installed in case it is missing on your system.&lt;/p&gt;

&lt;h2&gt;
  
  
  RVM vs Rbenv - which Ruby Version Manager should I use?
&lt;/h2&gt;

&lt;p&gt;The short answer for developers is: it does not really matter, just pick one and be done with it - both RVM and Rbenv get the job done.&lt;/p&gt;

&lt;p&gt;The long answer is: it depends.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JW7PKydG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e9eucy4juy9zzld93d4o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JW7PKydG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e9eucy4juy9zzld93d4o.png" alt="Alt Text" width="670" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One factor in favor of Rbenv over RVM is that it receives more love on Github. But let's get to the facts.&lt;/p&gt;

&lt;p&gt;RVM pros over Rbenv:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RVM is easier to install than Rbenv,&lt;/li&gt;
&lt;li&gt;RVM has more features than Rbenv,&lt;/li&gt;
&lt;li&gt;RVM includes a built-in Ruby installation mechanism while Rbenv does not.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rbenv pros over RVM:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rbenv is lightweight, RVM is heavier,&lt;/li&gt;
&lt;li&gt;Rbenv is more developer-friendly than RVM,&lt;/li&gt;
&lt;li&gt;Rbenv has a dedicated plugin for Ruby installation mechanism, RVM has it built-in&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/rbenv/rbenv-installer"&gt;Rbenv main sell point is that its lightweight in comparison with RVM&lt;/a&gt;, while still providing just enough functionality for the Ruby development.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we definitely have not decided which one to use leaving this decision to you, follow the installation instructions of the Ruby environment manager of your choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  RVM installation
&lt;/h2&gt;

&lt;p&gt;Depending on your operating system, follow the instructions below in order to install the RVM Ruby Environment Manager.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ubuntu
&lt;/h3&gt;

&lt;p&gt;RVM has a dedicated package for Ubuntu. In order to use it, you are going to be able to add stuff to PPA.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;software-properties-common
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-add-repository &lt;span class="nt"&gt;-y&lt;/span&gt; ppa:rael-gc/rvm
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;rvm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is configuring the terminal to always perform login in order to always load the RVM.&lt;/p&gt;

&lt;p&gt;At the terminal window:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to Edit / Profile Preferences ,&lt;/li&gt;
&lt;li&gt;Go to the Title and Command tab,&lt;/li&gt;
&lt;li&gt;Check Run command as login shell&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The last step is to reboot your machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other operating systems
&lt;/h3&gt;

&lt;p&gt;In order to install RVM, you are going to need the following packages: curl and gpg2. After confirming their presence, simply run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-sSL&lt;/span&gt; https://get.rvm.io | bash &lt;span class="nt"&gt;-s&lt;/span&gt; stable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Confirm your installation running the &lt;code&gt;rvm install ruby&lt;/code&gt; command.&lt;/p&gt;

&lt;h2&gt;
  
  
  RVM overview
&lt;/h2&gt;

&lt;p&gt;As stated before, RVM has more features built-in that Rbenv does.&lt;/p&gt;

&lt;p&gt;In order to browse all the RVM commands, run either &lt;code&gt;rvm --help&lt;/code&gt; or &lt;code&gt;man rvm&lt;/code&gt; in your CLI.&lt;/p&gt;

&lt;p&gt;Basic command-line RVM usage can be boiled down to this set of commonly used commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;rvm install &amp;lt;version&amp;gt;&lt;/code&gt; installs given Ruby version on your system,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rvm remove &amp;lt;version&amp;gt;&lt;/code&gt; removes given Ruby version from your system,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rvm list&lt;/code&gt; lists all Ruby versions installed on your system,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rvm list known&lt;/code&gt; lists all available Ruby versions that you can install with rvm install command,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rvm current&lt;/code&gt; displays currently used Ruby version&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rvm use &amp;lt;version&amp;gt;&lt;/code&gt; changes the currently used Ruby version to the given one&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rvm use default &amp;lt;version&amp;gt;&lt;/code&gt; sets the Ruby version that your system uses by default&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The last two commands are useful to remember whenever you start the development of a new Ruby-written program. In most cases, it's best to use the latest stable version, which is always installable via the &lt;code&gt;rvm install ruby --latest&lt;/code&gt; command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rbenv installation
&lt;/h2&gt;

&lt;p&gt;Based on your operating system, follow the instructions below in order to install the Rbenv Ruby Environment Manager.&lt;/p&gt;

&lt;h3&gt;
  
  
  macOS
&lt;/h3&gt;

&lt;p&gt;Installing the Rbenv on macOS is really easy and can be done using Homebrew.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install rbenv
rbenv init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running the commands, close and open your terminal for changes to take effect.&lt;/p&gt;

&lt;p&gt;The Ruby installation plugin is included by default, so you can now install any Ruby version using the &lt;code&gt;rbenv install X.Y.Z&lt;/code&gt; command.&lt;/p&gt;

&lt;h3&gt;
  
  
  Linux
&lt;/h3&gt;

&lt;p&gt;In order to set up Rbenv on Debian based system, we are going to install all Ruby dependencies first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For OSs other than Debian, the same might be done using other system package managers.&lt;/p&gt;

&lt;p&gt;Next, we are going to clone the official Rbenv repository into the home directory and add its binary to &lt;code&gt;$PATH&lt;/code&gt; in order to use &lt;code&gt;rbenv&lt;/code&gt; command line utility.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/rbenv/rbenv.git ~/.rbenv
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'export PATH="$HOME/.rbenv/bin:$PATH"'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is to add the following command to your shell configuration file in order to load Rbenv automatically when the CLI starts.&lt;/p&gt;

&lt;p&gt;~/.zshrc or ~/.bashrc&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;rbenv init -&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last step is installing Ruby installation Rbenv plugin by simply cloning its official Github repository into the correct path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it, Rbenv is ready to use. You can install the latest stable Ruby version using the &lt;code&gt;rbenv install -l&lt;/code&gt; command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rbenv overview
&lt;/h2&gt;

&lt;p&gt;In order to use Rbenv via CLI, you need to have the aforementioned &lt;a href="https://github.com/rbenv/ruby-build"&gt;ruby-build&lt;/a&gt; command-line utility installed.&lt;/p&gt;

&lt;p&gt;In order to browse all the Rbenv commands available, run the &lt;code&gt;rbenv --help&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;There are basic Rbenv commands that you are going to use at some point of Ruby development:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;rbenv install &amp;lt;version&amp;gt;&lt;/code&gt; installs given Ruby version,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rbenv global &amp;lt;version&amp;gt;&lt;/code&gt; sets the default system Ruby version,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rbenv version&lt;/code&gt; displays the currently used Ruby version of your system,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rbenv install --list&lt;/code&gt; option lists all available versions of Ruby.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whenever you start to develop the new Ruby program, it is worth using the latest stable Ruby version, which you can easily install using the &lt;code&gt;rbenv install -l&lt;/code&gt; command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Ruby Environment Management is a must-have for every Ruby developer.&lt;/p&gt;

&lt;p&gt;Ruby community provides two very popular Ruby environment managers, Rbenv and RVM. Both of them are pretty easy to install and get the job done.&lt;/p&gt;

&lt;p&gt;If you have any questions, leave a comment!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>management</category>
    </item>
    <item>
      <title>Running your Rails projects with Redis - all you need to know</title>
      <dc:creator>hix.dev</dc:creator>
      <pubDate>Thu, 20 Feb 2020 13:39:19 +0000</pubDate>
      <link>https://forem.com/hixdevs/running-your-rails-projects-with-redis-all-you-need-to-know-360a</link>
      <guid>https://forem.com/hixdevs/running-your-rails-projects-with-redis-all-you-need-to-know-360a</guid>
      <description>&lt;p&gt;In this tutorial, we'll go step by step through Ruby on Rails Redis installation and configuration.&lt;/p&gt;

&lt;p&gt;Redis is a key-value database, and it is very much worth using in multiple scenarios when working with Ruby on Rails.&lt;/p&gt;

&lt;p&gt;This piece is a &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-redis-installation-and-configuration/" rel="noopener noreferrer"&gt;1:1 copy of what you can find on our website&lt;/a&gt;, along with a bunch of other Rails tutorials.&lt;/p&gt;

&lt;p&gt;Let's start this Ruby on Rails Redis guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Redis?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://redis.io/" rel="noopener noreferrer"&gt;Redis&lt;/a&gt; is a BSD licensed, in-memory data structure store. It is one of the most popular NoSQL choices among open-source options available.&lt;/p&gt;

&lt;p&gt;On top of that, &lt;a href="https://db-engines.com/en/ranking" rel="noopener noreferrer"&gt;Redis is the most popular key-value database&lt;/a&gt;, and it was voted the most loved database in the Developer Survey by Stack Overflow three years in a row: 2017, 2018 and 2019.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1129v6mytfk57cu3rys8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1129v6mytfk57cu3rys8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Redis supports various data structures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;strings,&lt;/li&gt;
&lt;li&gt;hashes,&lt;/li&gt;
&lt;li&gt;lists,&lt;/li&gt;
&lt;li&gt;sets,&lt;/li&gt;
&lt;li&gt;sorted sets with range queries,&lt;/li&gt;
&lt;li&gt;bitmaps,&lt;/li&gt;
&lt;li&gt;hyperloglogs,&lt;/li&gt;
&lt;li&gt;geospatial indexes with radius queries,&lt;/li&gt;
&lt;li&gt;streams,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and is used as a database, session cache, full page cache, and message broker, such as publish-subscribe messaging.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Redis with Ruby on Rails?
&lt;/h2&gt;

&lt;p&gt;There are multiple reasons to use Redis in Ruby on Rails application.&lt;/p&gt;

&lt;p&gt;First of all, Redis offers the most popular in-memory data store. Data kept in the memory, as opposed to tools that write to disks, is going to be read and written faster.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fur312tja8s1z28wb0atp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fur312tja8s1z28wb0atp.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another reason to use Redis in Ruby on Rails is so obvious that it is even &lt;a href="https://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-rediscachestore" rel="noopener noreferrer"&gt;made official by the Ruby on Rails maintainers&lt;/a&gt;: using Redis as Ruby on Rails application cache-store.&lt;/p&gt;

&lt;p&gt;Next, there are leaderboards: think anything that changes over time, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;up and downvotes,&lt;/li&gt;
&lt;li&gt;likes,&lt;/li&gt;
&lt;li&gt;clasps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;or internal application statistics, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;active user sessions,&lt;/li&gt;
&lt;li&gt;scheduled emails,&lt;/li&gt;
&lt;li&gt;counting visitors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A good example of the leaderboard is the Sidekiq Dashboard - which itself is a great reason to Ruby on Rails Redis usage, as it offers the most popular community choice for asynchronous code execution - and uses Redis.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftm3nh6bgxzzs6wwr95rk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftm3nh6bgxzzs6wwr95rk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last but not least is a commonly needed these days Publish-Subscribe feature, and Redis is truly crafted for the job.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd6byhtuuoeqis0dxktw0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd6byhtuuoeqis0dxktw0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://guides.rubyonrails.org/action_cable_overview.html#broadcasting" rel="noopener noreferrer"&gt;Redis is officially the default production pub/sub queue for the built-in Ruby on Rails ActionCable library&lt;/a&gt;, dedicated to channeling data through WebSockets.&lt;/p&gt;

&lt;p&gt;As you can see, there are a lot of scenarios when it's going to be worth using Ruby on Rails and Redis combination.&lt;/p&gt;

&lt;h2&gt;
  
  
  Redis installation
&lt;/h2&gt;

&lt;p&gt;Now that we know what is Redis and what it is used for in Ruby on Rails, let's go through step by step guide to installing it for further usage with our Ruby on Rails application.&lt;/p&gt;

&lt;h2&gt;
  
  
  macOS
&lt;/h2&gt;

&lt;p&gt;The most straightforward way to install Redis on the macOS is using &lt;a href="https://brew.sh/" rel="noopener noreferrer"&gt;Homebrew&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F69yl7u0rzdmrwxfv6erl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F69yl7u0rzdmrwxfv6erl.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Homebrew, there's a single command to do so on the official website.&lt;/li&gt;
&lt;li&gt;Install Redis via Homebrew: &lt;code&gt;brew install redis&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the development convenience, we are going to do one more thing, that's gonna save us a lot of trouble in the future.&lt;/p&gt;

&lt;p&gt;Let's install and enable Brew Services, in order to run Redis in the background. This way, anytime you reboot your machine, it is going to launch Redis for you automatically.&lt;/p&gt;

&lt;p&gt;Run the following commands in your CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew tap homebrew/services
brew services start redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first command installs the brew services and the second one launches Redis as a brew service. You can browse all services running at any point using the &lt;code&gt;brew services&lt;/code&gt; list command.&lt;/p&gt;

&lt;p&gt;Verify that Redis is running with &lt;code&gt;redis-cli ping&lt;/code&gt; command - it should return &lt;code&gt;PONG&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;At this point, it is worth installing a Redis client for macOS - this way you will be able to easily browse all the data written to any Redis instance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Medis from AppStore for $4.99 or install from Github,&lt;/li&gt;
&lt;li&gt;Tableplus for $59,&lt;/li&gt;
&lt;li&gt;RDM - Redis Desktop Manager for $14.99&lt;/li&gt;
&lt;li&gt;FastoRedis for $249.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As scary as it sounds, paying for the Redis client is worth it in the long run, as it vastly improves Ruby on Rails development and debugging process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Linux
&lt;/h2&gt;

&lt;p&gt;Depending on your Linux distribution you are going to use a different package manager to install Redis.&lt;/p&gt;

&lt;p&gt;If you use CentOS or RedHat, install Redis using &lt;code&gt;yum&lt;/code&gt; package manager.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum install redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Otherwise, if you use Debian based distro such as Ubuntu, use &lt;code&gt;apt&lt;/code&gt; package manager.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In both cases, in order to automatically start Redis on boot, run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl enable redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way you won't have to remember to launch Redis every time, it is very convenient for continuous development.&lt;/p&gt;

&lt;p&gt;Verify that Redis is running with &lt;code&gt;redis-cli ping&lt;/code&gt; command - it should return &lt;code&gt;PONG&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;At this point, it is also worth installing the Redis GUI client. It greatly improves the development and debugging experience, allowing you to easily browse all data written to Redis while working with your Ruby on Rails application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo9ttror5oq5srmetzobx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo9ttror5oq5srmetzobx.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We recommend using a Redis Desktop Manager, which is free for Linux distributions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails Redis installation
&lt;/h2&gt;

&lt;p&gt;If you use &lt;a href="https://hixonrails.com/" rel="noopener noreferrer"&gt;Hix on Rails&lt;/a&gt;, then you can skip the rest of this tutorial - just run the installation wizard and all of the below is going to be preconfigured for you. Optionally you might jump to the Redis Sentinel production configuration part for better understanding and customization.&lt;/p&gt;

&lt;p&gt;Otherwise, if you still did not automate this part of your life yet, read on.&lt;/p&gt;

&lt;p&gt;With Redis up and running on our system, let us install the required Redis-related gems in order to use it with our Ruby on Rails application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fx8gnweexvrucl921gte5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fx8gnweexvrucl921gte5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are going to use a &lt;a href="https://github.com/redis/redis-rb" rel="noopener noreferrer"&gt;Ruby client recommended on the official Redis website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;On top of that, there are another two gems worth installing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/redis-store/redis-rails" rel="noopener noreferrer"&gt;redis-rails gem&lt;/a&gt; that provides a full set of stores for Ruby on Rails - Cache, Session, and HTTP Cache,&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/resque/redis-namespace" rel="noopener noreferrer"&gt;redis-namespace gem&lt;/a&gt;, which is very useful when working with multiple Ruby on Rails projects.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the Gemfile of your Ruby on Rails project, add the following, outside any of the specific groups. They need to be available to all of the Ruby on Rails environments.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Gemfile&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'redis'&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'redis-namespace'&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'redis-rails'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, run the &lt;code&gt;bundle install&lt;/code&gt; command in order to generate the Gemfile.lock file.&lt;/p&gt;

&lt;p&gt;In order to easily connect to Redis from our Ruby on Rails application, we are going to additionally use the environment variables management gem, &lt;a href="https://github.com/bkeepers/dotenv" rel="noopener noreferrer"&gt;dotenv-rails&lt;/a&gt; - install it and in your .env file add these three environment variables for development.&lt;/p&gt;

&lt;p&gt;.env&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;REDIS_DB&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="no"&gt;REDIS_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="ss"&gt;:/&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;127.0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;
&lt;span class="no"&gt;REDIS_PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;6379&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;those are the default host and port of every Redis installation.&lt;/p&gt;

&lt;p&gt;Next, we are going to tell our Ruby on Rails application to connect to Redis upon booting by creating the dedicated initializer.&lt;/p&gt;

&lt;p&gt;config/initializers/redis.rb&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# frozen_string_literal: true&lt;/span&gt;

&lt;span class="no"&gt;Redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;url:  &lt;/span&gt;&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REDIS_URL'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                          &lt;span class="ss"&gt;port: &lt;/span&gt;&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REDIS_PORT'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                          &lt;span class="ss"&gt;db:   &lt;/span&gt;&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REDIS_DB'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are going to use the aforementioned Action Cable, there's one little thing worth doing at this point.&lt;/p&gt;

&lt;p&gt;As you can see, in our environment we have separated the Redis URL and DB variables. Concatenated, they result in the Redis host, and it is how Ruby on Rails Action Cable uses them. Open its configuration and change it to the following.&lt;/p&gt;

&lt;p&gt;config/cable.yml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;development:
  adapter: &lt;/span&gt;&lt;span class="n"&gt;async&lt;/span&gt;

&lt;span class="ss"&gt;test:
  adapter: &lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt;

&lt;span class="ss"&gt;production:
  adapter: &lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;
  &lt;span class="ss"&gt;url: &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= ENV.fetch("REDIS_URL") %&amp;gt;/&amp;lt;%=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"REDIS_DB"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="ss"&gt;channel_prefix: &lt;/span&gt;&lt;span class="n"&gt;app_production&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I personally like to keep the development environment as close to the production one as possible in order to catch any bugs at the earliest stage.&lt;/p&gt;

&lt;p&gt;To do that, you might consider changing the development Action Cable configuration to the same as production one - this way while writing your Ruby on Rails application's code and running it locally, you will use Redis as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails Redis production configuration with Sentinel
&lt;/h2&gt;

&lt;p&gt;If you care about high Redis availability in the production environment of your Ruby on Rails application, you might consider using the &lt;a href="https://redis.io/topics/sentinel" rel="noopener noreferrer"&gt;Redis Sentinel&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcw3h9ewwr0tc4iads8gb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcw3h9ewwr0tc4iads8gb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using Sentinel is the officially recommended way to automatically manage Redis failovers, it is also capable of monitoring and notifying on the Redis deployment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2wvxijh4anrggrlwwwry.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2wvxijh4anrggrlwwwry.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Redis client that we have previously installed in the Ruby on Rails application in order to connect to the Redis client is able to perform automatic failover using Redis Sentinel.&lt;/p&gt;

&lt;p&gt;In order to do that, we are going to change the Ruby on Rails Redis configuration file. Open the previously created initializer and edit it with the following:&lt;/p&gt;

&lt;p&gt;config/initializers/redis.rb&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# frozen_string_literal: true&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;production?&lt;/span&gt;
  &lt;span class="no"&gt;SENTINELS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'SENTINEL_HOSTS'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map!&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;host: &lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;port: &lt;/span&gt;&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'SENTINEL_PORT'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="no"&gt;Redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;url: &lt;/span&gt;&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'SENTINEL_URL'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                            &lt;span class="ss"&gt;sentinels: &lt;/span&gt;&lt;span class="no"&gt;SENTINELS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="ss"&gt;role: :master&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="no"&gt;Redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;url: &lt;/span&gt;&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REDIS_URL'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                            &lt;span class="ss"&gt;port: &lt;/span&gt;&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REDIS_PORT'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                            &lt;span class="ss"&gt;db: &lt;/span&gt;&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REDIS_DB'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration file assumes the existence of three additional environment variables. In the environment configuration of your Ruby on Rails application, add the following.&lt;/p&gt;

&lt;p&gt;.env&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SENTINEL_URL=redis://sentinel-master/1
SENTINEL_HOSTS=sentinel-slave-1 sentinel-slave-2 sentinel-slave-3
SENTINEL_PORT=26379
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another assumption that might require additional tweaks is that all the slave Redis instances run on the default Sentinel port which is &lt;code&gt;26379&lt;/code&gt;. If that is not a case, adjust the initializer file accordingly.&lt;/p&gt;

&lt;p&gt;If you are using Sidekiq and want it to respect your Sentinel production configuration, you'll need to adjust its configuration pretty much the same way - by conditionally connecting your Ruby on Rails to the Redis Sentinel in the production environment.&lt;/p&gt;

&lt;p&gt;In order to additionally improve Ruby on Rails Redis performance, you might want to take a look on &lt;a href="https://github.com/redis/hiredis" rel="noopener noreferrer"&gt;hiredis&lt;/a&gt; and its dedicated Ruby wrapper &lt;a href="https://github.com/redis/hiredis-rb" rel="noopener noreferrer"&gt;hiredis-rb&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Ruby on Rails Redis installation and configuration is a pretty straightforward thanks to the awesome official and community support.&lt;/p&gt;

&lt;p&gt;All it takes is installing a few well maintained Ruby gems, and your Ruby on Rails application is ready to read and write to Redis key-value store.&lt;/p&gt;

&lt;p&gt;All of this config comes ready with Ruby on Rails application initialized with &lt;a href="https://hixonrails.com/" rel="noopener noreferrer"&gt;Hix on Rails Application Template&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>redis</category>
      <category>ruby</category>
      <category>rails</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Using RSpec testing framework in your next Ruby on Rails project - cover-to-cover guide.</title>
      <dc:creator>hix.dev</dc:creator>
      <pubDate>Wed, 12 Feb 2020 15:12:41 +0000</pubDate>
      <link>https://forem.com/hixdevs/using-rspec-testing-framework-in-your-next-ruby-on-rails-project-cover-to-cover-guide-1388</link>
      <guid>https://forem.com/hixdevs/using-rspec-testing-framework-in-your-next-ruby-on-rails-project-cover-to-cover-guide-1388</guid>
      <description>&lt;p&gt;This post was &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-testing-rspec-configuration/"&gt;originally created on our official website&lt;/a&gt;. You are more than welcome to read it there! &lt;/p&gt;

&lt;p&gt;Now, let's get your code tested!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is RSpec?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://rspec.info/"&gt;RSpec&lt;/a&gt; is the most popular Ruby on Rails testing framework according to Ruby on Rails community. It is also perfectly capable to test any Ruby-written code. &lt;a href="https://github.com/rspec"&gt;RSpec organization repository&lt;/a&gt; is neatly organized into smaller parts, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/rspec/rspec"&gt;rspec&lt;/a&gt;, the main RSpec package,&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/rspec/rspec-core"&gt;rspec-core&lt;/a&gt;, the gem providing structure for writing executable examples and a customizable &lt;code&gt;rspec&lt;/code&gt; command,&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/rspec/rspec-rails"&gt;rspec-rails&lt;/a&gt;, RSpec package dedicated to testing Ruby on Rails applications,&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/rspec/rspec-mocks"&gt;rspec-mocks&lt;/a&gt;, RSpec gem that provides support for stubbing and mocking requests,&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/rspec/rspec-expectations"&gt;rspec-expectations&lt;/a&gt;, RSpec package that exposes a readable API to express expected outcomes of code examples.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and then some more. It all builds up into a comprehensive, fully-featured Ruby and Ruby on Rails testing framework.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7f6nwhsF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/549ihj51e1fv62mcf7lx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7f6nwhsF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/549ihj51e1fv62mcf7lx.png" alt="Alt Text" width="670" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One can easily see that the RSpec for Ruby on Rails is the most frequently developed of all the gems.&lt;/p&gt;

&lt;p&gt;As stated on the official RSpec informative website, RSpec provides a Behavior-Driven Development, BDD for Ruby, and it makes Test-Driven Development, TDD, fun and productive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ucVDucBc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9p5zv13xfyzd6g37njac.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ucVDucBc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9p5zv13xfyzd6g37njac.png" alt="Alt Text" width="670" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thorough documentation of the RSpec framework and all of its gems with executable examples is available thanks to Relish on their &lt;a href="https://relishapp.com/rspec"&gt;official website dedicated to RSpec&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5DAXhgoL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nd8t1vr0z3jvqf19jzhp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5DAXhgoL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nd8t1vr0z3jvqf19jzhp.png" alt="Alt Text" width="670" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Altogether it seems an awful lot, but it's definitely worth to use RSpec in Ruby on Rails applications, as it is the most advanced Rails testing framework of all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Ruby on Rails with RSpec over alternatives?
&lt;/h2&gt;

&lt;p&gt;Now that we review what is the RSpec testing framework, let's take a look at why it should be your choice when it comes to Ruby on Rails testing.&lt;/p&gt;

&lt;p&gt;As stated at the beginning, RSpec is the most popular choice for Ruby on Rails projects testing. However, it does not come with the default Ruby on Rails application setup, it needs to be installed manually.&lt;/p&gt;

&lt;p&gt;The default framework for Ruby on Rails applications testing is a MiniTest. It is a built-in mechanism with the &lt;a href="https://guides.rubyonrails.org/testing.html"&gt;official Ruby on Rails documentation&lt;/a&gt; on how to write unit, functional, integration and system tests, and all of its terminologies explained.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--47pzbw14--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vt9me5niiwe0b90dhjm9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--47pzbw14--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vt9me5niiwe0b90dhjm9.png" alt="Alt Text" width="670" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another noteworthy testing framework widely used with Ruby and Ruby on Rails - as with Java, Electron and many others - is a Cucumber framework.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QWsZIAPq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1p0ocaijj4ps6f3rr8yu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QWsZIAPq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1p0ocaijj4ps6f3rr8yu.png" alt="Alt Text" width="670" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what does make RSpec the best choice for testing Ruby on Rails applications?&lt;/p&gt;

&lt;p&gt;First of all, RSpec has the best documentation, which provides a ton of helpful examples and real-life scenarios that are commonly needed to be covered by developers. This is crucial for using anything that provides its own Domain-Specific Language - DSL- as the RSpec does.&lt;/p&gt;

&lt;p&gt;On top of that, RSpec out of the box has all the features that developers need, and all of them are highly maintained.&lt;/p&gt;

&lt;p&gt;MiniTest on the other hand, along with its claim that everything done by RSpec might be accomplished using dedicated plugins, does not maintain them successfully, and a lot of them are broken and have not been updated in a long time.&lt;/p&gt;

&lt;p&gt;At last, RSpec is an application, while MiniTest and Cucumber are simply frameworks. I cannot stress enough how important it is for daily usage. It does not require anything else to run the test suite, providing an end to end solution for Ruby testing.&lt;/p&gt;

&lt;p&gt;RSpec provides a mature, well maintained and documented command-line interface program. It works exactly as one would expect it to, with the CLI help available via the &lt;code&gt;--help&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;Summing it all up, RSpec is the most popular community choice for testing Ruby on Rails applications. Thanks to that, as it's open-sourced, it is highly maintained, a lot of solutions to the common problems are easily googleable and it grows in power rapidly.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is code coverage?
&lt;/h2&gt;

&lt;p&gt;Code coverage, also known as test coverage, is a measure responsible for calculating the percentage of code used while running the program's test suite.&lt;/p&gt;

&lt;p&gt;On its own, a 100% code coverage does not guarantee that the code does not contain any bugs, as a simple code execution does not guarantee its accuracy.&lt;/p&gt;

&lt;p&gt;However, it gives a nice overview of the program's test suite as a whole, telling the developers which parts are safe to edit, and which are yet to be tested.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rspec code coverage with SimpleCov
&lt;/h2&gt;

&lt;p&gt;Using RSpec in Ruby on Rails, the most popular choice for calculating the project's code coverage reports is &lt;a href="https://github.com/colszowka/simplecov"&gt;SimpleCov&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hJgEFEgx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xp9x05fgcw8nmnygxy56.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hJgEFEgx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xp9x05fgcw8nmnygxy56.png" alt="Alt Text" width="670" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, it provides a simple total percentage of the project's test suite code coverage.&lt;/p&gt;

&lt;p&gt;On top of that, SimpleCov allows grouping the reports by meaningful categories such as Ruby on Rails Controllers, Models, Views and Mailers, Sidekiq Workers and anything else that comes to mind for the given Ruby on Rails application, such as Service, Query, and Form Objects.&lt;/p&gt;

&lt;p&gt;Using the SimpleCov gem, one can set it up to fail - which means returning a non-zero value CLI-wise - for a minimum (and maximum) test code coverage limits, enforcing developers to meet the established limitations.&lt;/p&gt;

&lt;p&gt;It is a super helpful way to make people write tests when implemented in the Continuous Integration suite.&lt;/p&gt;

&lt;h2&gt;
  
  
  RSpec code coverage overview with Coveralls
&lt;/h2&gt;

&lt;p&gt;If you are serious about the code coverage, we recommend using &lt;a href="https://coveralls.io/"&gt;Coveralls&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O0OKMOIQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k0j1vu5c1xspzwromkpm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O0OKMOIQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k0j1vu5c1xspzwromkpm.png" alt="Alt Text" width="670" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is a SaaS that provides a comprehensive dashboard showing the test coverage history and statistics for the selected projects and can be easily integrated with any of the most used git repository hosting providers such as Github, Gitlab and Bitbucket.&lt;/p&gt;

&lt;p&gt;You might have met it already, as it provides a very popular coverage badge, commonly included in the &lt;code&gt;README&lt;/code&gt; files of Open Source projects, as Coveralls is free to use with any open-sourced code, forever.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t539olOB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qq7akdwiq78ovogds7z0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t539olOB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qq7akdwiq78ovogds7z0.png" alt="Alt Text" width="555" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Coveralls is an overall great tool to ensure a better Ruby on Rails application maintenance, providing both the simple and sophisticated overviews of the projects testing suite code coverage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure RSpec in a Ruby on Rails project
&lt;/h2&gt;

&lt;p&gt;If you use &lt;a href="https://hixonrails.com"&gt;Hix on Rails&lt;/a&gt;, you don't need to do any of the following - simply go through the setup wizard and be done with it, anytime you start a new project.&lt;/p&gt;

&lt;p&gt;Otherwise, if you sadly did not automate this part of your life yet, read on.&lt;/p&gt;

&lt;p&gt;Let us now configure the RSpec testing framework in the Ruby on Rails project, following a simple step by step guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Raw RSpec config in Ruby on Rails
&lt;/h2&gt;

&lt;p&gt;In order to use RSpec with your Ruby on Rails application, you need to install the dedicated rspec-rails gem. Open your project's &lt;code&gt;Gemfile&lt;/code&gt; and add it to the test and development groups.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Gemfile&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="ss"&gt;:development&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:test&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'rspec-rails'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, run the &lt;code&gt;bundle install&lt;/code&gt; command in your CLI after navigating to your project's root path, in order to include the gem in your Ruby on Rails project's &lt;code&gt;Gemfile.lock&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;bundle install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;RSpec is equipped with the &lt;code&gt;rspec&lt;/code&gt; command, that comes with an initialization option. However, in Ruby on Rails, there's a dedicated generator to do just that. In your CLI, run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;rails generate rspec:install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It generates three files: .rspec, spec/spec_helper.rb and spec/rails_helper.rb. The first file is loaded every time the &lt;code&gt;rspec&lt;/code&gt; command runs via CLI, passing the RSpec options to it. By default, it only tells RSpec to include the other helper files that are responsible for defining the gem's configuration.&lt;/p&gt;

&lt;p&gt;A full list of options available resides under the &lt;code&gt;rspec --help&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i0NE7_mo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pbxwaasjjllyszv1wtc4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i0NE7_mo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pbxwaasjjllyszv1wtc4.png" alt="Alt Text" width="670" height="908"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, there are three options defined in the second generated file, all of which are going to be the defaults in the next major version of the RSpec framework, the RSpec 4. It is recommended by the framework authors to leave them this way. Options are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Including the chained methods in the output messages&lt;/li&gt;
&lt;li&gt;Preventing from mocking or stubbing a method that does not exist on a real object&lt;/li&gt;
&lt;li&gt;Causing shared contexts metadata to be inherited by the metadata hash of host groups and examples, rather than triggering implicit auto-inclusion in groups with matching metadata&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On top of that, there are some commented-out configuration options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limiting a spec run to individual examples or groups you care about by providing custom tag&lt;/li&gt;
&lt;li&gt;Persisting tests state between runs in order to support failure-related CLI options&lt;/li&gt;
&lt;li&gt;Limiting the available syntax to the non-monkey patched, which is recommended&lt;/li&gt;
&lt;li&gt;Enabling warnings&lt;/li&gt;
&lt;li&gt;Custom formatting based on a number of spec files in the test run&lt;/li&gt;
&lt;li&gt;Profiling, that for a given number of tests tells us which of them are the slowest to run&lt;/li&gt;
&lt;li&gt;Ordering of the tests in the test run&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The last generated file, &lt;code&gt;spec/rails_helper.rb&lt;/code&gt;, is responsible for defining the Ruby on Rails specific configuration. Those two are separated for performance reasons, as explained in this &lt;a href="https://github.com/rspec/rspec-rails/issues/1180"&gt;rspec-rails dispute&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The third file does a multitude of helpful things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prevents tests run in the production environment&lt;/li&gt;
&lt;li&gt;Sets Rails environment to the TEST if nothing else is set&lt;/li&gt;
&lt;li&gt;Prevents tests run if Rails migrations are not up to date with the schema&lt;/li&gt;
&lt;li&gt;Defines fixtures path and tells RSpec to use transactional fixtures&lt;/li&gt;
&lt;li&gt;Tells RSpec to "figure out" the test type from its location in the project - defaults available are Controllers, Models, and Views&lt;/li&gt;
&lt;li&gt;Filters out the Ruby on Rails output from the backtrace&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From now on, whenever adding anything related to Ruby on Rails to the RSpec configuration, we are going to do so in the &lt;code&gt;spec/rails_helper.rb&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Let us do just that by adding a few helpful gems that make testing easier and more predictable.&lt;/p&gt;

&lt;h2&gt;
  
  
  DatabaseCleaner gem set up with RSpec in Ruby on Rails
&lt;/h2&gt;

&lt;p&gt;In order to keep our Ruby on Rails project's test database clean between test runs, we are going to install an additional &lt;a href="https://github.com/DatabaseCleaner/database_cleaner#list-of-adapters"&gt;gem dedicated to doing just that, the DatabaseCleaner&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First of all, select and install one of the gems dedicated to specific Ruby on Rails ORMs supported by DatabaseCleaner. The most popular choice is going to be the Active Record gem. In your Gemfile file, add the gem of your choice to the test group.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Gemfile&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="ss"&gt;:test&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'database_cleaner-active_record'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and run the &lt;code&gt;bundle install&lt;/code&gt; command from the root path of your Ruby on Rails project.&lt;/p&gt;

&lt;p&gt;Next, let us tell RSpec to clean the Ruby on Rails project tests database in between the test suite runs. Open the &lt;code&gt;spec/rails_helper.rb&lt;/code&gt; and add the following.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;spec/rails_helper.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;RSpec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="c1"&gt;# some&lt;/span&gt;
  &lt;span class="c1"&gt;# other&lt;/span&gt;
  &lt;span class="c1"&gt;# configuration&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;before&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:suite&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="no"&gt;DatabaseCleaner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strategy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;:truncation&lt;/span&gt;
    &lt;span class="no"&gt;DatabaseCleaner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clean_with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:truncation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;before&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="no"&gt;DatabaseCleaner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strategy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;:transaction&lt;/span&gt;
    &lt;span class="no"&gt;DatabaseCleaner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append_after&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="no"&gt;DatabaseCleaner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clean&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This set of configuration hooks tells RSpec to do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;truncate the database before test suite run&lt;/li&gt;
&lt;li&gt;rollback database changes between tests&lt;/li&gt;
&lt;li&gt;clean the database after the tests suite run&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cleaning the Ruby on Rails tests database on all of these stages prevents the test's failures caused by any rubbish data leftovers generated between the RSpec tests run.&lt;/p&gt;

&lt;h2&gt;
  
  
  ShouldaMatchers gem set up with RSpec in Ruby on Rails
&lt;/h2&gt;

&lt;p&gt;One of the most popular gems that support testing Ruby on Rails applications with RSpec is &lt;a href="https://github.com/thoughtbot/shoulda-matchers"&gt;ShouldaMatchers&lt;/a&gt;. It provides a great toolkit for testing the methods commonly used in the classes provided in Ruby on Rails framework, such as &lt;code&gt;ActiveModel&lt;/code&gt;, &lt;code&gt;ActiveRecord&lt;/code&gt; and &lt;code&gt;ActionController&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In order to use ShouldaMatchers in your Ruby on Rails project with RSpec, we need to install the shoulda-matchers gem first. Open the &lt;code&gt;Gemfile&lt;/code&gt; file and add it to the tests group.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Gemfile&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="ss"&gt;:test&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'shoulda-matchers'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the &lt;code&gt;bundle install&lt;/code&gt; command in your Ruby on Rails project's root directory, and edit the &lt;code&gt;spec/rails_helper.rb&lt;/code&gt; with the following.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;spec/rails_helper.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Shoulda&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Matchers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;integrate&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;with&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="n"&gt;with&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test_framework&lt;/span&gt; &lt;span class="ss"&gt;:rspec&lt;/span&gt;
    &lt;span class="n"&gt;with&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;library&lt;/span&gt; &lt;span class="ss"&gt;:rails&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it - your Ruby on Rails project is ready to use all the matchers provided by the ShouldaMatchers in the RSpec tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  FactoryBot gem set up with RSpec in Ruby on Rails
&lt;/h2&gt;

&lt;p&gt;FactoryBot is the most popular fixtures replacement for Ruby on Rails projects. It provides a straightforward definition syntax and supports both multiple build strategies and factories for the same class, including inheritance.&lt;/p&gt;

&lt;p&gt;In order to use FactoryBot in the Ruby on Rails project with RSpec, install the dedicated FactoryBotRails gem. Open the Gemfile file and add the following to the development and test groups.&lt;/p&gt;

&lt;p&gt;Gemfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="ss"&gt;:development&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:test&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'factory_bot_rails'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding the gem to the development group results in modifying the default Ruby on Rails generators to produce related factories - from now on, whenever you generate the new model via command line, the corresponding factory will be generated as well.&lt;/p&gt;

&lt;p&gt;In order to include the FactoryBot in the RSpec configuration, add the following to the spec/rails_helper.rb.&lt;/p&gt;

&lt;p&gt;spec/rails_helper.rb&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;RSpec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="c1"&gt;# some other configuration&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;include&lt;/span&gt; &lt;span class="no"&gt;FactoryBot&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Syntax&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Methods&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can take the full advantage of the FactoryBot gem whenever writing RSpec tests in your Ruby on Rails project.&lt;/p&gt;

&lt;h2&gt;
  
  
  TimeCop gem set up with RSpec in Ruby on Rails
&lt;/h2&gt;

&lt;p&gt;As stated in the &lt;a href="https://rspec.rubystyle.guide/#dealing-with-time"&gt;RSpec Ruby Styleguide&lt;/a&gt;, the best way to deal with time when testing Ruby on Rails applications with RSpec is to use the &lt;a href="https://github.com/travisjeffery/timecop"&gt;TimeCop&lt;/a&gt; gem.&lt;/p&gt;

&lt;p&gt;TimeCop provides time freezing, travel, and acceleration capabilities, giving developers oneliners to deal with the time, instead of stubbing anything on &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Time&lt;/code&gt; and &lt;code&gt;DateTime&lt;/code&gt; classes.&lt;/p&gt;

&lt;p&gt;In order to use the TimeCop gem in your Ruby on Rails project, simply add it to the test group of your Gemfile file.&lt;/p&gt;

&lt;p&gt;Gemfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="ss"&gt;:test&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'timecop'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It does not require any configuration specific to RSpec in the Ruby on Rails project.&lt;/p&gt;

&lt;p&gt;In order to &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-project-rubocop-setup-with-rspec/"&gt;take the quality of your RSpec Ruby tests to the next level, visit the Ruby on Rails RuboCop configuration guide&lt;/a&gt; - it provides the way to validate your RSpec tests suite in the Ruby on Rails project against aforementioned RSpec Style Guide automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  SimpleCov configuration in Ruby on Rails with RSpec
&lt;/h2&gt;

&lt;p&gt;In order to generate the coverage reports in the Ruby on Rails application tested with RSpec, we are going to install the aforementioned SimpleCov gem. In your project's Gemfile, add the required gem to the test group.&lt;/p&gt;

&lt;p&gt;Gemfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="ss"&gt;:test&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'simplecov'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and next, navigate to your projects root path and run the &lt;code&gt;bundle install&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;By default, SimpleCov is going to generate all of its reports into the coverage directory of our project. Let's add it to the project's .gitignore file in order to avoid a massive amount of changes accompanying every test run.&lt;/p&gt;

&lt;p&gt;.gitignore&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;coverage/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we are going to follow the gem instructions in order to turn on the SimpleCov code coverage gem every time the test suite runs. Open the spec/spec_helper.rb file and add the following at the beginning of it.&lt;/p&gt;

&lt;p&gt;spec/spec_helper.rb&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'simplecov'&lt;/span&gt;

&lt;span class="no"&gt;SimpleCov&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt; &lt;span class="s1"&gt;'rails'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the simplest manner possible, you're done - every test run is going to result in the code coverage report generation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coveralls account setup and configuration in Ruby on Rails
&lt;/h2&gt;

&lt;p&gt;Now that we are generating the code coverage reports, let us track their history along the Ruby on Rails application development via Coveralls.&lt;/p&gt;

&lt;p&gt;Follow the step by step guide in order to set up your Coveralls account and adding your Ruby on Rails project to it.&lt;/p&gt;

&lt;p&gt;Be aware that you are going to subscribe to the Corveralls PRO in order to set up private repositories here.&lt;/p&gt;

&lt;p&gt;1.Sign up on the &lt;a href="https://coveralls.io/sign-in"&gt;official Coveralls website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wPr-TFPu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t45b8gsnaftaywf24pre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wPr-TFPu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t45b8gsnaftaywf24pre.png" alt="Alt Text" width="670" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.After logging in, authorize Coveralls to access your repository hosting provider account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DSAYKIa4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/osngb4d7l5401z4vea5t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DSAYKIa4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/osngb4d7l5401z4vea5t.png" alt="Alt Text" width="495" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.Hover the left-hand side sidebar and click the "Add Repos" link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ouV5rB16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ka51gdr1bjylw5toekcb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ouV5rB16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ka51gdr1bjylw5toekcb.png" alt="Alt Text" width="670" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.Search for your Ruby on Rails project repository in Coveralls and turn it on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7Yzc8-1g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/h3fbj460x10trl3tzkqp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Yzc8-1g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/h3fbj460x10trl3tzkqp.png" alt="Alt Text" width="670" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5.Click the "Details" button and copy your Coveralls repository key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m2qiMgz6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5oldsbxqnuwy4tc23h3c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m2qiMgz6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5oldsbxqnuwy4tc23h3c.png" alt="Alt Text" width="880" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After obtaining the Coveralls repository key and enabling it in the tool's interface, we are going to set it up in our Ruby on Rails project.&lt;/p&gt;

&lt;p&gt;First, let's install the provided gem. Open the Gemfile file and add the coveralls to the test group.&lt;/p&gt;

&lt;p&gt;Gemfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="ss"&gt;:test&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'coveralls'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the &lt;code&gt;bundle install&lt;/code&gt; command and open the spec/spec_helper.rb file, in order to tell RSpec to use the provided formatter.&lt;/p&gt;

&lt;p&gt;spec/spec_helper.rb&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# frozen_string_literal: true

require 'coveralls'
require 'simplecov'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([SimpleCov::Formatter::HTMLFormatter,
                                                                Coveralls::SimpleCov::Formatter])
SimpleCov.start 'rails'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last step is to create a dedicated Coveralls configuration file with our previously generated repository key.&lt;/p&gt;

&lt;p&gt;.coveralls.yml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;service_name: &lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;
&lt;span class="ss"&gt;repo_token: &lt;/span&gt;&lt;span class="no"&gt;YOUR_COVERALLS_REPOSITORY_KEY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Depending on the Continuous Integration service that you use, update the service name accordingly. If in doubt, browse the &lt;a href="https://docs.coveralls.io/supported-ci-services"&gt;full list of services supported by Coveralls&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;My advice is to take another five minutes to figure out how to skip using the .coveralls.yml file completely, as keeping secrets checked into your remote repository might not be the best idea&lt;/p&gt;

&lt;p&gt;It is better to define them as environment variables, and most of the Continuous Integration providers enable that option. Coveralls documentation gives you guidelines on how to do just that for their supported services.&lt;/p&gt;

&lt;p&gt;The main goal here is to generate your code coverage reports via your RSpec tests run on the Continuous Integration whenever you merge the new feature to develop and master branches. This way your Coveralls history and statistics will not clutter with endless reports of identical feature branches code coverage data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As stated multiple times in this guide, RSpec is the most popular choice for testing the Ruby on Rails applications, and for a number of good reasons.&lt;/p&gt;

&lt;p&gt;If you care about Ruby on Rails tests, setting up the code coverage reporting is recommended - it gives developers a nice overview of the project's maintenance quality.&lt;/p&gt;

&lt;p&gt;The SimpleCov gem is a simple to use solution to do just that in your Ruby on Rails projects that use RSpec - all it takes are two extra lines of code and the dedicated gem installed.&lt;/p&gt;

&lt;p&gt;For those who want more control, enforcing the minimal code coverage in the Ruby on Rails application takes only the single line of code in the RSpec configuration file.&lt;/p&gt;

&lt;p&gt;If you're looking for a professional overview of the code coverage statistics and history for your Ruby on Rails projects, use Coveralls - it aggregates your code coverage data and exposes it via sophisticated web UI.&lt;/p&gt;

&lt;p&gt;As you can see, there's a lot of configuration related to the RSpec testing framework set up in the Ruby on Rails project -fortunately, you can skip most of it by using the &lt;a href="https://hixonrails.com"&gt;Hix on Rails, the Ruby on Rails project generator&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>codequality</category>
      <category>testing</category>
    </item>
    <item>
      <title>Setting up your next Rails project with RuboCop - a 101 guide</title>
      <dc:creator>hix.dev</dc:creator>
      <pubDate>Fri, 07 Feb 2020 14:44:46 +0000</pubDate>
      <link>https://forem.com/hixdevs/setting-up-your-next-rails-project-with-gitlabci-a-101-guide-2npp</link>
      <guid>https://forem.com/hixdevs/setting-up-your-next-rails-project-with-gitlabci-a-101-guide-2npp</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/rubocop-hq/rubocop"&gt;RuboCop&lt;/a&gt; is the most popular Ruby static code analyzer and code formatter, code linter in short. Linting is the process of running a program that analyzes the code for programmatic and stylistic errors.&lt;/p&gt;

&lt;p&gt;Using it translates to a better code quality, clean code, and better experience for the readers. &lt;/p&gt;

&lt;p&gt;In this tutorial I will explain how you can implement it in your next Rails project. &lt;/p&gt;

&lt;p&gt;It's also available in a &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-project-rubocop-setup-with-rspec/"&gt;1:1 format on our original site&lt;/a&gt; if you prefer to read from the source. &lt;/p&gt;

&lt;p&gt;Let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is RuboCop and Ruby Style Guide?
&lt;/h2&gt;

&lt;p&gt;Out of the box, Rubocop enforces most of the guidelines outlined in the &lt;a href="https://rubystyle.guide/"&gt;Ruby Style Guide&lt;/a&gt; maintained by the Ruby community. The guide groups its guidelines by related sections, which corresponds to RuboCop gems departments.&lt;/p&gt;

&lt;p&gt;There are nine departments in the base RuboCop gem. Numbers might change in time and are given here only for the rough overview of what the gem offers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Layout - 87 cops&lt;/li&gt;
&lt;li&gt;Linting - 81 cops&lt;/li&gt;
&lt;li&gt;Metrics - 10 cops&lt;/li&gt;
&lt;li&gt;Migration - 1 cop&lt;/li&gt;
&lt;li&gt;Naming - 16 cops&lt;/li&gt;
&lt;li&gt;Security - 5 cops&lt;/li&gt;
&lt;li&gt;Style Cops - 170 cops&lt;/li&gt;
&lt;li&gt;Bundler - 4 cops&lt;/li&gt;
&lt;li&gt;Gemspec - 4 cops&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In total, there is a little less than 400 rules applicable to anything written in Ruby, if we choose so.&lt;/p&gt;

&lt;p&gt;But, it does not end here - let us take a quick look at accelerating the Ruby code by following extended RuboCop guidelines.&lt;/p&gt;

&lt;h2&gt;
  
  
  RuboCop Performance
&lt;/h2&gt;

&lt;p&gt;There's an extension wisely encapsulated in its own &lt;a href="https://github.com/rubocop-hq/rubocop-performance"&gt;Ruby gem called RuboCop Performance&lt;/a&gt;. Its job is pointing out Ruby code optimization opportunities.&lt;/p&gt;

&lt;p&gt;All 25 rules of the RuboCop Performance gem are grouped in the single RuboCop department, called Performance.&lt;/p&gt;

&lt;p&gt;It is a relatively young project and some of the cops included were originally placed in the main RuboCop gem.&lt;/p&gt;

&lt;p&gt;If your Ruby program is really performance-dependent, you might want to additionally look at the &lt;a href="https://github.com/DamirSvrtan/fasterer"&gt;fasterer&lt;/a&gt; gem, based on the open-sourced Github repository called &lt;a href="https://github.com/JuanitoFatas/fast-ruby"&gt;Fast Ruby - the biggest collection of Ruby benchmarks&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let us now take a look into other, framework-specific RuboCop extensions.&lt;/p&gt;

&lt;h2&gt;
  
  
  RuboCop Rails and Rails Style Guide
&lt;/h2&gt;

&lt;p&gt;When RuboCop is a code linter of your choice, &lt;a href="https://github.com/rubocop-hq/rubocop-rails"&gt;RuboCop Rails extension&lt;/a&gt; is the must-have for your Ruby on Rails projects.&lt;/p&gt;

&lt;p&gt;RuboCop Rails is a RuboCop extension focused on enforcing Ruby on Rails coding conventions and best practices, neatly described in the &lt;a href="https://rails.rubystyle.guide/"&gt;Ruby on Rails Style Guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The style guide itself is split into 16 sections, covering things such as Ruby on Rails configuration, dealing with time, Models, Controllers, Mailers and more.&lt;/p&gt;

&lt;p&gt;Whenever in doubt on how to approach Ruby on Rails related problem, try browsing the relevant style guide section, or go one step further and let your projects Continuous Integration point it out for you, by configuring RuboCop gem with all its extension on either &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-set-up-on-gitlab-with-gitlabci/"&gt;GitlabCI&lt;/a&gt; or &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-set-up-on-github-with-circleci/"&gt;CircleCI&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  RuboCop RSpec and RSpec Style Guide
&lt;/h2&gt;

&lt;p&gt;If RSpec is your weapon of choice unit-testing-wise, setting up the &lt;a href="https://github.com/rubocop-hq/rubocop-rspec"&gt;RuboCop RSpec extension&lt;/a&gt; will help you a lot.&lt;/p&gt;

&lt;p&gt;RuboCop RSpec is a RuboCop extension that provides RSpec, RSpec for Rails, FactoryBot and Capybara analysis for Ruby projects, which in total gives us another 76 rules to follow, for the sake of neat codebase.&lt;/p&gt;

&lt;p&gt;All of the RuboCop RSpec cops - and then some - are extensively described in the &lt;a href="https://rspec.rubystyle.guide/"&gt;RSpec Ruby Style Guide&lt;/a&gt;, providing examples of the code that follows the guideline paired with the one that does not.&lt;/p&gt;

&lt;p&gt;It is my personal favorite style guide of all provided by the RubCop HeadQuarters, and I rely on it a lot during Code Reviews - my Github account saved replies are linking to it heavily.&lt;/p&gt;

&lt;p&gt;Next to the gem itself, the guide gives an extremely useful overview of how to write unit tests of Ruby on Rails related parts, such as the MVC Models, Views, Controllers and also Mailers.&lt;/p&gt;

&lt;p&gt;Unfortunately, some of the Rails related rules are not possible to enforce via the gem itself, hence the Github saved replies linking to the relevant guide sections.&lt;/p&gt;

&lt;p&gt;It is still a great tool whenever you use RSpec in your Ruby and Ruby on Rails projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  RuboCop MiniTest and MiniTest Style Guide
&lt;/h2&gt;

&lt;p&gt;If you use &lt;a href="https://github.com/seattlerb/minitest"&gt;MiniTest&lt;/a&gt;, the second most popular choice for testing the Ruby written programs, there's a RuboCop extension dedicated to it, called &lt;a href="https://github.com/rubocop-hq/rubocop-minitest"&gt;RuboCop MiniTest&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It enforces best practices outlined in the &lt;a href="https://minitest.rubystyle.guide/"&gt;MiniTest Style Guide&lt;/a&gt;, yet another great read provided by RuboCop HeadQuarters.&lt;/p&gt;

&lt;p&gt;It's a relatively young project comparing to the more popular RSpec choice. It describes a total of 15 rules for writing unit tests using the MiniTest framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  RuboCop set up in a single Ruby on Rails project
&lt;/h2&gt;

&lt;p&gt;Now that we went through most of the RuboCop extensions - there are two more, for &lt;a href="https://github.com/rubocop-hq/rubocop-rake"&gt;Rake&lt;/a&gt; and &lt;a href="https://github.com/rubocop-hq/rubocop-md"&gt;Markdown&lt;/a&gt; - let us take a look at how to hook it all up in the Ruby on Rails application.&lt;/p&gt;

&lt;p&gt;RuboCop and its extension configuration files are written in YAML. They are all placed in the same config directory, in each of the repositories respectively, assisted with a great RubyDoc documentations, which altogether makes it very easy to find and understand every rule.&lt;/p&gt;

&lt;p&gt;When working on the Ruby on Rails project that uses either RSpec or MiniTest, we are going to install 4 RuboCop gems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RuboCop&lt;/li&gt;
&lt;li&gt;RuboCop Performance&lt;/li&gt;
&lt;li&gt;RuboCop Rails&lt;/li&gt;
&lt;li&gt;RuboCop RSpec or RuboCop MiniTest&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Go ahead and edit your &lt;code&gt;Gemfile&lt;/code&gt;, adding the following to the development and test group.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="ss"&gt;:development&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:test&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'rubocop'&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'rubocop-performance'&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'rubocop-rails'&lt;/span&gt;
  &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'rubocop-rspec'&lt;/span&gt; &lt;span class="c1"&gt;# or gem 'rubocop-minitest'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next in your CLI, navigate to the directory path of your Ruby on Rails project and run the &lt;code&gt;bundle install&lt;/code&gt; command in order to update your &lt;code&gt;Gemfile.lock&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now that all the gems are installed, let us prepare our custom RuboCop configuration file, called &lt;code&gt;.rubocop.yml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It is responsible for two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Importing installed extensions&lt;/li&gt;
&lt;li&gt;Defining which cops we do and do not want to enforce&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By default, it uses the predefined RuboCop configuration with no other extensions installed, as it is designed to work with any Ruby language codebase.&lt;/p&gt;

&lt;p&gt;In order to include the installed extensions, create the following RuboCop configuration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;require: 
  &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;rubocop&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;performance&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;rubocop&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;rails&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;rubocop&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;rspec&lt;/span&gt; &lt;span class="c1"&gt;# or rubocop-minitest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we are going to follow the &lt;a href="https://rubocop.readthedocs.io/en/stable/configuration/#includingexcluding-files"&gt;example configuration for Ruby on Rails project presented in the RuboCop documentation&lt;/a&gt; - but in order to use the aforementioned extensions, we are going to skip some of it.&lt;/p&gt;

&lt;p&gt;Add the following to your configuration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;AllCops&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="no"&gt;Exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'db/**/*'&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'script/**/*'&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'bin/**/*'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It tells RuboCop to exclude given directories while analyzing the codebase - the readability does not matter there too much and is not worth bothering for the pleasing Ruby on Rails development.&lt;/p&gt;

&lt;p&gt;Next, let us cut some additional slack while working with RuboCop. Those are the sane RuboCop rules to use with Ruby on Rails project.&lt;/p&gt;

&lt;p&gt;Below the previous configuration, add the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Metrics&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;LineLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="no"&gt;Max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;

&lt;span class="no"&gt;Metrics&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;BlockLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="no"&gt;Exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;/**&lt;/span&gt;&lt;span class="sr"&gt;/*
    - spec/&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sr"&gt;/*

Lint/&lt;/span&gt;&lt;span class="no"&gt;AmbiguousBlockAssociation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="no"&gt;Exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;spec&lt;/span&gt;&lt;span class="o"&gt;/**&lt;/span&gt;&lt;span class="sr"&gt;/*

Style/&lt;/span&gt;&lt;span class="no"&gt;Documentation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="no"&gt;Enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Most of those are pretty self-descriptive, but let's go through them quickly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Line length cop - that's the one you might want to change to your liking - it enforces a maximum amount of characters per single line of the code&lt;/li&gt;
&lt;li&gt;Block length cop is told to ignore the config and spec directories, as those blocks of code tend to grow like mad, and we don't want to discourage our contributors to write fewer tests, right?&lt;/li&gt;
&lt;li&gt;Ambiguous block association is turned off for the tests directory, &lt;a href="https://github.com/rubocop-hq/rubocop/issues/4222#issuecomment-290722962"&gt;as encouraged by the RuboCop HeadQuarters rockstar, bbatsov&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Documentation cop is turned off, as there are better ways to document the Ruby on Rails code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is important to remember that nothing here is written in stone - if you ever feel like you waste more time than its worth fixing some "stupid RuboCop rules", you can always disable them in this file.&lt;/p&gt;

&lt;p&gt;At this point, assuming that you've recently created your brand new Ruby on Rails project the RuboCop analysis will give you some headache, as Ruby on Rails does not follow its default guidelines.&lt;/p&gt;

&lt;p&gt;But worry not - most of it can be easily fixed using the RuboCop command with the &lt;code&gt;--safe-auto-correct flag&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's not be naive, everything can crash, no matter if its name contains "safe" - create a backup of your recent changes to git first.&lt;/p&gt;

&lt;p&gt;Then, navigate to your project directory and run the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;bundle exec rubocop --safe-auto-correct&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will fix all RuboCop violations that are marked as auto-fixable in the default configuration file. Browse the changes and if it seems ok, add it to git.&lt;/p&gt;

&lt;p&gt;There's also a big chance that you work on some much older Ruby on Rails codebase, and the quick-fix presented above might not be that effective, nor the best idea - some stuff might actually break.&lt;/p&gt;

&lt;p&gt;Thankfully to the awesome RuboCop maintainers, there's a solution for legacy code implementations, the &lt;code&gt;--auto-gen-config&lt;/code&gt; command-line flag.&lt;/p&gt;

&lt;p&gt;In the root directory of your legacy Ruby on Rails project after installing all the gems and creating the configuration file, run the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;bundle exec rubocop --auto-gen-config&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It does two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Analyzes the codebase for RuboCop violations, writing the exclusions into the .rubocop_todo.yml file,&lt;/li&gt;
&lt;li&gt;Updates the .rubocop.yml file with an import of the exclusions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, if you run the bare &lt;code&gt;bundle exec rubocop&lt;/code&gt; command again, it will show 0 offenses.&lt;/p&gt;

&lt;p&gt;This is a great way for improving legacy Ruby on Rails applications code: just tell your team, that whenever anybody works on it, they should:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Look it up and comment-out a path to it in the TODO file,&lt;/li&gt;
&lt;li&gt;Fix what's possible,&lt;/li&gt;
&lt;li&gt;Delete the commented-out paths exclusions for good.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That way the Ruby on Rails codebase quality is going to improve vastly over time, eventually allowing developers to remove the TODO list completely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sharing RuboCop configuration in multiple Ruby on Rails projects
&lt;/h2&gt;

&lt;p&gt;It is easy to set the RuboCop up for a single Ruby on Rails project, although, following the current microservices trend, that's hardly enough. There's a big chance that wherever you work at, your team either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;creates multiple Ruby on Rails projects monthly (like Software Houses do),&lt;/li&gt;
&lt;li&gt;maintains multiple Ruby on Rails projects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;RuboCop evolves, all its extensions do too, and developers' preferences change. Maintenance of all those moving parts along with keeping sane is not a trivial task. Imagine that company you work for has 15 microservices, all written in Ruby on Rails, and consider one of the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Your team decides that they don't like Department/Cop anymore&lt;/li&gt;
&lt;li&gt;RuboCop releases a newer version&lt;/li&gt;
&lt;li&gt;RuboCop Rails releases a newer version&lt;/li&gt;
&lt;li&gt;RuboCop RSpec releases a newer version&lt;/li&gt;
&lt;li&gt;RuboCop Performance releases a newer version&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It's quite a copypaste task to keep it all up to date.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.percy.io/share-rubocop-rules-across-all-of-your-repos-f3281fbd71f8"&gt;Percy, the QA SaaS&lt;/a&gt;, and &lt;a href="https://github.com/googleapis/ruby-style"&gt;Google APIs&lt;/a&gt; propose (and use themselves) a solution to that - creating your own gem with all the required extensions installed, a single source of the RuboCop configuration.&lt;/p&gt;

&lt;p&gt;With your own gem, the "only" thing you need to do is updating it (and either backward-fixing or ignoring the "new" violations after the update) in every single project. There's automatically less room for error, as the single configuration per project would require you to update the core, every single extension and on top of that, the configuration file.&lt;/p&gt;

&lt;p&gt;There's another option available, although I'm not a big fan of it, as in my opinion it is not controlled enough and might actually do some damage - with RuboCop, you might include the configuration from an URL address, so theoretically you would not need to manually update it in every single project.&lt;/p&gt;

&lt;p&gt;What I don't like about it: if you lint the code in your Continuous Integration suite, it might suddenly cause your jobs to stop passing if new rules won't be backward compatible with the old code - and as a result, stop the development just to fix them.&lt;/p&gt;

&lt;p&gt;Summing up, if your team maintains and/or creates a lot of Ruby on Rails applications, consider encapsulating your RuboCop configuration in the separated, shared gem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced RuboCop configuration
&lt;/h2&gt;

&lt;p&gt;For all the standards nazis like myself, I'm going to mention yet another detail that I've recently discovered about RuboCop: it does not enable all its options by default.&lt;/p&gt;

&lt;p&gt;See it for yourself.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Browse the &lt;a href="https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml"&gt;config/default.yml&lt;/a&gt; file in the core RuboCop gem repository,&lt;/li&gt;
&lt;li&gt;Search &lt;code&gt;CTRL + F&lt;/code&gt; for the "Enabled: false" phrase.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At the time of writing this guide, there are 35 occurrences of the searched phrase, two of which are some explanatory comments.&lt;/p&gt;

&lt;p&gt;It seems that there are 33 additional rules that one can potentially follow, improving the Ruby on Rails codebase even further!&lt;/p&gt;

&lt;p&gt;Those are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Bundler/GemComment&lt;/code&gt;: Add a comment describing each gem.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Layout/ClassStructure&lt;/code&gt;: Enforces a configured order of definitions within a class body.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Layout/FirstArrayElementLineBreak&lt;/code&gt;: Checks for a line break before the first element in a multi-line array.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Layout/FirstHashElementLineBreak&lt;/code&gt;: Checks for a line break before the first element in a multi-line hash.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Layout/FirstMethodArgumentLineBreak&lt;/code&gt;: Checks for a line break before the first argument in a multi-line method call.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Layout/FirstMethodParameterLineBreak&lt;/code&gt;: Checks for a line break before the first parameter in a multi-line method parameter definition.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Layout/HeredocArgumentClosingParenthesis&lt;/code&gt;: Checks for the placement of the closing parenthesis in a method call that passes a HEREDOC string as an argument.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Layout/MultilineArrayLineBreaks&lt;/code&gt;: Checks that each item in a multi-line array literal starts on a separate line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Layout/MultilineAssignmentLayout&lt;/code&gt;: Check for a newline after the assignment operator in multi-line assignments.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Layout/MultilineHashKeyLineBreaks&lt;/code&gt;: Checks that each item in a multi-line hash literal starts on a separate line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Layout/MultilineMethodArgumentLineBreaks&lt;/code&gt;: Checks that each argument in a multi-line method call starts on a separate line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Lint/HeredocMethodCallPosition&lt;/code&gt;: Checks for the ordering of a method call where the receiver of the call is a HEREDOC.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Lint/NumberConversion&lt;/code&gt;: Checks unsafe usage of number conversion methods.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Migration/DepartmentName&lt;/code&gt;: Check that cop names in rubocop:disable (etc) comments are given with department name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/AutoResourceCleanup&lt;/code&gt;: Suggests the usage of an auto resource cleanup version of a method (if available).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/CollectionMethods&lt;/code&gt;: Preferred collection methods: map, find, select, reduce, size by default.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/ConstantVisibility&lt;/code&gt;: Check that class and module constants have visibility declarations.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/Copyright&lt;/code&gt;: Include a copyright notice in each file before any code.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/DateTime&lt;/code&gt;: Use Time over DateTime.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/DocumentationMethod&lt;/code&gt;: Checks for missing documentation comments for public methods.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/ImplicitRuntimeError&lt;/code&gt;: Use raise or fail with an explicit exception class and message, rather than just a message.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/InlineComment&lt;/code&gt;: Avoid trailing inline comments.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/IpAddresses&lt;/code&gt;: Don't include literal IP addresses in code.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/MethodCallWithArgsParentheses&lt;/code&gt;: Use parentheses for method calls with arguments.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/MethodCalledOnDoEndBlock&lt;/code&gt;: Avoid chaining a method call on a do...end block.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/MissingElse&lt;/code&gt;: Require if/case expressions to have an else branches.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/MultilineMethodSignature&lt;/code&gt;: Avoid multi-line method signatures.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/OptionHash&lt;/code&gt;: Don't use option hashes when you can use keyword arguments.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/ReturnNil&lt;/code&gt;: Use return instead of return nil.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/Send&lt;/code&gt;: Prefer Object#&lt;strong&gt;send&lt;/strong&gt; or Object#public_send to send, as send may overlap with existing methods.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/SingleLineBlockParams&lt;/code&gt;: Enforces the names of some block params.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Style/StringHashKeys&lt;/code&gt;: Prefer symbols instead of strings as hash keys.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's check out one that I personally like the most, the ClassStructure cop residing in the Layout department.&lt;/p&gt;

&lt;p&gt;As its description states, &lt;code&gt;Layout/ClassStructure&lt;/code&gt; enforces a configured order of definitions within a class body. There are multiple things that can be included in the Ruby class, and thanks to this cop we can make sure that all the classes written in the codebase define them in the custom or default order:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;include&lt;/li&gt;
&lt;li&gt;prepend&lt;/li&gt;
&lt;li&gt;constants&lt;/li&gt;
&lt;li&gt;initializer&lt;/li&gt;
&lt;li&gt;public, private and protected methods&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next to those, there are multiple other &lt;code&gt;Layout&lt;/code&gt;, &lt;code&gt;Lint&lt;/code&gt; and &lt;code&gt;Style&lt;/code&gt; cops, that put together remind me of some very wise words that I've read a long time ago.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Any codebase should look like it is written by a single person.&lt;/p&gt;

&lt;p&gt;"Clean Code" by Robert Cecil Martin&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is the effect you might accomplish via the disabled by default RuboCop configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;RuboCop is a very powerful and the most popular code linting tool for the Ruby language.&lt;/p&gt;

&lt;p&gt;Its configuration is not rocket science, so the amount of community knowledge on writing a clean, easily maintainable code comes with a very low price - all it takes is installing a few gems and writing a simple YAML file.&lt;/p&gt;

&lt;p&gt;The only justification of not using it is knowing all those rules by heart - and I seriously doubt that there's a lot of people who do.&lt;/p&gt;

&lt;p&gt;Using RuboCop when developing Ruby on Rails applications helps developers to avoid common mistakes, guards from the code formatting discrepancies and allows them to create a codebase that is well maintained and easy to understand.&lt;/p&gt;

&lt;p&gt;Use RuboCop in your Ruby on Rails projects, period.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>tutorial</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Quick guide on Ruby on Rails Continuous Integration with GitlabCI - why it's worth and how to get it running.</title>
      <dc:creator>hix.dev</dc:creator>
      <pubDate>Thu, 30 Jan 2020 13:42:18 +0000</pubDate>
      <link>https://forem.com/hixdevs/quick-guide-on-ruby-on-rails-continuous-integration-with-gitlabci-why-it-s-worth-and-how-to-get-it-running-23jg</link>
      <guid>https://forem.com/hixdevs/quick-guide-on-ruby-on-rails-continuous-integration-with-gitlabci-why-it-s-worth-and-how-to-get-it-running-23jg</guid>
      <description>&lt;p&gt;This is the ultimate guide for your next Ruby on Rails project setup on Gitlab with GitlabCI for continuous integration in 2020.&lt;/p&gt;

&lt;p&gt;You can find original, &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-set-up-on-gitlab-with-gitlabci/" rel="noopener noreferrer"&gt;1:1 version on our website&lt;/a&gt; - feel invited! &lt;/p&gt;

&lt;p&gt;Let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Gitlab?
&lt;/h2&gt;

&lt;p&gt;Gitlab is, among all the other DevOps related features, one of the top git remote hosting cloud providers, next to Microsoft's Github and Atlassian's Bitbucket.&lt;/p&gt;

&lt;p&gt;It can be both self-hosted or used via provided web UI on &lt;a href="https://about.gitlab.com/" rel="noopener noreferrer"&gt;an official website&lt;/a&gt;. Like the other two giants, it offers an unlimited amount of public and private repositories, with limited users access extendable with a paid plan.&lt;/p&gt;

&lt;p&gt;Fun fact is that both &lt;a href="https://stackshare.io/gitlab/gitlab" rel="noopener noreferrer"&gt;Ruby and Ruby on Rails are a big part of the Gitlab's tech stack&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgximk4mglxcuzyutg4r4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgximk4mglxcuzyutg4r4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Gitlab allows its users to integrate various pipelines into the code lifecycle, providing powerful GitlabCI, which should be rather called GitlabCD, for Continuous Delivery, as it equips developers with everything that's necessary to deliver code from their workstations straight to the production servers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Gitlab for Ruby on Rails app?
&lt;/h2&gt;

&lt;p&gt;Creating constant backups of your code without using git or any other version control system would be true horror. Gitlab's biggest advantage for Ruby on Rails and projects written with any other frameworks is that on top of checkpoints in your codebase saved locally, you can host them in the cloud.&lt;/p&gt;

&lt;p&gt;An ability to roll back to the older version of the code in case of introducing bugs in newer releases is yet another life-saving feature of Gitlab and other git remote hosting providers.&lt;/p&gt;

&lt;p&gt;Another advantage is that with its massive usage as a self-hosted remote git repository solution there's a big chance that anybody that is going to collaborate with your code is going to know how to use Gitlab, so statistically, a learning curve is gone.&lt;/p&gt;

&lt;p&gt;Thanks to its intuitive UI, Merge Requests, Code Review and Forks, Gitlab allows developers to easily work together.&lt;/p&gt;

&lt;p&gt;On top of all that, it introduces its own, very advanced &lt;a href="https://docs.gitlab.com/ee/topics/gitlab_flow.html" rel="noopener noreferrer"&gt;git branching strategy called GitLab flow&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continuous Integration for Ruby on Rails
&lt;/h2&gt;

&lt;p&gt;Continuous Integration (CI) in a programming world is a widely accepted practice that requires developers to push their work to the shared codebase continuously, ideally several times a day.&lt;/p&gt;

&lt;p&gt;On top of general usages such as building programs and running the test suite against new features, new code might be verified against static code analysis tools knowledge base, pinpointing security vulnerabilities, common stylistic mistakes and all different kinds of inaccuracies.&lt;/p&gt;

&lt;p&gt;Continuous Integration pipelines are a great place to ensure high code quality, well, continuously, which is good for both programmers and software itself.&lt;/p&gt;

&lt;p&gt;There are multiple open-source static code analysis tools available for both Ruby and Ruby on Rails.&lt;/p&gt;

&lt;p&gt;Most of them can be set up on the CI server to audit the code of Ruby on Rails project every time it's pushed, or nightly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use GitlabCI for Ruby on Rails app?
&lt;/h2&gt;

&lt;p&gt;GitlabCI is Gitlab's own solution for Continuous Integration and Delivery, hosted in its cloud.&lt;/p&gt;

&lt;p&gt;It is tightly integrated with Gitlab repository hosting, turned on by default, so every time you create a new repository on Gitlab all you need to do in order to turn on its Continuous Integration solution for your project is providing a correct configuration file, .gitlab-ci.yml.&lt;/p&gt;

&lt;p&gt;There are several shared runners available, so there's no need for your custom CI server maintenance (hello Jenkins), just one YAML file and you're all set.&lt;/p&gt;

&lt;p&gt;No credit card information required, a perfect combination to start small with your project and pay for what you use as you grow.&lt;/p&gt;

&lt;p&gt;GitlabCI provides an intuitive, well-organized UI with all the information required to establish the problem that occurs when the new code was integrated into the Gitlab hosted codebase.&lt;/p&gt;

&lt;p&gt;It is crucial to set up the Continuous Integration system for any project, let alone Ruby on Rails, from the first day of the development.&lt;/p&gt;

&lt;p&gt;This is a great way to avoid a lot of technical debt, protect yourself from common mistakes and enforce certain standards that make working with Ruby on Rails codebase pleasing and its maintenance much, much easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Ruby on Rails project on Gitlab
&lt;/h2&gt;

&lt;p&gt;Follow the instructions below to create your Gitlab account and set up the Ruby on Rails project.&lt;/p&gt;

&lt;p&gt;1.Sign up on the &lt;a href="https://gitlab.com/users/sign_up" rel="noopener noreferrer"&gt;official Gitlab website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8ebw2ncqpocf55t5o5wd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8ebw2ncqpocf55t5o5wd.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.Verify your email and complete the simple account creation wizard.&lt;br&gt;
3.When successfully logged in, select "Create project".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp6cwy72lu0p0j7aids3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp6cwy72lu0p0j7aids3m.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.Provide a project name and click "Create project".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fx8jvec0nono2w9wm8tw5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fx8jvec0nono2w9wm8tw5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5.Copy your new project's URL to the clipboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Feugb9u16qvsk6ziynycs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Feugb9u16qvsk6ziynycs.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6.If you are using &lt;a href="https://hixonrails.com/" rel="noopener noreferrer"&gt;Hix on Rails&lt;/a&gt;, that's all you are going to need for now, just paste the address into the CLI when asked for it.&lt;br&gt;
7.Navigate to the Ruby on Rails project root directory in the command line and enter &lt;code&gt;git remote add origin YOUR_REPOSITORY_URL&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Ruby on Rails project with GitlabCI pipelines
&lt;/h2&gt;

&lt;p&gt;If you are using &lt;a href="https://hixonrails.com/" rel="noopener noreferrer"&gt;Hix on Rails&lt;/a&gt; - that's it. Your pipeline will run with all the code quality checks selected in the installation wizard upon the first push the remote. Beware that it will initially fail unless you create any database migration, as it is necessary for the database to be created.&lt;/p&gt;

&lt;p&gt;Otherwise, if you still on the copy/paste duty instead of automating that part of your life, follow the steps below for Ruby on Rails project configuration on the GitlabCI.&lt;/p&gt;

&lt;p&gt;In your project root, create the required GitlabCI configuration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;cd path/to/your/project/root&lt;/span&gt;
&lt;span class="s"&gt;touch .gitlab-ci.yml&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the GitlabCI configuration file with a text editor of your choice and paste the basic code required, depending on which database you use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails with PostgreSQL on GitlabCI
&lt;/h2&gt;

&lt;p&gt;PostgreSQL is the most popular choice for Ruby on Rails projects.&lt;/p&gt;

&lt;p&gt;For the GitlabCI to test your application along with PostgreSQL you are going to need a specific setup in the &lt;code&gt;config/database.yml&lt;/code&gt; file. We use the &lt;a href="https://github.com/bkeepers/dotenv" rel="noopener noreferrer"&gt;dotenv-rails&lt;/a&gt; gem.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;config/database.yml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;default: &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;
  &lt;span class="ss"&gt;adapter: &lt;/span&gt;&lt;span class="n"&gt;postgresql&lt;/span&gt;
  &lt;span class="ss"&gt;encoding: &lt;/span&gt;&lt;span class="n"&gt;unicode&lt;/span&gt;
  &lt;span class="ss"&gt;pool: &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= ENV['DB_POOL'] %&amp;gt;
  username: &amp;lt;%=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'DB_USERNAME'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="ss"&gt;password: &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= ENV['DB_PASSWORD'] %&amp;gt;
  host: &amp;lt;%=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'DB_HOST'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="ss"&gt;port: &lt;/span&gt;&lt;span class="mi"&gt;5432&lt;/span&gt;

&lt;span class="ss"&gt;development:
  &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;hix_postgresql_development&lt;/span&gt;

&lt;span class="ss"&gt;test:
  &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;hix_postgresql_test&lt;/span&gt;

&lt;span class="ss"&gt;production:
  &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;hix_postgresql_development&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you decided to go with it, here's the basic GitlabCI configuration for the Ruby on Rails project build with the PostgreSQL database.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.gitlab-ci.yml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;stages:
  &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;test&lt;/span&gt;

&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="ss"&gt;image: &lt;/span&gt;&lt;span class="n"&gt;ruby&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;2.6&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="ss"&gt;cache:
    key: &lt;/span&gt;&lt;span class="n"&gt;rat&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;
    &lt;span class="ss"&gt;paths:
      &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
      &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;vendor&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ruby&lt;/span&gt;
      &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;node_modules&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
    &lt;span class="ss"&gt;policy: &lt;/span&gt;&lt;span class="n"&gt;pull&lt;/span&gt;
  &lt;span class="ss"&gt;before_script:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;bundler&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;no&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;jobs&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nproc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;"${FLAGS[@]}"&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;vendor&lt;/span&gt;

&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="ss"&gt;extends: &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;
  &lt;span class="ss"&gt;services:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;postgres&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;12.0&lt;/span&gt;
  &lt;span class="ss"&gt;variables:
    &lt;/span&gt;&lt;span class="no"&gt;POSTGRES_USER&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;hix_postgresql&lt;/span&gt;
    &lt;span class="no"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;hixonrails&lt;/span&gt;
    &lt;span class="no"&gt;DB_USERNAME&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;hix_postgresql&lt;/span&gt;
    &lt;span class="no"&gt;DB_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;hixonrails&lt;/span&gt;
    &lt;span class="no"&gt;DB_HOST&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;postgres&lt;/span&gt;
    &lt;span class="no"&gt;RAILS_ENV&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;test&lt;/span&gt;
    &lt;span class="no"&gt;DISABLE_SPRING&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="no"&gt;BUNDLE_PATH&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;vendor&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bundle&lt;/span&gt;
  &lt;span class="ss"&gt;before_script:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;export&lt;/span&gt; &lt;span class="no"&gt;APT_CACHE_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`pwd`&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;mkdir&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;pv&lt;/span&gt; &lt;span class="vg"&gt;$APT_CACHE_DIR&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;qq&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="n"&gt;dir&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;archives&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$APT_CACHE_DIR"&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;yqq&lt;/span&gt; &lt;span class="n"&gt;nodejs&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;bundler&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;no&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;jobs&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nproc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;"${FLAGS[@]}"&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;vendor&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="n"&gt;rails&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="ss"&gt;:create&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="ss"&gt;:schema:load&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;trace&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As is, this file will fail the pipeline, it is only a strong foundation for further jobs presented in the guide.&lt;/p&gt;

&lt;p&gt;Adjust the configuration file for this code to work with your project:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the build Ruby image, line 6, adjust your Ruby version. At the time of writing this article the last stable version is used, 2.6.5.&lt;/li&gt;
&lt;li&gt;In the database PostgreSQL image, line 20, adjust your PostgreSQL version. At the time of writing this article, the last stable version is used, 12.0.&lt;/li&gt;
&lt;li&gt;You can freely change corresponding user and password values, respectively in lines 22 - 24 and 23 - 25, however it's not mandatory.&lt;/li&gt;
&lt;li&gt;Replace all occurrences of the "hix_postgresql" with your Ruby on Rails project name.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is important for the Continuous Integration suite to run on an environment as close to your production as possible.&lt;/p&gt;

&lt;p&gt;To check your local PostgreSQL version, run the following command in the CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;psql -V&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are developing some serious Ruby on Rails project, it is the best moment to install the &lt;a href="https://www.postgresql.org/" rel="noopener noreferrer"&gt;latest stable version of the PostgreSQL database&lt;/a&gt;. If not, &lt;a href="https://hub.docker.com/_/postgres" rel="noopener noreferrer"&gt;find the Docker PostgreSQL image corresponding to your local database version&lt;/a&gt; and adjust the GitlabCI configuration file accordingly.&lt;/p&gt;

&lt;p&gt;Follow the next steps to actually use defined images in your continuous integration workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails with MySQL on GitlabCI
&lt;/h2&gt;

&lt;p&gt;MySQL is the second most popular choice for Ruby on Rails applications, just behind the PostgreSQL.&lt;/p&gt;

&lt;p&gt;For the MySQL to work you, same as with PostgreSQL, you are going to need a setup in the &lt;code&gt;config/database.yml&lt;/code&gt; file adjusted to the one configuring the GitlabCI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;default: &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;
  &lt;span class="ss"&gt;adapter: &lt;/span&gt;&lt;span class="n"&gt;mysql2&lt;/span&gt;
  &lt;span class="ss"&gt;encoding: &lt;/span&gt;&lt;span class="n"&gt;utf8&lt;/span&gt;
  &lt;span class="ss"&gt;pool: &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= ENV['DB_POOL'] %&amp;gt;
  username: &amp;lt;%=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'DB_USERNAME'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="ss"&gt;password: &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= ENV['DB_PASSWORD'] %&amp;gt;
  host: &amp;lt;%=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'DB_HOST'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="ss"&gt;port: &lt;/span&gt;&lt;span class="mi"&gt;3306&lt;/span&gt;

&lt;span class="ss"&gt;development:
  &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;hix_mysql_development&lt;/span&gt;

&lt;span class="ss"&gt;test:
  &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;hix_mysql_test&lt;/span&gt;

&lt;span class="ss"&gt;production:
  &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;hix_mysql_production&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If that's your choice, here's the basic GitlabCI configuration for the Ruby on Rails project build with the MySQL database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;stages:
  &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;test&lt;/span&gt;

&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="ss"&gt;image: &lt;/span&gt;&lt;span class="n"&gt;ruby&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;2.6&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="ss"&gt;cache:
    key: &lt;/span&gt;&lt;span class="n"&gt;rat&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;
    &lt;span class="ss"&gt;paths:
      &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
      &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;vendor&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ruby&lt;/span&gt;
      &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;node_modules&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
    &lt;span class="ss"&gt;policy: &lt;/span&gt;&lt;span class="n"&gt;pull&lt;/span&gt;
  &lt;span class="ss"&gt;before_script:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;bundler&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;no&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;jobs&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nproc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;"${FLAGS[@]}"&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;vendor&lt;/span&gt;

&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="ss"&gt;extends: &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;
  &lt;span class="ss"&gt;services:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="n"&gt;mysql&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;8.0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;18&lt;/span&gt;
      &lt;span class="ss"&gt;command: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'--default-authentication-plugin=mysql_native_password'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="ss"&gt;variables:
    &lt;/span&gt;&lt;span class="no"&gt;MYSQL_ROOT_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;hixonrails&lt;/span&gt;
    &lt;span class="no"&gt;DB_USERNAME&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;
    &lt;span class="no"&gt;DB_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;hixonrails&lt;/span&gt;
    &lt;span class="no"&gt;DB_HOST&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;mysql&lt;/span&gt;
    &lt;span class="no"&gt;RAILS_ENV&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;test&lt;/span&gt;
    &lt;span class="no"&gt;DISABLE_SPRING&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="no"&gt;BUNDLE_PATH&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;vendor&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bundle&lt;/span&gt;
  &lt;span class="ss"&gt;before_script:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;export&lt;/span&gt; &lt;span class="no"&gt;APT_CACHE_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`pwd`&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;mkdir&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;pv&lt;/span&gt; &lt;span class="vg"&gt;$APT_CACHE_DIR&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;qq&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="n"&gt;dir&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;archives&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$APT_CACHE_DIR"&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;yqq&lt;/span&gt; &lt;span class="n"&gt;nodejs&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;bundler&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;no&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;jobs&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nproc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;"${FLAGS[@]}"&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;vendor&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="n"&gt;rails&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="ss"&gt;:create&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="ss"&gt;:schema:load&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;trace&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It needs a few tweaks in order to work with your particular project. Do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the build Ruby image, line 6, adjust your Ruby version. At the time of writing this article the last stable version is used, 2.6.5.&lt;/li&gt;
&lt;li&gt;In the database MySQL image, line 21, adjust your MySQL version. At the time of writing this article, the last stable version is used, 12.0.&lt;/li&gt;
&lt;li&gt;You can freely change corresponding root password values, respectively in lines 24 - 26, however, it's not mandatory.&lt;/li&gt;
&lt;li&gt;Replace all occurrences of the "hix_postgresql" with your Ruby on Rails project name.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Be aware that those are only images to extend in order to use them for the jobs to follow and they do nothing by themselves, as they do not belong to any of the stages defined at the beginning of the GitlabCI configuration file.&lt;/p&gt;

&lt;p&gt;I am going to state that again, in case you skipped the PostgreSQL section: it is important for the Continuous Integration suite to run on an environment as close to your production as possible.&lt;/p&gt;

&lt;p&gt;Take a moment now to check your local MySQL version. In your local CLI, type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;mysql -V&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and do one of the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Best: Update your local MySQL version to the latest stable one.&lt;/li&gt;
&lt;li&gt;Good: Update your GitlabCI docker image to the one matching your local version - check an official Docker MySQL images&lt;/li&gt;
&lt;li&gt;Bad: Do nothing (in case versions differ, because if they don't your technically in point 2).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you went with the local update alternative, your future self is smiling at you right now. The second point is probably the most common choice, as all it takes is editing the configuration file.&lt;/p&gt;

&lt;p&gt;The third option is plain wrong and it will cost you more time than it's worth it, eventually - go back to point 2.&lt;/p&gt;

&lt;p&gt;Now that we have the installed bundle with our Ruby on Rails applications database ready to use, let's see what we can use them to run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails with RSpec on GitlabCI
&lt;/h2&gt;

&lt;p&gt;RSpec is the favorite choice of the Ruby and Ruby on Rails community for writing tests.&lt;/p&gt;

&lt;p&gt;It is important to check if newly developed features did not break older parts of the codebase and the Continuous Integration flow is a great place to do it. If you enforce the full test suite run from the Ruby on Rails application day one and agree with your team on some rational test coverage you will not regret it.&lt;/p&gt;

&lt;p&gt;Speaking of the code coverage, there are great tools like SimpleCov, the Ruby gem for generating test coverage reports that hooked up with a &lt;a href="https://coveralls.io/" rel="noopener noreferrer"&gt;Coveralls&lt;/a&gt; always tell you what's codebase code coverage at a glance, from the &lt;code&gt;README.md&lt;/code&gt; badge level.&lt;/p&gt;

&lt;p&gt;The Continuous Integration part of checking Ruby on Rails application tests health is really easy, all it takes is to store the results in the CI environment after the suite run. Reporting part comes in the RSpec configuration, you can read about it in the Ruby on Rails tested with RSpec article.&lt;/p&gt;

&lt;p&gt;Overall, running the test suite of the Ruby on Rails project is the perfect job for the GitlabCI, so let's get to it.&lt;/p&gt;

&lt;p&gt;Edit your GitlabCI configuration file with the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;rspec:
  extends: &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;db&lt;/span&gt;
  &lt;span class="ss"&gt;stage: &lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt;
  &lt;span class="ss"&gt;cache:
    policy: &lt;/span&gt;&lt;span class="n"&gt;pull&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;push&lt;/span&gt;
  &lt;span class="ss"&gt;artifacts:
    name: &lt;/span&gt;&lt;span class="n"&gt;coverage&lt;/span&gt;
    &lt;span class="ss"&gt;paths:
      &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;coverage&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
  &lt;span class="ss"&gt;script:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="n"&gt;rspec&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt; &lt;span class="n"&gt;progress&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can skip the artifacts part of the job if you did not bother with SimpleCov configuration, but you don't have to. It is always possible to browse the coverage results from the GitlabCI level.&lt;/p&gt;

&lt;p&gt;Another thing that's happening here is the profiling flag of our RSpec script - given the integer 10, it will show us the ten slowest unit tests in the whole suite.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails with RuboCop on GitlabCI
&lt;/h2&gt;

&lt;p&gt;RuboCop is the Ruby and Ruby on Rails community favorite linting tool. It checks the code against almost four hundred rules in its default configuration.&lt;/p&gt;

&lt;p&gt;Along with the default gem corresponding to a Ruby Styleguide website, there are RuboCop extensions encapsulated in the separated gems for some of the most popular Ruby frameworks, including Ruby on Rails and RSpec.&lt;/p&gt;

&lt;p&gt;On top of that, there's another gem authored by RuboCop Headquarters specifically checking the Ruby code performance, called, you guessed it, rubocop-performance.&lt;/p&gt;

&lt;p&gt;If you decided to use the RuboCop in your Ruby on Rails project, the GitlabCI continuous integration suite is the place to do it - this way you can always be sure that your code is kept up to the RuboCop standard.&lt;/p&gt;

&lt;p&gt;Edit the GitlabCI configuration file of your Ruby on Rails project with the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;rubocop:
  extends: &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;
  &lt;span class="ss"&gt;stage: &lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt;
  &lt;span class="ss"&gt;cache:
    policy: &lt;/span&gt;&lt;span class="n"&gt;pull&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;push&lt;/span&gt;
  &lt;span class="ss"&gt;script:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="n"&gt;rubocop&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The RuboCop job does not require a Docker database image. We simply extend bare build, in which the gems bundle is installed - this way your CI runs faster every time.&lt;/p&gt;

&lt;p&gt;For the complete RuboCop setup for Ruby on Rails applications using RSpec, please read the &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-project-rubocop-setup-with-rspec/" rel="noopener noreferrer"&gt;Ruby on Rails project RuboCop setup with RSpec&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails with Brakeman on GitlabCI
&lt;/h2&gt;

&lt;p&gt;If you keep the security of the Ruby on Rails project in mind, Brakeman is the way to go.&lt;/p&gt;

&lt;p&gt;It is a simple command-line tool that checks the Ruby on Rails codebase against known security vulnerabilities, including &lt;a href="https://rails-sqli.org/" rel="noopener noreferrer"&gt;SQL Injection&lt;/a&gt; and &lt;a href="https://excess-xss.com/" rel="noopener noreferrer"&gt;Cross-Site Scripting&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The GitlabCI Continuous Integration suite is the best place to check your code against Brakeman's knowledge of breaking Ruby on Rails stuff. If you decided to use it, edit your configuration file with the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;brakeman:
  extends: &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;
  &lt;span class="ss"&gt;stage: &lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt;
  &lt;span class="ss"&gt;cache:
    policy: &lt;/span&gt;&lt;span class="n"&gt;pull&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;push&lt;/span&gt;
  &lt;span class="ss"&gt;script:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="n"&gt;brakeman&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;rails6&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;A&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same as the RuboCop job, Brakeman does not need the Docker database image in order to run, so we save ourselves a few seconds every time and extend the bare build one.&lt;/p&gt;

&lt;p&gt;Remember, that using any security audit tool does not guarantee that your Ruby on Rails application is 100% safe. Please read the &lt;a href="https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project" rel="noopener noreferrer"&gt;Open Web Application Security Project Top 10 Project&lt;/a&gt; and on top of other things, audit your website regularly with tools like Mozilla Observatory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails with Fasterer on GitlabCI
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/DamirSvrtan/fasterer" rel="noopener noreferrer"&gt;Fasterer&lt;/a&gt; is a static Ruby code analysis command-line tool that corresponds to the open-source project called &lt;a href="https://github.com/JuanitoFatas/fast-ruby" rel="noopener noreferrer"&gt;Fast Ruby&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is the single biggest website with up-to-date benchmarks of various Ruby methods that are able to achieve the same goal, which allows programmers to find the fastest tool for a lot of stuff done with Ruby.&lt;/p&gt;

&lt;p&gt;If you decide to use the Fasterer in your Ruby on Rails project, here's the GitlabCI Continuous Integration configuration for running the static performance analysis against the codebase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;fasterer:
  extends: &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;
  &lt;span class="ss"&gt;stage: &lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt;
  &lt;span class="ss"&gt;cache:
    policy: &lt;/span&gt;&lt;span class="n"&gt;pull&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;push&lt;/span&gt;
  &lt;span class="ss"&gt;script:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="n"&gt;fasterer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One configuration tweak worth pointing out and included in the example fasterer repository configuration file is to turn off &lt;code&gt;each.with_index&lt;/code&gt; vs a &lt;code&gt;while&lt;/code&gt; loop comparison when using with Ruby on Rails applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails with Rails Best Practices on GitlabCI
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://rails-bestpractices.com/" rel="noopener noreferrer"&gt;Rails Best Practices&lt;/a&gt; is a Ruby on Rails blog by Xinmin Labs, with its last article written in 2014. Do not give up on it though, as most of its wisdom is still applicable now, and it is safe to say that it will be for a long time.&lt;/p&gt;

&lt;p&gt;Next to the old but gold read, there's a &lt;a href="https://github.com/flyerhzm/rails_best_practices" rel="noopener noreferrer"&gt;static code analysis tool with the same "Rails Best Practices"&lt;/a&gt; name. It reports all the code violating the guidelines thoroughly explained on the website.&lt;/p&gt;

&lt;p&gt;If you decide to follow the Rails Best Practices, your GitlabCI Continuous Integration suite for the Ruby on Rails project is the best place to do so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;rails_best_practices:
  extends: &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;
  &lt;span class="ss"&gt;stage: &lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt;
  &lt;span class="ss"&gt;cache:
    policy: &lt;/span&gt;&lt;span class="n"&gt;pull&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;push&lt;/span&gt;
  &lt;span class="ss"&gt;script:
    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="n"&gt;rails_best_practices&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this small additional GitlabCI configuration comes a lot of good stuff that will keep your Ruby on Rails codebase safe and sound, pointing out common mistakes that are otherwise easy to forget.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Gitlab is a very popular choice for Ruby on Rails applications remote version control and it comes with many benefits, one of which is its tremendous help in the DevOps world.&lt;/p&gt;

&lt;p&gt;GitlabCI is a powerful yet very easy to set up cloud suite for Continuous Integration and Delivery, and it comes built-in and ready to use with every new Gitlab repository, for free.&lt;/p&gt;

&lt;p&gt;A lot of Ruby on Rails community knowledge about how to do things correctly was forged into static code analysis tools.&lt;/p&gt;

&lt;p&gt;Enforcing the standardized style guide for your Ruby on Rails application via GitlabCI jobs and pipelines is a great way to both learn the framework better and save yourself some trouble in the future.&lt;/p&gt;

&lt;p&gt;Again, if you wish to help us in growing our tutorial base, please share this article to your dev friends! Kudos!&lt;/p&gt;

&lt;p&gt;You can also take a look at &lt;a href="https://hixonrails.com" rel="noopener noreferrer"&gt;Hix&lt;/a&gt; which we've made with love for Rails developers.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>tutorial</category>
      <category>git</category>
    </item>
    <item>
      <title>Why you should use Rollbar logger in your Rails project and how to configure it</title>
      <dc:creator>hix.dev</dc:creator>
      <pubDate>Fri, 17 Jan 2020 13:27:58 +0000</pubDate>
      <link>https://forem.com/hixdevs/why-you-should-use-rollbar-logger-in-your-rails-project-and-how-to-configure-it-1jij</link>
      <guid>https://forem.com/hixdevs/why-you-should-use-rollbar-logger-in-your-rails-project-and-how-to-configure-it-1jij</guid>
      <description>&lt;p&gt;This is the step by step guide to install and configure Rollbar logger in the Ruby on Rails project in 2020.&lt;/p&gt;

&lt;p&gt;You can find the original, 1:1 piece on &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-rollbar-logger-installation-and-configuration/"&gt;Rails + Rollbar configuration&lt;/a&gt; on our website.&lt;/p&gt;

&lt;p&gt;Let's jump right into it, you'll see how easy it is to have error-free Rails application!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Rollbar?
&lt;/h2&gt;

&lt;p&gt;Rollbar is a realtime application monitoring and error tracking software which one can visit anytime via a web browser.&lt;/p&gt;

&lt;p&gt;Applications can communicate with Rollbar via the HTTP protocol, sending data about their crashes and exceptions.&lt;/p&gt;

&lt;p&gt;Developers subscribe to Rollbar's notifications and can almost instantly react to production problems by easily pinpointing them via sophisticated UI, which provides a complete set of data necessary for the job.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Rollbar with Ruby on Rails?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;It is free to use up to 5000 API requests per month.&lt;/li&gt;
&lt;li&gt;It gathers more data than the default Ruby on Rails logger.&lt;/li&gt;
&lt;li&gt;It provides an intuitive UI, which is more comfortable to work with than primitive log files.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ruby on Rails is provided with a basic logger that writes to the selected file, or files. Reading a single file with the constantly appended massive stack traces is a primitive way to monitor the application.&lt;/p&gt;

&lt;p&gt;Rollbar collects and aggregates Ruby on Rails application crashes and exceptions data, with an additional context, such as a suspected release that started to cause the problem.&lt;/p&gt;

&lt;p&gt;Via a sophisticated Rollbar web UI developer can browse errors by the latest, most occurrent and multiple additional pieces of information provided.&lt;/p&gt;

&lt;p&gt;I cannot stress enough how crucial it is that your Ruby on Rails application is hooked up with an advanced logging and monitoring system such as Rollbar from its day one on production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rollbar account and project setup
&lt;/h2&gt;

&lt;p&gt;Follow the instructions below to create your Rollbar account and set up Ruby on Rails project for further monitoring.&lt;/p&gt;

&lt;p&gt;1.Sign up on the official &lt;a href="https://rollbar.com/signup/"&gt;Rollbar website&lt;/a&gt;. By default, every email from your email domain will be allowed to join.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UVdizH3V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/pbllj96vqfhwvthdxv7e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UVdizH3V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/pbllj96vqfhwvthdxv7e.png" alt="Alt Text" width="644" height="746"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.Verify your email and set up your user credentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v6SB8Cwe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/potp7rfmnt47bd6yaq8s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v6SB8Cwe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/potp7rfmnt47bd6yaq8s.png" alt="Alt Text" width="638" height="612"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.You'll be taken to the Quick Setup Overview. The first step is to create your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_ZgxN6ML--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wobdm3j4p7945leru493.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_ZgxN6ML--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wobdm3j4p7945leru493.png" alt="Alt Text" width="670" height="692"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.Enter your project name and press "Continue".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pJiARvxP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/kx5j7nz3wh5pd98deugj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pJiARvxP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/kx5j7nz3wh5pd98deugj.png" alt="Alt Text" width="670" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5.In the next step, select "Rails" for your project SDK.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tT-ytLpY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/l05oc9pmjkvytbqmx6rr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tT-ytLpY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/l05oc9pmjkvytbqmx6rr.png" alt="Alt Text" width="670" height="778"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6.Copy your Rollbar Access Token from the last step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I2OOq0sS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8442ibarb582tb02dojl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I2OOq0sS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8442ibarb582tb02dojl.png" alt="Alt Text" width="670" height="742"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rollbar allows you to set up multiple organization's projects and monitor them all via single web UI, which comes very handy especially for multiple services monitored daily.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rollbar installation in Ruby on Rails project
&lt;/h2&gt;

&lt;p&gt;If you use &lt;a href="https://hixonrails.com"&gt;Hix on Rails&lt;/a&gt;, your job is done here, all you gonna do is paste your Rollbar Access Key into the first step of the Hix on Rails project initialization wizard.&lt;/p&gt;

&lt;p&gt;Otherwise, if you sadly did not automate that part of your life yet, follow steps below for Ruby on Rails Rollbar configuration.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open your projects &lt;code&gt;Gemfile&lt;/code&gt; and paste the gem 'rollbar' so it's available for every environment.&lt;/li&gt;
&lt;li&gt;In a command-line navigate to the project's directory, enter &lt;code&gt;bundle install&lt;/code&gt; and while it runs go to the next step.&lt;/li&gt;
&lt;li&gt;Create the &lt;code&gt;config/rollbar.rb&lt;/code&gt; file and paste the minimal configuration required, replacing the value with previously copied Rollbar Access Key.&lt;/li&gt;
&lt;li&gt;Create the &lt;code&gt;config/initializers/rollbar.rb&lt;/code&gt; file to wrap a default &lt;code&gt;Rails.logger&lt;/code&gt; so whenever you use it, the results are visible in the Rollbar UI.&lt;/li&gt;
&lt;li&gt;To report exceptions occurring in the Ruby on Rails booting process add the code to the &lt;code&gt;config/environment.rb&lt;/code&gt; file, as Rails does not provide a way to hook into it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;config/rollbar.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# frozen_string_literal: true&lt;/span&gt;

&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;access_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'YOUR_ROLLBAR_ACCESS_TOKEN_GOES_HERE'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;config/rollbar.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# frozen_string_literal: true&lt;/span&gt;

&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ActiveSupport&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;broadcast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;config/environment.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# frozen_string_literal: true&lt;/span&gt;

&lt;span class="nb"&gt;require_relative&lt;/span&gt; &lt;span class="s1"&gt;'application'&lt;/span&gt;
&lt;span class="nb"&gt;require_relative&lt;/span&gt; &lt;span class="s1"&gt;'rollbar'&lt;/span&gt;

&lt;span class="n"&gt;notify&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="k"&gt;begin&lt;/span&gt;
    &lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;with_config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;use_async: &lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
      &lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;rescue&lt;/span&gt;
    &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt; &lt;span class="s1"&gt;'Synchronous Rollbar notification failed.  Sending async to preserve info'&lt;/span&gt;
    &lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;begin&lt;/span&gt;
  &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;initialize!&lt;/span&gt;
&lt;span class="k"&gt;rescue&lt;/span&gt; &lt;span class="no"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
  &lt;span class="n"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;raise&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a minimal setup required to hook up your Ruby on Rails application with your newly created Rollbar account, via the dedicated &lt;a href="https://github.com/rollbar/rollbar-gem"&gt;rollbar gem&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is overall a better idea to not store credentials in your project repository and use dedicated environmental management instead. For example, if you use a &lt;a href="https://github.com/bkeepers/dotenv"&gt;dotenv-rails gem&lt;/a&gt;, it is a better idea to provide your DSN via the &lt;code&gt;.env&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.env&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ROLLBAR_ACCESS_KEY=YOUR_ROLLBAR_ACCESS_TOKEN_GOES_HERE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;config/rollbar.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# frozen_string_literal: true&lt;/span&gt;

&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;access_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ROLLBAR_ACCESS_TOKEN'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see what other configuration options are worth tweaking while monitoring Ruby on Rails project with Rollbar.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails Rollbar configuration
&lt;/h2&gt;

&lt;p&gt;With the minimalistic setup, we started to report Ruby on Rails application exceptions to the Rollbar.&lt;/p&gt;

&lt;p&gt;Rollbar default configuration with the access key passed at this point is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;access_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ROLLBAR_ACCESS_TOKEN'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;async_handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;before_process&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;capture_uncaught&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;code_version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;custom_data_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;default_logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;lambda&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;STDERR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logger_level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;:info&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delayed_job_enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;disable_monkey_patch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;disable_core_monkey_patch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;disable_rack_monkey_patch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dj_threshold&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt; &lt;span class="c1"&gt;# set to true when configure is called&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endpoint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DEFAULT_ENDPOINT&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;environment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exception_level_filters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s1"&gt;'ActiveRecord::RecordNotFound'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'warning'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'AbstractController::ActionNotFound'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'warning'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'ActionController::RoutingError'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'warning'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;failover_handlers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;framework&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Plain'&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ignored_person_ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;payload_options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;person_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'current_user'&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;person_id_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'id'&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;person_username_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;person_email_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;project_gems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;populate_empty_backtraces&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;report_dj_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open_timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request_timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;net_retries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;js_enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;js_options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;locals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrub_fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:passwd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:password_confirmation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:secret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="ss"&gt;:confirm_password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:password_confirmation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:secret_token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="ss"&gt;:api_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:access_token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:accessToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:session_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrub_user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrub_password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;randomize_scrub_length&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrub_whitelist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uncaught_exception_level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'error'&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrub_headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'Authorization'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sidekiq_threshold&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;safely&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transform&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use_async&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use_eventmachine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify_ssl_peer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;web_base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DEFAULT_WEB_BASE&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_to_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_extra_frame_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;:none&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;project_gem_paths&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use_exception_level_filters_default&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;proxy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_on_error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transmit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log_payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collect_user_ip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;anonymize_user_ip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;backtrace_cleaner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hooks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="ss"&gt;:on_error_response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# params: response&lt;/span&gt;
    &lt;span class="ss"&gt;:on_report_internal_error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt; &lt;span class="c1"&gt;# params: exception&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configured_options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ConfiguredOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Environments setup
&lt;/h2&gt;

&lt;p&gt;Using Rollbar reporting in the test and development environments is an overkill. You can set up when it's enabled via the configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;%w[production staging]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;include?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to give your custom name to the environment, you can do that by yet another environment-related configuration option.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;environment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'your_custom_environment_name'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Asynchronous reporting
&lt;/h2&gt;

&lt;p&gt;Error logging is not the primary task of most of the web applications, including Ruby on Rails. It is good to keep it asynchronous, and Rollbar allows users to do so by exposing the asynchronous configuration for the most popular choices of asynchronous code execution in Ruby.&lt;/p&gt;

&lt;p&gt;Sidekiq integration with Rollbar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use_sidekiq&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;queue: :rollbar&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SuckerPunch integration with Rollbar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use_sucker_punch&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GirlFriday integration with Rollbar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use_async&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;DelayedJob integration with Rollbar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delayed_job_enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use_delayed_job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;queue: &lt;/span&gt;&lt;span class="s1"&gt;'rollbar'&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;report_dj_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dj_threshold&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Data sanitization
&lt;/h2&gt;

&lt;p&gt;As we can see in the Rollbar defaults above, the logger scrubs some of the data from its reports.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collect_user_ip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;anonymize_user_ip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;user_ip_obfuscator_secret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"a-private-secret-here"&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrub_fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:passwd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:password_confirmation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:secret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="ss"&gt;:confirm_password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:password_confirmation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:secret_token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="ss"&gt;:api_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:access_token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:accessToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:session_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrub_user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrub_password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrub_headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'Authorization'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can further configure that by adding the custom fields that we want to remove from the reports or even whitelist some that we don't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Users data
&lt;/h2&gt;

&lt;p&gt;Whenever your Ruby on Rails application provides any kind of authentication for the visitors, you can report user data for an additional context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;person_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my_current_user"&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;person_id_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"id"&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;person_username_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"name"&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;person_email_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"email"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Pinpoint guilty release
&lt;/h2&gt;

&lt;p&gt;For an easier way to estimate what caused the reported exception to occur it is useful to report some release context to Rollbar, ideally extracted from your code version control.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;code_version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`git describe --abbrev=0`&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following will give you the most recent annotated git tag. If you follow the &lt;a href="https://semver.org/"&gt;Semantic Versioning&lt;/a&gt;, it will be for example 3.17.2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Proxy and Secure Sockets Layer
&lt;/h2&gt;

&lt;p&gt;It is possible to report the Ruby on Rails exception occurrences to Rollbar via a proxy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;proxy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="ss"&gt;host: &lt;/span&gt;&lt;span class="s1"&gt;'http://some.proxy.server'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;port: &lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;user: &lt;/span&gt;&lt;span class="s1"&gt;'username_if_auth_required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;password: &lt;/span&gt;&lt;span class="s1"&gt;'password_if_auth_required'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An exported environment variable &lt;code&gt;https_proxy&lt;/code&gt; will be respected as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export https_proxy='http://username:password@example.com:5000'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On top of that, you can disable SSL verification with a configuration flag, as it's enabled by default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify_ssl_peer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Custom reports modifications
&lt;/h2&gt;

&lt;p&gt;Every Ruby on Rails application exception reported to Rollbar is expandable. It accepts &lt;code&gt;lambda&lt;/code&gt; as an argument and has to return a Hash later merged to the original exception.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;conifg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;custom_data_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;lambda&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;android_version: &lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;dimensions: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;width: &lt;/span&gt;&lt;span class="mi"&gt;320&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;height: &lt;/span&gt;&lt;span class="mi"&gt;540&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once sent, it appears in the Occurrences tab of the exception reported.&lt;/p&gt;

&lt;p&gt;If there's some really important functionality in our Ruby on Rails application, it is a good practice to prepare for the worst with custom exceptions and to set their severity to &lt;code&gt;critical&lt;/code&gt; with configuration options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exception_level_filters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;merge!&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="s1"&gt;'PaymentException'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'critical'&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same configuration option comes to help if we want to ignore reporting a chosen exception.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rollbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exception_level_filters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;merge!&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="s1"&gt;'ActionController::RoutingError'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'ignore'&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, it's not the most developer-friendly to always remember to add the critical error severity to the configuration. My advice is to define your own critical exception class and inherit from it further down the code whenever.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Rollbar is a powerful tool that helps you to keep the Ruby on Rails application well-maintained and is definitely worth using if you want to monitor every newly developed feature seriously.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://hixonrails.com"&gt;Hix on Rails&lt;/a&gt;, all you need to do in order to have a fully configured Rollbar logger is creating your account and copy-pasting the Rollbar Access Key into the project initialization wizard.&lt;/p&gt;

&lt;p&gt;If you found the tutorial helpful, please spread the knowledge by sharing it! Thanks!&lt;/p&gt;

&lt;p&gt;Also, if you wish us to cover something else, let us know in the comment.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Tracking your Ruby on Rails app errors with Sentry logger</title>
      <dc:creator>hix.dev</dc:creator>
      <pubDate>Mon, 13 Jan 2020 13:38:34 +0000</pubDate>
      <link>https://forem.com/hixdevs/tracking-your-ruby-on-rails-app-errors-with-sentry-logger-3j7b</link>
      <guid>https://forem.com/hixdevs/tracking-your-ruby-on-rails-app-errors-with-sentry-logger-3j7b</guid>
      <description>&lt;p&gt;This is the step by step guide to install and configure Sentry Raven logger in the Ruby on Rails project in 2020.&lt;/p&gt;

&lt;p&gt;You can find the original, &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-sentry-logger-installation-and-configuration/"&gt;1:1 piece on our blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Sentry?
&lt;/h2&gt;

&lt;p&gt;Sentry is a realtime application monitoring and error tracking software which one can visit anytime via a web browser.&lt;/p&gt;

&lt;p&gt;Applications can communicate with Sentry via the HTTP protocol, sending data about their crashes and exceptions.&lt;/p&gt;

&lt;p&gt;Developers subscribe to Sentry's notifications and can almost instantly react to production problems by easily pinpointing them via sophisticated UI, which provides a complete set of data necessary for the job.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Sentry Raven with Ruby on Rails?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;It is free to use up to 5000 API requests per month.&lt;/li&gt;
&lt;li&gt;It gathers more data than the default Ruby on Rails logger.&lt;/li&gt;
&lt;li&gt;It provides an intuitive UI, which is more comfortable to work with than primitive log files.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ruby on Rails is provided with a basic logger that writes to the selected file, or files. Reading a single file with the constantly appended massive stack traces is a primitive way to monitor the application.&lt;/p&gt;

&lt;p&gt;Sentry collects and aggregates Ruby on Rails application crashes and exceptions data, with an additional context, such as a suspected release that started to cause the problem.&lt;/p&gt;

&lt;p&gt;Via a sophisticated Sentry web UI developer can browse errors by the latest, most occurrent and multiple additional pieces of information provided.&lt;/p&gt;

&lt;p&gt;I cannot stress enough how crucial it is that your Ruby on Rails application is hooked up with an advanced logging and monitoring system such as Sentry from its day one on production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sentry account and project setup
&lt;/h2&gt;

&lt;p&gt;Follow the instructions below to create your Sentry account and set up the Ruby on Rails project for further monitoring.&lt;/p&gt;

&lt;p&gt;1.Sign up on the official &lt;a href="https://sentry.io/signup/"&gt;Sentry website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sFRfW1tD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0iahpfilc0fh82lut68w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sFRfW1tD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0iahpfilc0fh82lut68w.png" alt="Alt Text" width="670" height="868"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.In the second onboarding step, select "Rails" platform.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OhQIOec1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8yk5yzorb2733l6jgya0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OhQIOec1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8yk5yzorb2733l6jgya0.png" alt="Alt Text" width="670" height="904"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.From the third onboarding step copy your Sentry DSN&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sFZo8W9d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/urc5qavvsd56hjmu3oy2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sFZo8W9d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/urc5qavvsd56hjmu3oy2.png" alt="Alt Text" width="670" height="693"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The DSN abbreviation stands for Data Source Name and is autogenerated for every project that you are going to hook into your Sentry account.&lt;/p&gt;

&lt;p&gt;It allows you to keep all the logs in one place, which comes very handy especially for multiple services monitored daily.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sentry Raven installation in Ruby on Rails project
&lt;/h2&gt;

&lt;p&gt;If you use &lt;a href="https://hixonrails.com/"&gt;Hix on Rails&lt;/a&gt;, your job is done here, all you gonna do is paste your Sentry DSN into the second step of the Hix on Rails project initialization wizard.&lt;/p&gt;

&lt;p&gt;Otherwise, if you sadly did not automate that part of your life yet, follow steps below for Ruby on Rails Sentry configuration.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open your projects &lt;code&gt;Gemfile&lt;/code&gt; and paste the &lt;code&gt;gem 'sentry-raven'&lt;/code&gt; so it's available for every environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In a command-line navigate to the project's directory, enter &lt;code&gt;bundle install&lt;/code&gt; and while it runs go to the next step.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create the &lt;code&gt;config/initializers/sentry.rb&lt;/code&gt; file and paste the minimal configuration required, replacing the value with previously copied Sentry DSN.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;config/initializers/sentry.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# frozen_string_literal: true&lt;/span&gt;

&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dsn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'YOUR_SENTRY_DSN_GOES_HERE'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a minimal setup required to hook up your Ruby on Rails application with your newly created Sentry account, via the dedicated &lt;a href="https://github.com/getsentry/raven-ruby"&gt;sentry-raven gem&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is overall a better idea to not store credentials in your project repository and use dedicated environmental management instead. For example, if you use a &lt;a href="https://github.com/bkeepers/dotenv"&gt;dotenv-rails&lt;/a&gt; gem, it is a better idea to provide your DSN via the &lt;code&gt;.env&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.env&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SENTRY_DSN=YOUR_SENTRY_DSN_GOES_HERE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;config/initializers/sentry.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# frozen_string_literal: true&lt;/span&gt;

&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dsn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'SENTRY_DSN'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see what other configuration options are worth tweaking while monitoring Ruby on Rails project with Sentry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails Sentry configuration
&lt;/h2&gt;

&lt;p&gt;With the minimalistic setup, we started to report Ruby on Rails application exceptions to the Sentry.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/getsentry/raven-ruby/blob/master/lib/raven/configuration.rb#L204-L235"&gt;Raven default configuration&lt;/a&gt; with the DSN passed at this point is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dsn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'SENTRY_DSN'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;async&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;context_lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;current_environment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_environment_from_env&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encoding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'gzip'&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;environments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exclude_loggers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;excluded_exceptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;IGNORE_DEFAULT&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dup&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;inspect_exception_causes_for_exclusion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;linecache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;LineCache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;STDOUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open_timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;processors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DEFAULT_PROCESSORS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dup&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;project_root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;detect_project_root&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rails_activesupport_breadcrumbs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rails_report_rescued_exceptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;release&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;detect_release&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sample_rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sanitize_credit_cards&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sanitize_fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sanitize_fields_excluded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sanitize_http_headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_modules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'SENTRY_DSN'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;server_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;server_name_from_env&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;should_capture&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ssl_verification&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tags&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transport_failure_callback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;before_send&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Environments setup
&lt;/h2&gt;

&lt;p&gt;By default, whenever provided a valid DSN, Sentry Raven will work automatically in every Ruby on Rails environment, where the defaults are test, development, and production.&lt;/p&gt;

&lt;p&gt;That's overkill for the development environment, so my advice is to further configure it after checking if it works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;environments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;%[production]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way an automated test suite and development of new features won't eat up your quota.&lt;/p&gt;

&lt;p&gt;Another closely related option that is wisely deduced by Raven is current environment detection.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, Sentry tries to get &lt;code&gt;ENV['RAILS_ENV']&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Next, if first is absent, it tries &lt;code&gt;ENV['RACK_ENV']&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can customize it via the current environment configuration flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;current_environment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'staging'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whatever you'll set here, will be visible in the Sentry environments dropdown.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NR8-ypQ3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9emky4x9e3lasmkl2u5k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NR8-ypQ3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9emky4x9e3lasmkl2u5k.png" alt="Alt Text" width="670" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Asynchronous reporting
&lt;/h2&gt;

&lt;p&gt;Error logging is not the primary task of most of the web applications, including Ruby on Rails. It is good to keep it asynchronous, and Sentry allows users to do so by exposing the asynchronous configuration flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;async&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;lambda&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="no"&gt;SentryJob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perform_later&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;app/jobs/sentry_job.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SentryJob&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveJob&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;
  &lt;span class="n"&gt;queue_as&lt;/span&gt; &lt;span class="ss"&gt;:sentry&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;perform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the async callback raises an exception, Raven will attempt to send synchronously.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data sanitization
&lt;/h2&gt;

&lt;p&gt;Sentry for Ruby on Rails provides two configuration options for data sanitization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sanitize_fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"my_field"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"foo(.*)?bar"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sanitize_http_headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;%w[Referer User-Agent Server From]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The field sanitization accepts a raw string and regex-like strings for striping the data from the requests sent to Sentry.&lt;/p&gt;

&lt;p&gt;The second one allows you to filter out HTTP headers from the payload. A full list of potentially sensitive HTTP headers can be found in the &lt;a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html"&gt;RFC 2616&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data processing
&lt;/h2&gt;

&lt;p&gt;The default Sentry data processors are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Note the order - we have to remove circular references and bad characters&lt;/span&gt;
&lt;span class="c1"&gt;# before passing to other processors.&lt;/span&gt;
&lt;span class="no"&gt;DEFAULT_PROCESSORS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Processor&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;RemoveCircularReferences&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Processor&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;UTF8Conversion&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Processor&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;SanitizeData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Processor&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Cookies&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Processor&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PostData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Processor&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;HTTPHeaders&lt;/span&gt;
&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;freeze&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which we can modify via yet another configuration flag by adding new and removing existing processors from the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'raven/processor/removestacktrace'&lt;/span&gt;

&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;processors&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Processor&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;RemoveStacktrace&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;processors&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Processor&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PostData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;processors&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Processor&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Cookies&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might want to remove cookies and post data processors via the configuration, as by default Sentry does not send POST data or cookies if present, and it may improve your further debugging experience.&lt;/p&gt;

&lt;p&gt;A full list of the Raven processors belonging to the &lt;code&gt;Raven::Processor&lt;/code&gt; module.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── processor
│   ├── cookies.rb
│   ├── http_headers.rb
│   ├── post_data.rb
│   ├── removecircularreferences.rb
│   ├── removestacktrace.rb
│   ├── sanitizedata.rb
│   └── utf8conversion.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On top of all that, Sentry allows filtering out selected exceptions by appending them to the excluded exceptions array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;excluded_exceptions&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ActionController::RoutingError'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On an even deeper level, Sentry allows you to prevent exceptions from being sent via providing your custom logic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;should_capture&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;exception&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="n"&gt;exception&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;super&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s1"&gt;'WillinglyUnreportedException'&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is especially useful when you want to filter out a whole bunch of exceptions without always remembering to put them into the excluded exceptions array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WillinglyUnreportedException&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;StandardError&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DontCareTooMuchException&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;WillinglyUnreportedExceptions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;NevermindException&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;WillinglyUnreportedExceptions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another option that might be especially useful for large applications is data sampling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sample_rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A value of &lt;code&gt;0&lt;/code&gt; will deny sending any events, and value of &lt;code&gt;1&lt;/code&gt; will send every single event, which is the default behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pinpoint guilty release
&lt;/h2&gt;

&lt;p&gt;Sentry is clever in deducing which release causes an exception. It takes the following in the given order of precedence.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Commit SHA of the last git commit&lt;/li&gt;
&lt;li&gt;Last line of the application root REVISION file&lt;/li&gt;
&lt;li&gt;For Heroku, dyno metadata enabled via Heroku Labs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It can be customized if you have some kind of custom release tracking system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;release&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'custom release string'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default settings may be configured smoothly with popular git remote providers such as Github and Gitlab for convenient linking to the guilty git commits and tags via Sentry UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Proxy and Secure Sockets Layer
&lt;/h2&gt;

&lt;p&gt;Sentry gives its user an option to configure a proxy connection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;proxy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'http://example.com'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It accepts a simple string representing the URL to your proxy server.&lt;/p&gt;

&lt;p&gt;SSL verification might be disabled in the configuration file, as it's enabled by default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ssl_verification&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Custom reports modifications
&lt;/h2&gt;

&lt;p&gt;In your configuration file, you can use two options provided for globally customizing Sentry reports.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Raven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tags&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;hostname: &lt;/span&gt;&lt;span class="sb"&gt;`hostname`&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;before_send&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;lambda&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hint&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fingerprint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'fingerprint'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;event&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A first of them, the tagging option, allows you to send an additional context with your events for further filtering. For example, if you have a load balancer set up in front of your Ruby on Rails application, you might want to send some info identifying a specific instance on which the exception occurred.&lt;/p&gt;

&lt;p&gt;The second one helps you to modify every single occurrence on the fly, accessing it before is send. Be aware that if you won't return the event from this method, it will be dropped.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Sentry is a powerful tool that helps you to keep the Ruby on Rails application well-maintained and is definitely worth using if you want to monitor every newly developed feature seriously.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://hixonrails.com"&gt;Hix on Rails&lt;/a&gt;, all you need to do in order to have a fully configured Sentry logger is creating your account and copy-pasting the Sentry DSN into the project initialization wizard.&lt;/p&gt;

&lt;p&gt;If you enjoyed reading through, please share this article or follow us for more! &lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>security</category>
    </item>
    <item>
      <title>Ruby on Rails set up on Github with CircleCI</title>
      <dc:creator>hix.dev</dc:creator>
      <pubDate>Fri, 10 Jan 2020 11:47:54 +0000</pubDate>
      <link>https://forem.com/hixdevs/ruby-on-rails-set-up-on-github-with-circleci-2mnh</link>
      <guid>https://forem.com/hixdevs/ruby-on-rails-set-up-on-github-with-circleci-2mnh</guid>
      <description>&lt;p&gt;This is the ultimate guide for your next Ruby on Rails project setup on Github with CircleCI for continuous integration in 2020.&lt;/p&gt;

&lt;p&gt;So let's start with some basic knowledge.&lt;/p&gt;

&lt;p&gt;Note: A full 1:1 &lt;a href="https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-set-up-on-github-with-circleci/"&gt;"Ruby on Rails set up on Github with CircleCI"&lt;/a&gt; article was originally posted on our website. You can also find more tutorials already there.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Github?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.similarweb.com/website/github.com"&gt;Github is one of the top 100 websites on the Internet&lt;/a&gt;, with ~310M monthly visits. It holds the biggest OpenSource codebase in the world.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iXK384bd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fyxk6514waxnlfpj7zlm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iXK384bd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fyxk6514waxnlfpj7zlm.png" alt="Alt Text" width="670" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One can safely say that it's a proven tool in a programmers' toolbox.&lt;/p&gt;

&lt;p&gt;Fun fact is that Ruby, with &lt;a href="https://stackshare.io/github/github"&gt;Ruby on Rails, is a big part of the Github's tech stack&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---wzOtK9e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/3w6g73zxwn6dq9erwagk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---wzOtK9e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/3w6g73zxwn6dq9erwagk.png" alt="Alt Text" width="670" height="726"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Among all the other features, Github is a remote repository hosting for the git version control system. When developers create their code, they make constant changes, additions, improvements and deletions to the codebase.&lt;/p&gt;

&lt;p&gt;The version control system stores these code revisions in a central repository, which allows programmers to easily collaborate, as they can download the new version of the software, add their changes and upload them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Github for Ruby on Rails app?
&lt;/h2&gt;

&lt;p&gt;The biggest advantage of using Github for Ruby on Rails project, as well as any other remote repository hosting provider, is that you can create constant backups of your code&lt;/p&gt;

&lt;p&gt;Git provides a full history of changes and an ability to roll back to the older version of the code in case of introducing changes that causes errors.&lt;/p&gt;

&lt;p&gt;With Github, it is available at any point in time, online. You are not limited to the single machine on which code was written.&lt;/p&gt;

&lt;p&gt;Another advantage is that with its massive Open Source codebase there is a big chance that anybody that is going to collaborate with your code is going to know how to use Github, so statistically, a learning curve is the smallest possible.&lt;/p&gt;

&lt;p&gt;Github provides an intuitive UI that allows developers to easily collaborate, with its Pull Requests, Code Review and Forks.&lt;/p&gt;

&lt;p&gt;It even introduces its own &lt;a href="http://scottchacon.com/2011/08/31/github-flow.html"&gt;git branching strategy, called GitHub flow&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continuous integration for Ruby on Rails
&lt;/h2&gt;

&lt;p&gt;Continuous Integration (CI) is a development practice that requires collaborators to upload their code to the shared repository continuously, ideally several times a day.&lt;/p&gt;

&lt;p&gt;Every time they do, the code is verified by an automated build, the test suite runs and dedicated static code analysis tools check it for security vulnerabilities, errors, and all kinds of inaccuracies.&lt;/p&gt;

&lt;p&gt;It is good for both developers and software to automatically check the code quality and CI a great place to do it.&lt;/p&gt;

&lt;p&gt;There are multiple open-source static code analysis tools available for both Ruby and Ruby on Rails.&lt;/p&gt;

&lt;p&gt;Most of them can be set up on the CI server to audit the code of Ruby on Rails project every time it's pushed or nightly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use CircleCI for Ruby on Rails app?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://circleci.com/"&gt;CircleCI&lt;/a&gt; is a Continous Integration and Delivery cloud provider.&lt;/p&gt;

&lt;p&gt;It integrates with Github, so using both of them together is as simple as creating your accounts and setting up the Ruby on Rails project.&lt;/p&gt;

&lt;p&gt;No custom servers maintenance, just going through some web forms and you are all set.&lt;/p&gt;

&lt;p&gt;No credit card information required, a perfect combination to start small with your project and pay for what you use as you grow.&lt;/p&gt;

&lt;p&gt;CircleCI provides an intuitive, well-organized UI with all the information required to establish the problem that occurs when the new code was integrated into the Github hosted codebase.&lt;/p&gt;

&lt;p&gt;It is crucial to set up the Continuous Integration system for any project, let alone Ruby on Rails, from the first day of the development.&lt;/p&gt;

&lt;p&gt;This is a great way to avoid a lot of technical debt, protect yourself from common mistakes and enforce certain standards that make working with Ruby on Rails codebase pleasing and its maintenance much, much easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Github account and Ruby on Rails project
&lt;/h2&gt;

&lt;p&gt;Follow the instructions below to create your Github account and set up the Ruby on Rails project.&lt;/p&gt;

&lt;p&gt;1.Sign up on the &lt;a href="https://github.com/join"&gt;official Github website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HJ3BGKoB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/sisz25mrgtrvf1lbjssi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HJ3BGKoB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/sisz25mrgtrvf1lbjssi.png" alt="Alt Text" width="596" height="669"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.Verify your email.&lt;br&gt;
3.You will be redirected to the new Github repository creation page.&lt;br&gt;
4.Provide the repository name and click the "Create repository" button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--plvsT9AS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qavr5hsxyuo4gsfcotge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--plvsT9AS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qavr5hsxyuo4gsfcotge.png" alt="Alt Text" width="670" height="612"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5.On the new repository page, get your remote repository HTTPS or SSH link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nJ6D0U6---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/tberoxrh7njewiek0lwq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nJ6D0U6---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/tberoxrh7njewiek0lwq.png" alt="Alt Text" width="670" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6.If you are using &lt;a href="https://hixonrails.com/"&gt;Hix on Rails&lt;/a&gt;, that's all you are going to need for now, just paste the address into the CLI when asked for it.&lt;/p&gt;

&lt;p&gt;7.Navigate to the Ruby on Rails project root directory in the command line and enter &lt;code&gt;git remote add origin YOUR_REPOSITORY_URL&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create CircleCI account linked to Github
&lt;/h2&gt;

&lt;p&gt;Follow the instructions below to create your CircleCI account linked to your Github account, and to set up the Ruby on Rails project continuous integration.&lt;/p&gt;

&lt;p&gt;1.Click "Sign up with Github" on the &lt;a href="https://circleci.com/signup/"&gt;official CircleCI website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SG_6OAxd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qe05ooexej0igqvyonh3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SG_6OAxd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qe05ooexej0igqvyonh3.png" alt="Alt Text" width="670" height="269"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.On the authorization page, click "Authorize circleci".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eWvRaWFi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1k5oxswcogycb8qyl2ox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eWvRaWFi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1k5oxswcogycb8qyl2ox.png" alt="Alt Text" width="531" height="684"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.You will be redirected to the CircleCI dashboard. From the left-side sidebar, select "Add Projects".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ay4kmmAm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9wpqw0vid2bys9d58gdd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ay4kmmAm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9wpqw0vid2bys9d58gdd.png" alt="Alt Text" width="670" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.In the projects tab, click "Set up project" next to the newly created Github project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gNityxN2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/lmsjp3bygyajt1yfmccc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gNityxN2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/lmsjp3bygyajt1yfmccc.png" alt="Alt Text" width="670" height="209"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby on Rails project on CircleCI
&lt;/h2&gt;

&lt;p&gt;If you are using &lt;a href="https://hixonrails.com"&gt;Hix on Rails&lt;/a&gt;, that's it, all you need to do is click "Start building" after pushing the code with your first database migration, as the database creation is a part of the Ruby on Rails application build process and it will fail if no tables are present.&lt;/p&gt;

&lt;p&gt;Otherwise, if you sadly did not automate that part of your life yet, follow steps below for Ruby on Rails project configuration on the CircleCI.&lt;/p&gt;

&lt;p&gt;In your project root, create the required CircleCI configuration file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;path/to/your/project/root
&lt;span class="nb"&gt;mkdir&lt;/span&gt; .circleci
&lt;span class="nb"&gt;touch&lt;/span&gt; .circleci/config.yml
~~~&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;

Open the CircleCI configuration file with a text editor of your choice and &lt;span class="nb"&gt;paste &lt;/span&gt;the basic code required, depending on your database choice.

&lt;span class="c"&gt;##Ruby on Rails with PostgreSQL on CircleCI&lt;/span&gt;

PostgreSQL is the most popular choice &lt;span class="k"&gt;for &lt;/span&gt;Ruby on Rails applications.

For the CircleCI to work you are going to need a specific setup &lt;span class="k"&gt;in &lt;/span&gt;the &lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;config/database.yml&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt; file. Notice that the &lt;span class="o"&gt;[&lt;/span&gt;dotenv-rails]&lt;span class="o"&gt;(&lt;/span&gt;https://github.com/bkeepers/dotenv&lt;span class="o"&gt;)&lt;/span&gt; gem is used.

&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;config/database.yml&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;

~~~yaml
default: &amp;amp;default
  adapter: postgresql
  encoding: unicode
  pool: &amp;lt;%&lt;span class="o"&gt;=&lt;/span&gt; ENV[&lt;span class="s1"&gt;'DB_POOL'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; %&amp;gt;
  username: &amp;lt;%&lt;span class="o"&gt;=&lt;/span&gt; ENV[&lt;span class="s1"&gt;'DB_USERNAME'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; %&amp;gt;
  password: &amp;lt;%&lt;span class="o"&gt;=&lt;/span&gt; ENV[&lt;span class="s1"&gt;'DB_PASSWORD'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; %&amp;gt;
  host: &amp;lt;%&lt;span class="o"&gt;=&lt;/span&gt; ENV[&lt;span class="s1"&gt;'DB_HOST'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; %&amp;gt;
  port: 5432

development:
  &amp;lt;&amp;lt;: &lt;span class="k"&gt;*&lt;/span&gt;default
  database: hix_postgresql_development

&lt;span class="nb"&gt;test&lt;/span&gt;:
  &amp;lt;&amp;lt;: &lt;span class="k"&gt;*&lt;/span&gt;default
  database: hix_postgresql_test

production:
  &amp;lt;&amp;lt;: &lt;span class="k"&gt;*&lt;/span&gt;default
  database: hix_postgresql_production
~~~&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;

If you decided to go with it, here&lt;span class="s1"&gt;'s the basic CircleCI configuration for the Ruby on Rails project build with the PostgreSQL database.{% raw %}

~~~yaml
version: 2.1

executors:
  default:
    working_directory: ~/hix_postgresql
    docker:
      - image: circleci/ruby:2.6.5
        environment:
          BUNDLE_JOBS: 3
          BUNDLE_PATH: vendor/bundle
          BUNDLE_RETRY: 3
          BUNDLER_VERSION: 2.0.1
          RAILS_ENV: test
          DB_HOST: 127.0.0.1
          PG_HOST: 127.0.0.1
          PGUSER: hixonrails
      - image: circleci/postgres:12.0
        environment:
          POSTGRES_DB: hix_postgresql_test
          POSTGRES_USER: hixonrails

commands:
  configure_bundler:
    description: Configure bundler
    steps:
      - run:
          name: Configure bundler
          command: |
            echo '&lt;/span&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;BUNDLER_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;Gemfile.lock | &lt;span class="nb"&gt;tail&lt;/span&gt; &lt;span class="nt"&gt;-1&lt;/span&gt; | &lt;span class="nb"&gt;tr&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s1"&gt;' &amp;gt;&amp;gt; $BASH_ENV
            source $BASH_ENV
            gem install bundler

jobs:
  build:
    executor: default
    steps:
      - checkout
      - restore_cache:
          keys:
            - hix_postgresql-`{{ .Branch }}`-`{{ checksum "Gemfile.lock" }}`
            - hix_postgresql-
      - configure_bundler
      - run:
          name: Install bundle
          command: bundle install
      - run:
          name: Wait for DB
          command: dockerize -wait tcp://127.0.0.1:5432 -timeout 1m
      - run:
          name: Setup DB
          command: bundle exec rails db:create db:schema:load --trace
      - save_cache:
          key: hix_postgresql-`{{ .Branch }}`-`{{ checksum "Gemfile.lock" }}`
          paths:
            - vendor/bundle
      - persist_to_workspace:
          root: ~/
          paths:
            - ./hix_postgresql

workflows:
  version: 2
  integration:
    jobs:
      - build
~~~

There are multiple adjustments necessary for this code to work with a particular project.

1. In the Docker Ruby image, line 7, adjust your Ruby version. At the time of writing this article the last stable version is used, 2.6.5
2. In the Docker PostgreSQL image, line 17, adjust your PostgreSQL version. At the time of writing this article the last stable version is used, 12.0.
3. In lines 16 and 20, you can adjust the PostgreSQL user name, however, it'&lt;/span&gt;s not mandatory.
4. Replace all occurrences of the &lt;span class="s2"&gt;"hix_postgresql"&lt;/span&gt; with your Ruby on Rails project name.

For the workflow to pass on the CircleCI, you need to have &lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;db/schema.rb&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt; file checked into the repository, which means that you need to create at least one database migration.

&lt;span class="c"&gt;##Ruby on Rails with MySQL on CircleCI&lt;/span&gt;

MySQL is the second most popular choice &lt;span class="k"&gt;for &lt;/span&gt;Ruby on Rails applications, just behind the PostgreSQL.

For the CircleCI to work you are going to need a specific setup &lt;span class="k"&gt;in &lt;/span&gt;the &lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;config/database.yml&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt; file. Notice that the &lt;span class="o"&gt;[&lt;/span&gt;dotenv-rails]&lt;span class="o"&gt;(&lt;/span&gt;https://github.com/bkeepers/dotenv&lt;span class="o"&gt;)&lt;/span&gt; gem is used.

&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;config/database.yml&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;

~~~yaml
default: &amp;amp;default
  adapter: mysql2
  encoding: utf8
  pool: &amp;lt;%&lt;span class="o"&gt;=&lt;/span&gt; ENV[&lt;span class="s1"&gt;'DB_POOL'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; %&amp;gt;
  username: &amp;lt;%&lt;span class="o"&gt;=&lt;/span&gt; ENV[&lt;span class="s1"&gt;'DB_USERNAME'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; %&amp;gt;
  password: &amp;lt;%&lt;span class="o"&gt;=&lt;/span&gt; ENV[&lt;span class="s1"&gt;'DB_PASSWORD'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; %&amp;gt;
  host: &amp;lt;%&lt;span class="o"&gt;=&lt;/span&gt; ENV[&lt;span class="s1"&gt;'DB_HOST'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; %&amp;gt;
  port: 3306

development:
  &amp;lt;&amp;lt;: &lt;span class="k"&gt;*&lt;/span&gt;default
  database: hix_mysql_development

&lt;span class="nb"&gt;test&lt;/span&gt;:
  &amp;lt;&amp;lt;: &lt;span class="k"&gt;*&lt;/span&gt;default
  database: hix_mysql_test

production:
  &amp;lt;&amp;lt;: &lt;span class="k"&gt;*&lt;/span&gt;default
  database: hix_mysql_production
~~~&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;

If you decided to go with it, here&lt;span class="s1"&gt;'s the basic CircleCI configuration for the Ruby on Rails project build with the PostgreSQL database.

~~~yaml
version: 2.1

executors:
  default:
    working_directory: ~/hix_mysql
    docker:
      - image: circleci/ruby:2.6.5
        environment:
          BUNDLE_JOBS: 3
          BUNDLE_PATH: vendor/bundle
          BUNDLE_RETRY: 3
          BUNDLER_VERSION: 2.0.1
          RAILS_ENV: test
          DB_HOST: 127.0.0.1
          DB_USERNAME: root
          DB_PASSWORD: ''
      - image: circleci/mysql:8.0.18
        command: [--default-authentication-plugin=mysql_native_password]
        environment:
          MYSQL_ALLOW_EMPTY_PASSWORD: '&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="s1"&gt;'
          MYSQL_ROOT_HOST: '&lt;/span&gt;%&lt;span class="s1"&gt;'

commands:
  configure_bundler:
    description: Configure bundler
    steps:
      - run:
          name: Configure bundler
          command: |
            echo '&lt;/span&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;BUNDLER_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;Gemfile.lock | &lt;span class="nb"&gt;tail&lt;/span&gt; &lt;span class="nt"&gt;-1&lt;/span&gt; | &lt;span class="nb"&gt;tr&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s1"&gt;' &amp;gt;&amp;gt; $BASH_ENV
            source $BASH_ENV
            gem install bundler

jobs:
  build:
    executor: default
    steps:
      - checkout
      - restore_cache:
          keys:
            - hix_mysql-`{{ .Branch }}`-`{{ checksum "Gemfile.lock" }}`
            - hix_mysql-
      - configure_bundler
      - run:
          name: Install bundle
          command: bundle install
      - run:
          name: Wait for DB
          command: dockerize -wait tcp://127.0.0.1:3306 -timeout 1m
      - run:
          name: Setup DB
          command: bundle exec rails db:create db:schema:load --trace
      - save_cache:
          key: hix_mysql-`{{ .Branch }}`-`{{ checksum "Gemfile.lock" }}`
          paths:
            - vendor/bundle
      - persist_to_workspace:
          root: ~/
          paths:
            - ./hix_mysql

workflows:
  version: 2
  integration:
    jobs:
      - build
~~~

There are multiple adjustments necessary for this code to work with a particular project.

1. In the Docker Ruby image, line 7, adjust your Ruby version. At the time of writing this article the last stable version is used, 2.6.5
2. In the Docker MySQL image, line 17, adjust your MySQL version. At the time of writing this article the last stable version is used, 8.0.18.
3. Replace all occurrences of the "hix_mysql" with your Ruby on Rails project name.

For the workflow to pass on the CircleCI, you need to have `db/schema.rb` file checked into the repository, which means that you need to create at least one database migration.

##Ruby on Rails with RSpec on CircleCI

[RSpec](https://rspec.info/) is the most popular Ruby testing framework, hence the tool of our choice.

In the continuous integration flow, running the test suite is one of the most common jobs, to ensure that new features do not break other well-tested parts of a Ruby on Rails application.

On top of that, RSpec can be easily configured with [SimpleCov, the ruby gem for generating test coverage reports](https://github.com/colszowka/simplecov). Generating those reports gives developers a nice overview on how the Ruby on Rails application is maintained.

This is the perfect job for the CircleCI, so if you have decided to go with it, edit the previously created configuration file, adding the RSpec job and running it in the defined workflow.

~~~yaml
jobs:
  build:
    executor: default
    steps:
      - checkout
      - restore_cache:
          keys:
            - hix-`{{ .Branch }}`-`{{ checksum "Gemfile.lock" }}`
            - hix-
      - configure_bundler
      - run:
          name: Install bundle
          command: bundle install
      - run:
          name: Wait for DB
          command: dockerize -wait tcp://127.0.0.1:3306 -timeout 1m
      - run:
          name: Setup DB
          command: bundle exec rails db:create db:schema:load --trace
      - run:
          name: RSpec
          command: |
            bundle exec rspec --profile 10 \
                              --format progress
      - store_artifacts:
          path: coverage
      - save_cache:
          key: hix-`{{ .Branch }}`-`{{ checksum "Gemfile.lock" }}`
          paths:
            - vendor/bundle
      - persist_to_workspace:
          root: ~/
          paths:
            - ./hix

workflows:
  version: 2
  integration:
    jobs:
      - build
~~~

For the RSpec to work it needs the Ruby on Rails project to be built and the database to be set up.

You can skip the part that stores the artifacts if you did not bother with the SimpleCov setup.

The profiling flag is another thing that'&lt;/span&gt;s &lt;span class="nb"&gt;nice &lt;/span&gt;to have &lt;span class="k"&gt;in &lt;/span&gt;the CI workflow - it tells you which tests are the slowest to run.

&lt;span class="o"&gt;[&lt;/span&gt;Hix on Rails]&lt;span class="o"&gt;(&lt;/span&gt;https://hixonrails.com&lt;span class="o"&gt;)&lt;/span&gt; comes additionally configured to use &lt;span class="o"&gt;[&lt;/span&gt;Coveralls]&lt;span class="o"&gt;(&lt;/span&gt;https://coveralls.io/&lt;span class="o"&gt;)&lt;/span&gt;, which gives a &lt;span class="nb"&gt;nice test &lt;/span&gt;coverage percentage badge &lt;span class="k"&gt;for &lt;/span&gt;your Ruby on Rails project&lt;span class="s1"&gt;'s README.md.

##Ruby on Rails with RuboCop on CircleCI

[RuboCop](https://github.com/rubocop-hq/rubocop) is the most popular Ruby code linting tool available, with almost 400 rules checked in the default configuration.

Next to the default gem, there are plugins that check the Ruby on Rails, RSpec and Ruby code performance rules, which combined gives as the total of almost 500 rules checked, every time new code is contributed to the codebase.

If you decided to use the RuboCop in your Ruby on Rails project here'&lt;/span&gt;s the CircleCI configuration required.&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;

~~~yaml
  rubocop:
    executor: default
    steps:
      - attach_workspace:
          at: ~/
      - configure_bundler
      - run:
          name: Rubocop
          &lt;span class="nb"&gt;command&lt;/span&gt;: bundle &lt;span class="nb"&gt;exec &lt;/span&gt;rubocop

workflows:
  version: 2
  integration:
    &lt;span class="nb"&gt;jobs&lt;/span&gt;:
      - build
      - rubocop:
          requires:
            - build
~~~&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;

For the &lt;span class="nb"&gt;complete &lt;/span&gt;RuboCop setup &lt;span class="k"&gt;for &lt;/span&gt;Ruby on Rails applications using RSpec, please &lt;span class="nb"&gt;read &lt;/span&gt;the &lt;span class="o"&gt;[&lt;/span&gt;Ruby on Rails project RuboCop setup with RSpec]&lt;span class="o"&gt;(&lt;/span&gt;https://hixonrails.com/ruby-on-rails-tutorials/ruby-on-rails-project-rubocop-setup-with-rspec/&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;##Ruby on Rails with Brakeman on CircleCI&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt;Brakeman]&lt;span class="o"&gt;(&lt;/span&gt;https://brakemanscanner.org/&lt;span class="o"&gt;)&lt;/span&gt; is the most popular ruby gem &lt;span class="k"&gt;for &lt;/span&gt;Ruby on Rails applications security vulnerabilities audit.

It provides a simple command-line tool that among the total 29 warnings, checks your Ruby on Rails application code &lt;span class="k"&gt;for &lt;/span&gt;possible &lt;span class="o"&gt;[&lt;/span&gt;SQL Injection]&lt;span class="o"&gt;(&lt;/span&gt;https://rails-sqli.org/&lt;span class="o"&gt;)&lt;/span&gt; or &lt;span class="o"&gt;[&lt;/span&gt;Cross-Site Scripting]&lt;span class="o"&gt;(&lt;/span&gt;https://excess-xss.com/&lt;span class="o"&gt;)&lt;/span&gt; attacks.

The CircleCI continuous integration suite is the perfect place to check your code &lt;span class="k"&gt;for &lt;/span&gt;security, so &lt;span class="k"&gt;if &lt;/span&gt;you decided to use Brakeman &lt;span class="k"&gt;in &lt;/span&gt;your Ruby on Rails application, here&lt;span class="s1"&gt;'s the required CircleCI configuration.

~~~yaml
brakeman:
    executor: default
    steps:
      - attach_workspace:
          at: ~/
      - configure_bundler
      - run:
          name: Brakeman
          command: bundle exec brakeman

workflows:
  version: 2
  integration:
    jobs:
      - build
      - brakeman:
          requires:
            - build
~~~

Remember, that using any security audit tool does not guarantee that your Ruby on Rails application is 100% safe. Please read the [Open Web Application Security Project Top 10 Project](https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project) and on top of other things, audit your website regularly with tools like Mozilla Observatory.

##Ruby on Rails with Fasterer on CircleCI


[Fast Ruby](https://github.com/JuanitoFatas/fast-ruby) is the open-source project with a multitude of various benchmarks between different Ruby methods able to achieve the same goal.

[Fasterer](https://github.com/DamirSvrtan/fasterer) is a ruby gem, a static code analysis command-line tool that'&lt;/span&gt;s able to check your code &lt;span class="k"&gt;for &lt;/span&gt;potentially faster solutions, based on the Fast Ruby benchmarks.

If you decide to use the Fasterer, your continuous integration flow on CircleCI is a perfect place to &lt;span class="k"&gt;do &lt;/span&gt;so.&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;

~~~yaml
  fasterer:
    executor: default
    steps:
      - attach_workspace:
          at: ~/
      - configure_bundler
      - run:
          name: Fasterer
          &lt;span class="nb"&gt;command&lt;/span&gt;: bundle &lt;span class="nb"&gt;exec &lt;/span&gt;fasterer

workflows:
  version: 2
  integration:
    &lt;span class="nb"&gt;jobs&lt;/span&gt;:
      - build
      - fasterer:
          requires:
            - build
~~~&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;

One option that is recommended to be turned off &lt;span class="k"&gt;for &lt;/span&gt;Ruby on Rails project using Fasterer is the &lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;each.with_index&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt; versus the &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;loop&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;, all the rest of a default configuration is good to go.

&lt;span class="c"&gt;##Ruby on Rails with Rails Best Practices on CircleCI&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt;Rails Best Practices]&lt;span class="o"&gt;(&lt;/span&gt;https://rails-bestpractices.com/&lt;span class="o"&gt;)&lt;/span&gt; is an old but gold blog about Ruby on Rails applications development. It explains with a great detail common Ruby on Rails &lt;span class="o"&gt;(&lt;/span&gt;and other&lt;span class="o"&gt;)&lt;/span&gt; patterns, like &lt;span class="s2"&gt;"Law of Demeter"&lt;/span&gt; and &lt;span class="s2"&gt;"Tell, don't ask"&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;

Next to the great &lt;span class="nb"&gt;read&lt;/span&gt;, there&lt;span class="s1"&gt;'s another static code analysis tool, called… [Rails Best Practices](https://github.com/flyerhzm/rails_best_practices). It makes sure to report any Ruby on Rails application code that does not apply to the guides written on the blog.

If you decide to use it, your continuous integration suite on CircleCI is the perfect place to do so.

~~~yaml
  rails_best_practices:
    executor: default
    steps:
      - attach_workspace:
          at: ~/
      - configure_bundler
      - run:
          name: Rails Best Practices
          command: bundle exec rails_best_practices

workflows:
  version: 2
  integration:
    jobs:
      - build
      - rails_best_practices:
          requires:
            - build
~~~

I strongly recommend against giving up on the tool only because the blog'&lt;/span&gt;s last update was &lt;span class="k"&gt;in &lt;/span&gt;2014. All of the rules, as well as all the code quality checks, are still applicable &lt;span class="k"&gt;in &lt;/span&gt;the latest Ruby on Rails version.

&lt;span class="c"&gt;##Conclusion&lt;/span&gt;

Ruby on Rails is a very popular choice &lt;span class="k"&gt;for &lt;/span&gt;web application development and it comes with many benefits, one of which is the well-established community knowledge on how to &lt;span class="k"&gt;do &lt;/span&gt;things correctly.

A lot of this knowledge was forged into static code analysis tools that &lt;span class="nb"&gt;let &lt;/span&gt;developers find their mistakes easily.

CircleCI is trivial to use yet very powerful Continous Integration provider that lets you build, &lt;span class="nb"&gt;test &lt;/span&gt;and audit your Ruby on Rails application code with minimal setup, &lt;span class="k"&gt;for &lt;/span&gt;free.

If you care about the Ruby on Rails application code quality and easy maintenance, that&lt;span class="s1"&gt;'s the perfect combination for you.



Hope you like the tutorial! If you wish to learn more, follow us on dev.to or visit [our blog](https://hixonrails.com/ruby-on-rails-tutorials/). Thanks!

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
