Creating a Ruby Gem Driven by RSpec (Let's Build a Ruby Gem, Ep 01)

Описание к видео Creating a Ruby Gem Driven by RSpec (Let's Build a Ruby Gem, Ep 01)

Ruby Gems are collections of Ruby code (a.k.a. libraries, similar to Node.js packages). They contain code that you can require and use within your projects and/or command-line tools.

In the first episode of this series, we create a new Ruby Gem using Bundler's `bundle gem` command and drive out initial functionality using RSpec tests.

Table of contents:
00:00 - Intro
00:27 - Create new gem using Bundler
02:39 - Walking through the created files
11:35 - VERSION constant overview
12:58 - Adding our convert method with tests
22:54 - Using the bin/console command
24:00 - Committing the files in Git
25:58 - Building and installing the new gem

The project I begin to build out in this video is a gem called Converty—a simple library that allows you to convert an amount between different units. For example, easily convert feet to inches or miles to kilometers or ounces to pounds.

The API is pretty simple to start, a module with a class method that handles the conversion. For example, `Converty.convert(1, from: :mi, to: :ft)` returns 5280.0. When invalid unit types are passed in, a custom exception is thrown.

The majority of this screencast covers the test-driven development flow of writing a failing test, changing the code, and then getting it passing to have the functionality work. In the next episode, I'll go over refactoring the code, adding useful messages to the errors, and supporting more conversion types.

Support my screencasts by buying me a coffee: https://www.buymeacoffee.com/brettcha...
View the code from the episode on GitHub: https://github.com/monoso/converty/re...

Ruby version: 2.6.5
Bundler version: 2.2.16
Gem version: 3.0.6

Useful resources that have helped me over the years and with the making of this video:

- https://guides.rubygems.org/make-your...
- https://bundler.io/guides/creating_ge...

Комментарии

Информация по комментариям в разработке