Asserting method calls with Minitest

Minitest has support for stubbing via Minitest::Mock. This is a good fit for providing fake results to a caller, but what about asserting that a method is actually called? To do this, you can leverage the fact that if the stubbed value is callable, it will be called. This means that you can provide a mock, then expect that the...

Converting geofiles to WKT using ogr2ogr

I love gdal, particularly ogr2ogr. Like ffmpeg, and convert, it’s just one of those convert anything to anything commands that is so handy to know about. ogr2ogr is part of the GDAL library, and is particularly suited to converting files containing geospatial data from one source to another. I often use this tool to convert shapefiles into GeoJSON for example,...

Tapping targets with Stimulus

Normally I would use Bootstrap’s stretched link behaviour to implement functionality where clicking anywhere on a containing element triggers a link element. This is useful for cards, menus, and other cases where a ‘primary’ link can benefit from a larger tap target. Bootstrap’s stretched link works by adding an ::after pseudo element to the link element with the stretched-link class,...

iOS Action Sheet with Strada

Virtualtrails uses Strada to bridge native iOS code to the web application, including notifications, native Apple + Google Signin and Apple Healthkit integration. I added a feature yesterday to replace a Bootstrap dropdown with a native iOS sheet, just because it’s a more intuitive experience for users. Strada has two parts - the web side (which is in the form...

Implementing an around callback with Minitest using Ruby

I use both RSpec and Minitest, but prefer Minitest. It’s not quite as feature-rich as RSpec, but I find that I prefer the tests I write in Minitest - they are more Ruby-ish, and aren’t as reliant on RSpec’s DSL to work. I don’t use around callbacks in RSpec very often, but it is something I recently found myself wanting...

Auto-resizing images for .ico files using ImageMagick

There’s a bit of a mystery about how relevant favicon.ico files are in 2024. Like it not though, they are the lowest common denominator, so they still have some use. Today I learned about a handy option that can be passed to ImageMagick that will automatically resize a source into a range of common dimensions to be packed into an...

Generating responsive utility classes with Bootstrap

I’m a big fan of Bootstrap, I use it a lot. I’ve used it for many years, and with the recent support for theming with CSS variables, and for their utility API, I’ve found I can have the best of both worlds - a rich and capable library of components, along with an extensive class-based approach for making tweaks to...

How to rearrange menu bar icons in Mac OS

This is a tip I re-discover every couple of years, then forget until I find my menu bar getting a bit cluttered up again. Holding down the Command key allows menu icons to be dragged backwards and forwards along the menu bar to order them. This is available for all items other than the control center and date/time, including system...

Logging the DOM state of an element with testing-library

I’m sure this is all over testing-library documentation, but I haven’t had to do this before, so I think it’s worth a quick post about. If I’m writing a testing-library assertion, every now and then the test won’t pass, because the element I expected to be present, was not. Usually, when this happens, a snippet of the DOM will be...

Stretching interactive elements

Stretched links have been a feature of Bootstrap for some time, but it’s quite a useful technique to understand, because the functionality it offers - expanding the tap target of an element, works for any element that can be interacted with with a tap or mouse gesture, not just links. Some common examples include: Buttons Inputs Labels The way that...