SASS: Adding, removing and converting units

Posted 3 months ago by Dominik Schöler.
sitepoint.com

Multiply by 1x the unit: $number = 13 $length = $number * 1px // => 13px Removing a unit

When loading Yaml contents in Ruby, use the :freeze argument to deep-freeze everything

Posted 3 months ago by Arne Hartherz.

Ruby methods which load from a Yaml file, like YAML.safe_load or YAML.safe_load_file, support passing freeze: true to...

Creating a self-signed certificate for local HTTPS development

Posted 3 months ago by Arne Hartherz.

Your development server is usually running on an insecure HTTP connection which is perfectly fine for development.

Maintaining custom application tasks in Rails

Posted 3 months ago by Emanuel.

Here are some hints on best practices to maintain your tasks in larger projects. Rake Tasks vs. Scripts

Disable PostgreSQL's Write-Ahead Log to speed up tests

Posted 4 months ago by Michael Leimstädtner.
edgeapi.rubyonrails.org

The linked article suggests an interesting way to speed up tests of Rails + Postgres apps: PostgreSQL allows the creation of...

open-next-failure: An alias to speed up test debugging

Posted 4 months ago by Michael Leimstädtner.

Getting an entire test suite green can be a tedious task which involves frequent switches between the CLI that is...

Capistrano 3: Running a command on all servers

Posted 4 months ago by Dominik Schöler.

This Capistrano task runs a command on all servers. bundle exec cap production app:run cmd='zgrep -P "..." RAILS_ROOT/log/production.log...

Gitlab: How to cancel redundant pipelines

Posted 4 months ago by Emanuel.

In the Gitlab settings the flag Auto-cancel redundant pipelines is enabled by default. This auto-cancels jobs that have...

OpenAI TTS: How to generate audio samples with more than 4096 characters

Posted 5 months ago by Michael Leimstädtner.

OpenAI is currently limiting the Audio generating API endpoint to text bodies with a maximum of 4096 characters.

Livereload + esbuild

Posted 5 months ago by Tobias Kraze.

Getting CSS (and JS) live reloading to work in a esbuild / Rails project is a bit of a hassle, but...

RSpec: Messages in Specific Order

Posted 5 months ago by Julian.

tl;dr You can use ordered to ensure that messages are received in a specific order. Example expect(ClassA).to...

RSpec: Composing a custom matcher from existing matchers

Posted 5 months ago by Henning Koch.

When you find similar groups of expect calls in your tests, you can improve readability by extracting the group into...

Ruby: Using `sprintf` to replace a string at fixed named references

Posted 5 months ago by Felix Eschey.
docs.ruby-lang.org

The sprintf method has a reference by name format option: sprintf("% d : % f", { :foo => 1, :bar => 2 }) # => 1 : 2.000000

Using Rationals to avoid rounding errors in calculations

Posted 5 months ago by Martin Schaflitzl.
ruby-doc.org

Ruby has the class Rational which allows you to store exact fractions. Any calculation on these variables will now use...

A reasonable default CSP for Rails projects

Posted 5 months ago by Tobias Kraze.

Every modern Rails app should have a Content Security Policy enabled. Very compatible default The following "default" is a minimal...

How to: Upgrade CarrierWave to 3.x

Posted 6 months ago by Dominic Beger.

While upgrading CarrierWave from version 0.11.x to 3.x, we encountered some very nasty fails. Below are the basic...

Zeitwerk: How to collapse folders in Rails

Posted 6 months ago by Niklas Hä..

All direct child directories of app are automatically added to the eager- and autoload paths. They do NOT create a...

Solving "TypeError (nil can't be coerced into Integer)" in the Rails console / IRB

Posted 6 months ago by Dominik Schöler.

On the Rails console, assigning an object to a variable can lead to this strange error (without stacktrace): irb > recipient...

Ruby: `extend` extends the singleton class's inheritance chain

Posted 6 months ago by Felix Eschey.

In the discussion of the difference between include and extend in Ruby, there is a misconception that extend would add...

Heads up: Quering array columns only matches equally sorted arrays

Posted 6 months ago by Michael Leimstädtner.

Given you have an array column like this: create_table "users", force: :cascade do |t| t.integer "movie_ids", default: [], array...

RSpec: Leverage the power of Capybara Finders and Matchers for view specs

Posted 6 months ago by Felix Eschey.
thegnar.com

View specs are a powerful tool to test several rendering paths by their cases instead of using a more costing...

Spreewald, Cucumber: Selector for the nth element

Posted 6 months ago by Felix Eschey.

The recommended additional setup of the spreewald gem, a useful set of cucumber steps, includes adding a file for defining...

RSpec: Efficiently rerunning failed examples during development

Posted 7 months ago by Martin Schaflitzl.
rspec.info

Note Don't use reruns as a mean to work around flaky tests. You should always try to fix those...

Using Ruby's Method objects for inspecting methods

Posted 7 months ago by Felix Eschey.
ruby-doc.org

Do you remember finding where a method is defined? I recently learned from a senior colleague that Method objects are...