Tech tips
subscribe via RSS
Blog articles | Continuous Integration | Tech tips |
-
Have you ever used Ruby's Object#method?
Object#method
is a little-known, yet very interesting Ruby method. Let’s see how it works and how you can use it in your code. -
Estimate database connections pool size for Rails application
Configuring the database connections pool for the Rails app might not be a straightforward task for many programmers. There is a constraint of max opened connections on a database level. Your server environment configuration can change in time and affect the number of connections to the database required. For instance number of servers you use can change when you autoscale it based on the web traffic. It means that the number of web processes/threads running for Puma or Unicorn servers could change. All this adds additional complexity. When you use two databases (e.g. Postgres + Redis), everything gets more complex. In this article, we will address that. You will learn how to estimate needed database connections for your Ruby on Rails production application.
-
Querying single columns in Rails Active Record using the #pluck method
Have you heard of the #pluck method from Rails’ Active Record? Read on to see what it does and how it can be used to easily query single columns from your database!
-
Using Ruby's 2.7 new #tally method
Ruby 2.7 introduced the
Enumberable#tally
method. It allows to easily count elements’ occurrences in a given collection. In other words, it literally tallies them up. :) -
Fix: 'warning: Using the last argument as keyword parameters is deprecated'
Have you encountered the
warning: Using the last argument as keyword parameters is deprecated
message in your Ruby project? You probably started seeing this after upgrading your project to Ruby 2.7. This version introduced the deprecation as a means to prepare users for a breaking change in Ruby 3. Let’s learn how to fix this! -
How and when to use Ruby case statements
Using the
case
expression in Ruby is a great way to write conditionals in a clear, and succinct way. Despite that, it’s not hard to encounter convolutedif
constructs in places where refactoring to thecase
statement would result in huge improvements. Let’s learn more about thecase
expression and when it’s best to use it. -
How to load Ruby gems from cache on Github Actions
How to start CI build faster by loading Ruby gems from cache on Github Actions? You can start running your tests for a Ruby on Rails project quicker if you manage to set up all dependencies in a short amount of time. Caching can be helpful with that. Ruby gems needed for your project can be cached by Github Actions and thanks to that they can be loaded much faster when you run a new CI build.
-
Understanding and using Ruby's powerful #grep method
Ruby is known for its many handy methods. I’d like to take a look at one that is a little bit less known, but quite powerful nonetheless: the
#grep
method. -
Setting up Knapsack Pro in your Ruby RSpec project
Knapsack Pro offers two modes for RSpec tests in your Ruby application: the Regular Mode and the Queue Mode. They differ in their approach towards dividing your test files between parallel CI nodes.
-
Best Heroku add-ons for Ruby on Rails project
After working for over 8 years with Heroku and Ruby on Rails projects I have my own favorite set of Heroku add-ons that work great with Rails apps. You are about to learn about the add-ons that come in handy in your daily Ruby developer life.
-
RSpec testing parallel jobs with CircleCI and JUnit XML report
You will learn how to run RSpec tests for your Ruby on Rails project on CircleCI with parallel jobs to shorten the running time of your CI build. Moreover, you will learn how to configure JUnit formatter to generate an XML report for your tests to show failing RSpec test examples nicely in CircleCI web UI. Finally, you will see how to automatically detect slow spec files and divide their test examples between parallel jobs to eliminate the bottleneck job that’s taking too much time to run tests.
-
How to build Knapsack Pro API client from scratch in any programming language
You will learn how to integrate with Knapsack Pro API to run parallel tests in any programming language for any testing framework. You will see what’s needed to build from scratch Knapsack Pro API client similar to our existing clients like
knapsack_pro
Ruby gem,@knapsack-pro/jest
for Jest in JavaScript, or@knapsack-pro/cypress
for Cypress test runner (also in JavaScript). -
Fix intermittently failing CI builds due to flaky tests in RSpec
Randomly failing CI builds can be frustrating. One run is green, another is red (with no changes in the code!). Disheartening. Let’s see what can be done with this.
-
How to merge SimpleCov results with parallel Rails specs on Semaphore CI
If you are running Rails specs on parallel machines with Knapsack Pro, one challenge you will run into is combining the code coverage results generated by SimpleCov.
-
How to build native integration with Knapsack Pro API to run tests in parallel for any test runner (testing framework)
Do you know that Knapsack Pro API can work with any test runner in any programming language?
-
How to run slow RSpec files on Github Actions with parallel jobs by doing an auto split of the spec file by test examples
Splitting your CI build jobs between multiple machines running in parallel is a great way to make the process fast, which results in more time for building features. Github Actions allows running parallel jobs easily. In a previous article, we explained how you can use Knapsack Pro to split your RSpec test files efficiently between parallel jobs on GitHub Actions. Today we’d like to show how to address the problem of slow test files negatively impacting the whole build times.
-
How to merge Cypress test reports generated by Mochawesome on Github Actions
Looking through CI logs to find out which of your Cypress tests failed can be time consuming and error-prone, especially when your tests are spread out across several machines. With the Mochawesome test report generator and Github Actions, you can easily generate a beautiful, easy-to-read report of your test run, which merges results from all parallel nodes.
-
URI.escape is obsolete. Percent-encoding your query string
Have you encountered one of those warnings in your Ruby 2.7.0 project?
-
GitHub Actions CI config for Ruby on Rails project with MySQL, Redis, Elasticsearch - how to run parallel tests
You will learn how to configure Ruby on Rails project on GitHub Actions. This specific Rails project has MySQL and Redis database. There is also Elasticsearch service running on CI. If your project is close to that setup below GitHub Actions yaml configuration will allow you to run tests on GitHub CI server.
-
CodeClimate and CircleCI 2.0 parallel builds config for RSpec with SimpleCov and JUnit formatter
How to merge CodeClimate reports for your RSpec test suite executed with parallel builds on CircleCI 2.0? You will learn how to run RSpec parallel tests for your for Ruby on Rails project using CircleCI and how to send test coverage merged from parallel jobs into CodeClimate. We will cover config examples for:
-
How to merge CodeClimate reports for parallel jobs (CI nodes)
If you run tests on parallel jobs (using CI parallelisation) you need to merge CodeClimate reports from each parallel job (CI node) into a unified report.
-
Handle invalid JSON payload in Rails 5+ API. Catch JSON parse error
When someone post invalid JSON payload to your Ruby on Rails URL endpoint then Rails crashes with 500 error. We could render nice message instead of the error. For instance if you have public API you may want to show reason of the error to explain to your API client why the request failed.
-
CircleCI 2.0 cache Ruby gems or npm dependencies
CircleCI 2.0 allows us to cache specific files or folders. We can use that to cache ruby gems installed with bundler and restore them when we will run another CI build. This way new CI build could run faster by using cached files from the previous build. This article shows you how to cache npm dependencies as well.
-
Clean RSpec configuration directory structure for Ruby on Rails gems needed in testing
When your Ruby on Rails project is getting bigger your test suite as well. You need to test more of your business logic and sometimes you will use other gems that can help you with that. Most of the time you may need something like
database_cleaner
,capybara
for feature tests orrspec-sidekiq
to test your workers. -
How to run tests in Minitest continuously with dynamic test files loading
Recently I’ve been looking into the source code of Minitest to find out if I can run some tests and then dynamically run another set of tests once the previous run is done. This would allow me to provide dynamically a list of tests to execute on my parallel CI nodes to run CI builds faster.
-
How to export test suite timing data from Knapsack Pro API
Knapsack Pro tracks your CI builds and how long each test files took to run on one of parallel CI nodes. Thanks to that Knapsack Pro can prepare the optimal test suite split for your future test suite runs on your CI provider.
-
CircleCI 2.0 Capybara feature specs - Selenium webdriver with Chrome headless
I’ve been using Capybara-WebKit for a long time but while switching from CircleCI 1.0 to CircleCI 2.0 I had some problems to use it on the CI.
-
When distributed locks might be helpful in Ruby on Rails application
During this year I noticed 2 similar concurrency problems with my Ruby on Rails application and I solved them with distributed locks. I’m going to show you how to detect if your application might have a concurrency problem and how to solve it.