My must have RubyGems

João Paulo Lethier
4 min readApr 18, 2017

--

Every Gemfile I look on each project I work or worked has similarities, has some gems that are always there, together with me in all projects. I think that is something that all developers have, and I decided to list what are my and some brief explanation why I choose those gems(besides the fact that I already know how to use)

  1. Devise

I think this one is a gem that every ruby developer knows and use. It is really helpful to built authentication feature, has a lot of helpers and you can configure as you want.

This gem is composed with 10 modules, and you can configure since what fields user will use to login(email or username or both, for example), can add validations to model, remember me features, integrate with omniauth, … It is a really full authentication implementation, what let you focus on what really matters and build login, logout and others authentication features really quick with it.

Another pro is documentation, what is really good, with lot of examples, a lot of how-tos, really easy to learn and use.

2. Cancancan

You can see that this gem is great when a developers community keeps this alive after the creator of this gem stop to work on this. This solve the authorization problem in a really simple way. You only configure permissions of all kind of users in a single ruby class, telling what a specific user can or cannot do. You can pass parameters and attributes to telling that an user can edit only unreleased books, for example. For this, you only needs to write can :edit, Book, released_at: nil .

There are a lot of built in helpers for controllers and views, like current_ability and can? methods. current_ability is a helper that cancancan sets automatically for us, and with this you can ask can? :edit, @book in your books#show page, for example, to decide when to show and when to hide the edit link for a book.

Like devise, it has a great documentation and a lot of tutorial and how tos, and, since it is used by a lot of developers, it is easy to find on web help and answers for all kind of issues.

3. RSpec

It is a complete and easy to use tool for automated tests. It is a primer choice for a lot of ruby developers, and you will find a lot ot ruby on rails tutorials using RSpec besides of default rails test framework, so it is easy to search and solve any issue and it is easy to learn how to use. In my first projects I used to configure Rspec for unit tests and Cucumber for feature tests, but since my third project I decided to not use Cucumber anymore, and I discover that RSpec is really full(using with capybara).

It has some really good helpers, it is easy to configure, just follow the recipe on its own documentation and you will have tests configured and running really quick.

4. FactoryGirl

My test configuration always has RSpec and FactoryGirl. While Rspec is great for write and run tests, this gem is a solution to build and create model fixtures for tests scenarios. It is easy to configure and easy to use.

I always create a folder called factories inside the spec folder, and put all my factories there, so, if I wanna have a user factory, I just create a users.rb file in that folder and define what fields I want that user has when I create it using this factory. It is possible to define a sequence for attributes that has uniqueness validation, so each time you create a instance using the factory you will have a different value for this field. You can create traits for a factory, so you can configure specific attributes values for specific traits, for example, you can have a user factory that leaves user name blank, and have a trait called 'user_with_name' that does everything the user factory does plus fill user name. And has a lot of others great features.

5. LetterOpener

It is a case of a tool that has a huge focus on one task and does this task really well. The objective of this gem is to make easy to test emails on development environment, it is really easy to configure, just installs it and put config.action_mailer.delivery_method = :letter_opener on your config/development.rb file and it is done. Now all email deliveries for development environment will open on your browser.

This is only 5 of gems that I really like and I think are really helpfull when developing a RubyOnRails project, there are a lot more gems available that are as helpfull and as great as those, always keep in mind that the main objective to use a gem is to keep focus on what really matters on your project.

--

--

No responses yet