Hello,
This week I reviewed an old paper about “A Model of Creativity and Innovation in Organizations”. While the paper is old (1988) I found it so interesting reading the following quote included in the paper about:
“Quite often I will be tinkering in something that management will have no interest in, yet when I start to develop it into something. there will be a lot of interest. If they had close reins on me, they would have killed a lot of projects at an early stage and nothing would have resulted”
Ruby
How to Use Pattern Matching to Locate Elements in a Hash Array
I wrote an article about how to find an element in bit more complex structure like a Hash with some keys being Arrays of Hashes.
Having a structure like this:
system = {
users: [
{ username: 'alice', role: 'admin', email: '[email protected]' },
{ username: 'bob', role: 'user', email: '[email protected]' },
{ username: 'charlie', role: 'moderator', email: '[email protected]' }
]
}Here is how you can use the find pattern operator =>
system => {users: [*, { role: 'moderator', email: }, *]}
puts email # [email protected]I wrote a bit more about the differences between using Pattern Matching vs Enumerator#find like how do they behave when they cannot find an element and also why is there a new variable called email present after pattern matching.
Development and Testing
Collection of strings to use when writing tests
In case you really need in your test suite to handle real strings of various types, here are some resources you can use:
The Big List of Naughy Strings - a repository containing a huge list of strings that have a good chance to help you catch a bug
Based on an article I created this repository that contains a list of usernames, hostnames and emails that you might want to reserve in your web app.
I collected a bit more resources like this at Resources to use when you want to test strings
Ruby on Rails
Ruby on Rails: Loading Locales with Yes, No, On, and Off
If you write in your locales file keys like this:
en:
terms:
yes: Yes
no: No
switch_on: On
switch_off: Off
accept: true
reject: falseThey will be loaded with booleans like this:
I18n.locale = :en # make sure you have set a default locale
I18n.backend.send(:translations)[:en][:terms]
# => {true => true, false => false, switch_on: true, switch_off: false, accept: true, reject: false}The solution is either to write those keys as string keys ”yes”: “Yes” or to use RubySchema (see the two lines added here: yaml-language-server and the %YAML 1.1 ) and if you editors supports YAML language server (and most of them support either via plugins or natively) you will get warnings or errors when using keys that might be converted to booleans.
# yaml-language-server: $schema=https://www.rubyschema.org/i18n/locale.json
%YAML 1.1
---
en:
yes: "Yes"
on: "On"In case you want to read my exploration to understand why this is happening in Psych gem and why it does implement YAML 1.1 but still return Y and N as strings and not booleans read my full article.
Ruby on Rails
Ruby on Rails 8.1.0 RC1 is out
Ruby on Rails 8.1.0 RC 1 is out and you can create a new Rails app with it like this:
gem install -v 8.1.0.rc1 rails
rails _8.1.0.rc1_ new mynewrails81appGood Enough Testing Workshop
Preregistration for the Reliable Test Case Generation with AI
Join a practical 2 hours live online workshop that teaches you how to guide LLMs like ChatGPT to write smarter, more effective Ruby tests using proven design techniques. I delivered a form of this workshop at EuRuKo this year and it was fully booked and very well received.
If you are subscribed to this newsletter you should have received in your inbox a discount coupon of 20% off for this workshop
Read more about this workshop at Reliable Test Case Generation with AI
AI + LLMs
Some links to read about LLMs
I experiment constantly with various AI/LLMs tools on both development and testing. Here are some links that I think are useful to read:
That’s it for this week,
Lucian
