All posts tagged with 'ruby'
Waiting for it with Capybara’s synchronize method
Feature specs are notorious for their potential to flake. It’s possible for the results of feature specs to be inconsistent because they have to deal with asynchronous state. In a typical test environment, there’s a single Ruby process at play, so test code will be executed in order as written – we can reasonably expect one line to complete before the next is executed. But when it comes to feature specs… Continue reading
The Other Copilot: Coding with AI
It seems Copilots are ten a penny these days. While our CoPilot accountant partners are a human way to support you using FreeAgent, the flight term has really taken off(!) as branding for AI tools, GitHub’s Copilot being just one of them. The rise of AI tooling for developers has sparked a lot of discussion and controversy as of late. It’s also seen rapid development and innovation, with several code… Continue reading
How the Ruby Interpreter Creates Methods on the Fly
(And why it matters!) I was lucky enough to attend last year's EuRuKo, the travelling European Ruby conference. A theme of the conference (for me) was Ruby's infamous embrace of metaprogramming, which I've had little exposure to in my day-to-day as a Rails dev. The approach to this discussion was inspired by this great talk by Masafumi Okura on Code Reading, and much of the detail comes from the book… Continue reading
Ease into Ruby with a Python background
Starting your first role as a software engineer and having no knowledge of the programming language used in your organisation sounds like a nightmare at first, as thoughts of the imposter syndrome that many of us seem to suffer from these days start to take over. But worry not. At FreeAgent the environment is very friendly and relaxed, allowing you as a new joiner to focus on learning and integrating… Continue reading
Readable Dates in Rails
I was playing around in Swift recently, and wanted a reference to 'one day ago'. This is simple enough in human terms: if it's 9:30 on the 18th of September, 'one day ago' means 9:30 on the 17th of September. The Swift code to do this looks like this: Calendar.current.date( byAdding: .day, value: -1, to: Date.now ) ...and that's just a bit much, isn't it? First we need to access Calendar.current, a singleton… Continue reading
Type checking in Ruby – Part 1
Over the course of a career in software engineering, we learn to love elements of our tooling and dislike others - that’s perfectly natural. As requirements change, including our own need to improve as engineers, so does what appeals to us when reaching for a new framework, language or library. A common path for lots of engineers will have been to learn something like C or C++, both strongly typed… Continue reading
An introduction to object-oriented programming
Object-oriented programming, or OOP, is a programming paradigm centred around the concept of objects. This article will aim to provide a basic understanding of objects, classes, OOP principles and various other concepts within the paradigm. Code examples will be mediated in the Ruby programming language, which is an example of an object-oriented language. In Ruby, any value is an object, even data types like String and Integer, which are often… Continue reading
Titlecase, underscore and laser guns
Not so long ago, I had an opportunity to peek under the hood of titlecase and underscore methods, the tiny cogs of the “Rails magic” machine. The latter turned out to be a very interesting function—a lot of hard-to-follow transformations, secret injections and the like. All of these bits significantly contributed to an odd-looking bug I’ve been working on. Today, we’ll unravel the implementation of both methods and look in… Continue reading
Timecop vs Rails TimeHelpers
TL;DR - You probably can’t replace Timecop with Rails' built in TimeHelpers, as TimeHelpers only recreates Timecop’s freeze method, and can’t handle nested travelling. Timecop is the go-to gem for testing time-dependent code, as it allows you to manipulate the current time during test runs. This is important because without control over the time, flakey tests can emerge in your codebase. A very simple example is testing the created_at attribute… Continue reading
Testing Child Processes in Ruby
I was recently writing a piece of code that we wanted to act as a supervisor of child processes. We wanted to ask this supervisor the following “Hello there, would you mind running this task in a child process? Thanks!”. From here the supervisor would create a process, keep track of it so we can stop it if necessary, and run the given piece of code in it. This supervisor… Continue reading