Nowadays, web developers are able to access ready-made solutions instead of writing the functions from scratch, which of course has a great positive impact on the speed of development.
When we look at Ruby from this point of view, it stands out due to extensive libraries called Ruby gems. They offer particular functionalities to Ruby applications you build up. Suppose you want to have an authentication function in your program - you don't need to write one, you can get it in the form of a gem. And this is only one example among thousands of Ruby gems available for free.
In the first part of the article, we are going to uncover top Ruby gems we use in the following web development spheres: code quality, debugging, testing, deployment, and authentication & authorization.
In this article, we have prepared a list of Ruby gems. Actually, it is only a small part of all the gems that help us create quality products.
In order to remove bulky code blocks and handle the refactoring properly, we use the following Ruby gems.
Rubocop is a gem for analyzing and formatting Ruby static code. RuboCop is extremely flexible and most aspects of its behaviour can be tweaked via various configuration options.
Overcommit is a tool for configuring Git hooks. It is excellent for keeping the code quality high. It allows tuning git hooks for linters launch before every commit.
Actually, even a high-quality project definitely throws errors and bugs. For this reason, our development team uses the following Ruby gems for debugging.
Better_errors is a gem to show errors. It shows useful data about an error and has an excellent visual impact. Better_errors replaces the standard Rails error page.
Byebug is an easy-to-use and feature-rich debugger for Ruby. This gem allows line-by-line fulfilling of code, pausing between tasks and executing code, changing the variables on the move.
In general, any development process is impossible without quality assurance of the application. In such cases, we come to testing, which allows you to assess the quality. To start and control tests conveniently and smoothly, our team uses the following gems.
RSpec stands for Behaviour Driven Development for Ruby. It provides more readable DSL, as compared to the TestUnit standard testing library. Moreover, it smoothly cooperates and integrates with other gems that help test your application.
You may find interesting our GitHub repo on RSpec best practices.
Capybara is an acceptance test framework for web applications. It perfectly cooperates with RSpec for testing purposes. The tool is responsible for integrated tests that imitate users’ actions in a browser. It allows describing the authorization scenario in a few lines, suggesting then various convenient methods for tests debugging.
Capybara Screenshot is a gem for automatic saving of screenshots if a Capybara scenario breaks down. Together with Capybara and Cucumber, RSpec or Minitest, the gem allows view the source code and takes a screenshot (when relevant) for each failure in a test suite.
Parallel_tests makes tests written in TestUnit, RSpec and Cucumber pass faster running them in parallel on multiple CPUs.
Simplecov is one of the most useful gems for testing. It provides you with the percentage of code covered with unit-tests. Thus, the gem encourages developers to write fully-tested code.
Database Cleaner provides code coverage for Ruby 1.9+ with a powerful configuration library and automatic merging of coverage across test suites.
RSpec::Retry is a tool that provides :retry randomly failing RSpec example. It adds a :retry option for occasionally failing RSpec patterns.
Deployment is an important stage of web development, and there’s one library that helps us run the process smoothly.
Alongside, our development team has created our own tool for Mina, called mina-multideploy. It provides you with an opportunity to deploy applications on several servers in parallel.
Check our GitHub repository on Mina Multi-deploy for more information.
Nowadays, almost all of the web applications require an authentication and authorization system. Thus, in order to implement the best user data protection, we use the following gems:
Devise is a flexible authentication solution for Rails based on Warden. Devise provides you with any complexity level - from authentication via email and password to a referral system. In a few words, it has 10 modules, including:
- Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in;
- Recoverable: resets the user password and sends reset instructions;
- Rememberable: manages token generation and clearing to remember the user from a saved cookie;
- Trackable: tracks sign-in account, timestamps and IP address.
For practical application of this gem, check our blog article where we specify how we implemented JWT when creating a Time Bot for Slack.
In this scheme, an application server is configured to check whether an incoming JWT is the one generated with the authentication server.
In this chapter, we have provided you with various Ruby gems that we implement in different development spheres. They all help us to keep the code quality on a high level, simplify the debugging and testing processes, accelerate and enhance our applications’ deployment, and, finally, secure the users’ data.
We believe this chapter will be useful for you and your development team (if any). In the next chapter, we will tell you what Ruby gems are used at Codica for the following development aspects: uploading files, search, admin panels, and more awesome gems for different tasks.
Stay tuned and read the full article version here: 40 Best Ruby Gems That We Use.