Ruby RSpec: Mocks, Doubles, and Spies with Constructor Injection

Inversion of Control (IOC) containers or Dependency Injection  is a common design pattern used to help engineers "inject" different instances of an object at runtime into services, controllers, or gateway classes. This concept is somewhat foreign to the Ruby on Rails community but valuable in some contexts. Most unit tests in RoR won't utilize mocks and stubs and instead opt for direct integration with the database. This article provides an alternative to integration testing by unit testing through constructor injection. In this example, we will test the business logic that operates between an API request and an external, third-party web service. I will note that this pattern forces developers to consider not using patterns like that in active record callbacks. The problem with callbacks is they are hard to test and can conflate what business rules exist in a domain context . Instead, you can move these operations into "service" classes . This enables future dev

Coding Is a Form of Expression

🖼 The most challenging part about being a software engineer is that I deeply enjoy sharing my work. You can learn a lot about someone and the world by studying their work. ✍️ My writing style is logical and thoughtful but still carries its own artistic linguistics and style. What I create is useful, long-standing, and symbiotic. Hundreds of thousands of people depend on my work. 🌌 The code, process, and execution have a particular instinctual and creative attraction some might appreciate. They may link the connections they share with the world to my work. It may bring and interesting and new perspective to their world. 🗝 Unfortunately, very few people will ever see, understand, or appreciate my work. Though true, the community that does understand gets a special insight into me and together we learn and grow from it.

AWS Lambda HTML to PDF

The Nightmare is Over Rendering PDF in Lambda took longer than expected. Tutorials exist in both AWS Lambda and the Serverless Framework. Most do not work, though. The wktohtml and phantomJS libraries in nodeJS are problematic. They don't fully support NodeJS 12.X. So fear no more, some people have figured it out. Headless Chromium to the Rescue The key is to use the chrome-aws-lambda tooling. The catch is you must install a Lambda layer (instructions exist in the Readme). Serverless provides an easy way to apply layers. You can always manually add one in the Lambda AWS dashboard. Once there, you can write a Lambda function to load a headless browser to perform work. I hope this is helpful to you! Share your thoughts in the comments!

Modifying the timezone in Ruby or with ActiveSupport

Sometimes you may need to query an SQL record in ruby and convert the UTC time into a local timezone. This is usually done in a framework like Ruby on Rails. Many web frameworks use the Active Support gem. From their enhanced tooling, they may set the timezone on the thread by calling: = "Requests Time Zone". The Time class in ruby (w/ ActiveSupport) can then access this by calling the getter method: Here are some examples of how this plays out in action. See the TimeZone documentation if you need more info. Hope this may be helpful and please comment if you have any questions or additional advice!

Java Base64 URL Safe Encoding

When it comes to common tooling in Java, Guava is your best friend. If you are still using Apache Commons, stop now. Below is the gradle dependency information for guava as of this writing.

Microservices Tech Stack with Spring and Vert.X

It’s been awhile since my last blog post, and it’s been for several reasons. The primary, is that our team has been challenged to implement a Microservice Architecture (MSA) that fit’s my current company's needs. It’s been a process defining the stack, learning the new stack and providing tooling/components for developers to innovate.

Understanding Immutable Classes In Java

I recently reviewed an article that claimed immutable classes in Java are not always thread safe. Ultimately, this is not true since any immutable class cannot contain state and therefore no two threads could change it's state. To understand this more, I would like to do a quick dive into what an Immutable class is in Java.