#​560 — July 8, 2021

Read on the Web

Ruby Weekly

Ruby 3.0.2 Released (plus 2.7.4 and 2.6.8) — It’s security release time. Net::FTP and Net::IMAP have some vulnerabilities that have been fixed. The 2.6.8 release also includes some other bug fixes and 2.7.4 is here.

Ruby Core Team

Introducing MemoWise, A New Way to Memoize Methods — MemoWise is “the best way to memoize methods” as it takes care of nil and false values, methods with arguments, and instance variable/method confusion, applying the wisdom of the memoization ages.

Jemma Issroff and Jacob Evelyn

Analyze Your Ruby Apps’ Performance in Real Time with Datadog APM — Drill into error traces with Datadog’s App Analytics to debug and optimize Ruby code by tracing requests across web servers, databases, and services in your environment. Track your apps’ performance with Datadog APM free.

Datadog sponsor

Understanding Factory Bot Syntax by Coding Your Own Factory Bot — Recreating something is always a great way to learn (in programming, at least!) and Jason goes through the whole thing here using the delightful idea of ‘error driven development’ - ha!

Jason Swett

📅  Submit a Talk to the RubyConf 2021 CFP — Taking place in a hybrid online/offline form over November 8-10, RubyConf is keen to receive your talk proposals and they’ve provided quite a lot of detail here. The CFP closes on July 16 (so you’ve got just over a week).

RubyConf

IN BRIEF:

  • Did you know Ruby Together supports the Ruby API (rubyapi.org) project? Here's an update on how it's going and how it's been integrating Ruby 3 type signatures into the docs.

Jobs

Senior Backend Engineer (Remote) — Hiring for backend engineers to build the service infrastructure for our meditation app, Balance, and brain train app, Elevate.
Elevate Labs

Hint is Hiring — We are on a mission to help all software teams reach their full potential. You can help.
Hint

Find a Job Through Hired — Create a profile on Hired to connect with hiring managers at growing startups and Fortune 500 companies. It's free for job-seekers.
Hired

📕 Articles & Tutorials

The Shortest Path to Get Set Up with Automated Accessibility Testing in Rails — If you’ve ever tried to automate accessibility testing, you know how clumsy it can be. This code repo/tutorial shows how easy it can be to get the basics automated quickly.

Kevin Bongart

Understanding How rbenv, RubyGems, and Bundler Work Together — The chain of tools we use every day to do our job mostly “just works”, but how? Subomi dives into each layer, from version manager to bundler, and explains the chain.

Subomi Oluwalana

▶  Tracking Events with Ahoy — The Ahoy gem provides the capability to capture analytics, such as page visits, without sharing the data with any third parties.

Drifting Ruby

Crunchy Bridge: Fully Managed Cloud Postgres — Crunchy Bridge users experience performance improvements, better developer workflow and seamless migration.

Crunchy Bridge sponsor

Asynchronous Background Processing using AWS Lambda Extensions — AWS Lambda Extensions were created so Lambda authors could integrate with various monitoring tools, but LambdaPunch lets you use it in a more general way.

Ken Collins

The Hanami Architecture Explained — Hanami uses concepts like slices and Separation of Concerns to create a flexible application framework that extends beyond web apps.

Sebastian Wilgosz

Under The Hood of the includes Method in Rails

Paweł Dąbrowski

Neovim's Built-in LSP with Ruby and Rails — It’s not quite VSCode, but if you want to use LSP functionality in neovim, here you (mostly) go.

Sheldon Johnson

▶  Spearheading Static Site Generators with Ruby and Bridgetown — Jared White, the creator of the Bridgetown static site generator, discusses the origins and goals of the project.

The Ruby on Rails Podcast podcast

🛠 Code & Tools

Faraday 1.5: A Flexible HTTP Client Library — Where Faraday differs from many other HTTP client options is how it supports multiple backends and has a middleware concept for processing the request/response cycle. Basic usage in case you’ve not tried it before.

Olson, Hobson, et al.

Fisk: A Pure Ruby x86-64 Assembler — An interesting project from tenderlove and a clever bit of work representing x86 assembly language via a mostly implicit Ruby DSL.

Aaron 'tenderlove' Patterson

Everything a Dev Needs to Build Video for Ruby: Powerful API and Analytics

Mux sponsor

Heroku Database Connection Calculator — Optimizing your database pool configuration relies on quite a few variables (number of dynos, workers, processes, threads) so this guide does the math for you while also explaining each calculation.

Rails Autoscale

The Git Gem 1.9.0: A git Wrapper for Use from Ruby — Takes the simple approach for wrapping calls to the usual git binary.

Scott Chacon

WorkingHours 1.4: A Gem to Do Time Calculations with Working Hours — For example, 1.working.day.from_now or Date.new(2014, 12, 28).working_day?

Adrien S

A Minimal Forward Proxy in 150 Lines of Code using Standard Libraries Only

James Moriarty

💡 Tip of the Week

Running specific specs with RSpec

Sometimes when writing Ruby tests with RSpec we want to run the whole test suite. Other times, we want to run only specific tests. Here are a few different ways to only run part of a test suite:

--fail-fast flag

Running a spec file or full test suite with the --fail-fast flag will stop the tests at the first failure. For example: rspec spec --fail-fast will complete fully only if there are no failures in the suite. This can be helpful for large suites.

--example (-e) flag

The --example (or -e) flag takes a string argument and runs only examples whose names include the argument.

For example, if we had this spec file spec/example_spec.rb:

RSpec.describe Example do
  it "runs this specific test" do
    ...
  end

  it "does not run this" do
    ...
  end
end

We can run rspec spec/example_spec.rb -e "specific test" and only the first test will run. This is an additional reason it can be helpful to have well described tests.

:<line_number> flag

We can run an example on a specific line by including that line number right after the specific file when running the test. We can add line numbers to our previous example to clarify:

1 RSpec.describe Example do
2   it "runs this specific test" do
3     ...
4   end
5 
6   it "does not run this" do
7     ...
8   end
9 end

We can run rspec spec/example_spec.rb:2 to only run the first spec.

:focus

If we only want to run a specific context or example, we can add the following to our spec/spec_helper.rb to configure the ability to focus on a specific set of tests:

RSpec.configure do |config|
  config.filter_run focus: true
end

and then pass the symbol :focus as an optional argument to our example or group before running our tests:

describe "only testing this", :focus do
  ...
end

Hopefully some of these methods of running specific tests are useful in avoiding running the full suite unnecessarily!

This week’s tip was written by Jemma Issroff.