3693 cards
Linked contentAuto-destruct in 58 days

CucumberFactory 2.0.1 released

CucumberFactory 2.0.1 fixes an issue with multiline assignments.

2.0.1 - 2020-02-27

Compatible changes

Fix a bug that prevented created records to be named when using multiline attribute assignments

Given "Bob" is a user with these attributes:
  | email | foo@bar.com     |
Linked contentAuto-destruct in 57 days

Updated: How to enable SSL in development with Passenger standalone

Rewrote card with instruction to create a Passenger config file. This way, Passenger will always start with SSL enabled.

Linked contentAuto-destruct in 57 days

Updated: How to make a cucumber test work with multiple browser sessions

  • Simplified step
  • Added section "Effect on other step definitions"
Linked contentRepeats

How to use the Capistrano 2 shell to execute commands on servers

Capistrano 2 brings the shell command which allows you to run commands on your deployment targets.
There is also invoke to run a command directly from your terminal.

Both commands allow running Capistrano tasks or shell commands, and scope to individual machines or machine roles.

Unfortunately Capistrano 3 does not include these commands any more.

cap shell


First of all, spawn a Capistrano shell (we're using the multistage extension here):

$ cap staging shell

In your "cap" shell you can now run Capistrano ta…


Escape a string for transportation in a URL

To safely transport an arbitrary string within a URL, you need to percent-encode characters that have a particular meaning in URLs, like & or =.

If you are using Rails URL helpers like movies_path(:query => ARBITRARY_STRING_HERE), Rails will take care of the encoding for you. If you are building URLs manually, you need to follow this guide.


In Ruby, use CGI.escape:

=> "foo%3Dfoo%26bar%3Dbar"

Do not ever use URI.encode or …

nvm: Setting a default Node.js version

To set a default Node version for new shells, use nvm alias default <VERSION>:

nvm alias default 1.2.3

I like to use the most recent LTS version as my default:

nvm alias default lts/erbium
Linked content

Guide to String Encoding in Ruby

The linked article has a great explanation how to to deal with string encodings in Ruby. Furthermore you can check out some of our cards about encoding:

How to write modular code

Or: How to avoid and refactor spaghetti code

Please note that I tried to keep the examples small. The effects of the methods in this card are of course much more significant with real / more complex code.

Tell don't ask

This is all about where code should live. If you're asking an object a lot about interna, that's a code smell. It would be better to ask the object to do the things you want for you. Try to refactor that out of your method into its own method in the class where it belongs.

class MyClass
def create_target(…

How to make a cucumber test work with multiple browser sessions

Imagine you want to write a cucumber test for a user-to-user chat. To do this, you need the test to work with several browser sessions, logged in as separate users, at the same time.

Luckily, Capybara makes this relatively easy:


Scenario: Alice and Bob can chat
Given Alice, Bob, and a chat session
When I am signed in as "Alice"
And I go to the chat
And I am signed in as "Bob" [session: bob]
And I go to the chat [session: bob]
And I send the message "Hello, this is Alice!"
Then I should see "Hello, this …

Rails: Rest API post-mortem analysis

This is a personal post-mortem analysis of a project that was mainly build to provide a REST API to mobile clients.

For the API backend we used the following components:

  • Active Model Serializer (AMS) to serializer our Active Record models to JSON.
  • JSON Schema to test the responses of our server.
  • SwaggerUI to document the API.

It worked

The concept worked really good. Here are two points that were extraordinary compared to normal Rails project with many UI components:

  • Having a Rails application, that has no UI components (only…

How to: Validate dynamic attributes / JSON in ActiveRecord

PostgreSQL and ActiveRecord have a good support for storing dynamic attributes (hashes) in columns of type JSONB. But sometimes you are missing some kind of validation or lookup possibility (with plain attributes you can use Active Record's built-in validations and have your schema.rb).

One approach about being more strict with dynamic attributes is to use JSON Schema validations. Here is an example, where a project has the dynamic attributes analytic_stats, that we can use to store analytics from an external measurement tool.

  • A g…

Ubuntu: How to disable unused microphone devices

When you are using a dedicated webcam device on a desktop machine, you never want to use its microphone. Here is how to disable it.
This can be useful if "smart" voice chat or phone software picks its microphone at random. If you disable all but one, you can avoid that.

  1. sudo apt install pavucontrol
  2. Launch pavucontrol
  3. Go to the "Configuration" tab at the very right
  4. Disable your webcam's microphone by choosing "Off" from the dropdown menu.

You may use any other mixer tool wher…

Linked contentRepeats

Generating test images on the fly via JavaScript

When you need test images, instead of using services like lorempixel or placehold.it you may generate test images yourself. You can do this via JavaScript.

Here is an ES6 function that generates a simple SVG image and returns it as a data: URI. All browsers support SVG, and you can easily adjust it yourself.

function svgUri(text) {
  let svg = `
    <svg width="320" height="240" xmlns="http://www.w3.org/2000/svg">
      <rect x="0" y="0" width="320" height="240" style...

Handling duplicate links with Capybara and Cucumber

Sometimes, you might have duplicate links on a page. Trying to click those links will by default cause Capybara to raise an Ambiguous match error.

If you do not care about which of those links are clicked, you can disable this errors by adding the following meta step:

When(/^(.*) \[allow ambiguous\]$/)do |step_text|
  prior_match_strategy = Capybara.match
  Capybara.match = :first
  Capybara.exact = prior_match_strategy

Use it with

When I follow "a duplicate link" [allow ambiguous]
Linked content

Structuring Rails applications: the Modular Monorepo Monolith

Root Insurance runs their application as a monolithic Rails application – but they've modularized it inside its repository. Here is their approach in summary:


  • Keep all code in a single repository (monorepo)
  • Have a Rails Engine for each logical component instead of writing a single big Rails Application
  • Build database-independent components as gems
  • Thus: gems/ and engines/ directories instead of app/
  • Define a dependency graph of components. It should have few edges.
  • Gems and Engines can be extracted easier once nece…
Linked contentAuto-destruct in 44 days

Updated: Webpack(er): A primer

Added Webpack 4 example to the "Adding images" section

Linked contentAuto-destruct in 44 days

Updated: Migration from the Asset Pipeline to Webpacker

  • Added check for css extraction in webpacker.yml
  • Added link to Webpack(er) A primer
  • Added item 3 and 4 to the Cleanup section
This website uses cookies to improve usability and analyze traffic.
Accept or learn more