Weeknotes 33
13th February, 2022
“Testing Rust”
-
Last week I wondered if Hugo did anything to handle em dashes. I’ve been wondering for a while if and when I should be using them, so I investigated.
Hugo uses the Goldmark Markdown processor by default, which automatically converts
--
to an En dash, and---
to an Em dash which means there is nothing to do other than start using double or triple dashes when writing Markdown 🙌 -
The amount of time it takes WhatsApp to start on my MacBook Air M1 is hilarious. We can probably blame Electron in some capacity </s>, but in the meantime I’m going to try the web version.
-
I ran this site through Google’s Lighthouse tool in Chrome. It scored pretty well but did throw up a couple of issues. In particular, there was an accessibility related change I could make to ensure heading tags were in the correct source order. That is a worthwhile change to make.
I’m not convinced that all the rules make sense, so I’m not taking all the suggestions verbatim. It can easily become cargo culting without any real benefit.
-
My Rust project is coming along. I already had some integration tests in-place (written last week using a nice library called
assert_cmd
) and this week I turned my attention to unit tests.I’d written some code that performs requests against a JSON API and felt it really needed testing. I was not looking forward to this as I had imagined that mocking the network requests would be difficult. Fortunately, I found a nice library called wiremock which made it fairly easy. It works by starting a separate process for each test and stubbing out the responses. This would not be viable in Ruby, but works well here.
Testing the code did require some minor changes so I could pass in the URL of the test server started by
wiremock
. But like most changes required for testing, it made the code better — less coupling, fewer responsibilities.Interestingly, it seems the standard Rust way to add unit tests is to put them alongside the code itself, in the same file. On the one hand I like this a lot because you don’t have to constantly switch files to see what you’re testing, on the other, I wonder just how long my files are going to get if everything is in one file?
-
I used
ActiveRecord::Relation#destroy_by
this week for the first time. It’s a nice shorthand forrelation.where(condition).destroy_all
.I often find myself not knowing about the latest features in Rails, but these things are just a Google away most of the time so I don’t suppose it matters.
Saying that, I do now subscribe to This Week in Rails in order to have some visibility of what new stuff is coming to the framework.
-
jless seems cool — a command-line JSON viewer.
JLess is a command-line JSON viewer designed for reading, exploring, and searching through JSON data.
I usually use
jq
in it’s most basic form,jq .
, for things like this, but whilst is does a great job of formatting, highlighting, and displaying the JSON it doesn’t let you interactively navigate around. Sometimes figuring out the shape of the data is what I’m looking for.I hope to remember I have installed
jless
when the next use-case pops up 😬