...external commands from within Ruby, but the most powerful ones are Open3.capture3 and Open3.popen3. Since those can do almost everything you would possibly need in a clean way, I prefer...
...to simply always use them. Behind the scenes, Open3 actually just uses Ruby's spawn command, but gives you a much better API. Open3.capture3 Basic usage is require 'open3'
When testing JavaScript functionality in Selenium (E2E), you may need to access a class or function inside of a evaluate_script block in one of your steps. Capybara may only...
...your tests (and neither in the dev console). The following principles/concepts also apply to Sprockets. Say we have a StreetMap class: // street_map.js class StreetMap { function getLatitude() { // ... } function renderOn(mapElement) { // ... } }
...but does not have to be. It's actually very easy when done right. Summary (tl;dr) Here's the short version: Define a table_name_prefix method in the...
...not define any table_name_prefix in ActiveRecord classes inside of it. If this sounds familiar, we have a card about using it already. This card explains why you want...
...following places and uses the first implementation it finds: Methods from the object's singleton class (an unnamed class that only exists for that object) Methods from prepended modules (Ruby...
...from the object's class Methods from included modules Methods from the class hierarchy (superclass and its ancestors) Example Let's say we have the following class hierarchy: class Superclass...
I was recently asked to optimize the response time of a notoriously slow JSON API endpoint that was backed by a Rails application. While every existing app will have different...
...be used to reproduce the results. I tried to mimic the case where things started out fast but did not scale well: There is an existing Rails App with a...
...cases beyond that to make your life easier. For this cheatsheat I tried to structure the most useful commands by different use cases, such that a practical oriented overview of...
...some commands I added some tips for their usage and further details on their subcommands For most of the commands shortly explained here, there are some examples along with a...
Rails supports time zones, but there are several pitfalls. Most importantly because Time.now and Time.current are completely different things and code from gems might use one or the other.
Your life will be easier if your application does not need to support time zones. Disable them like this: config.time_zone = 'Berlin' # Your local time zone config.active_record.default_timezone...
...debugging console if developer tools are already open. Do this. Note that since JavaScript is single-threaded, you cannot interact with your app's frontend while the debugging console is...
...inspect the current DOM. In a @javascript scenario, observe the current frontend state in the Selenium-controlled browser. If you run E2E tests in headless Chrome, you may need to...
...request to save the movie. Select the request from the list and go to the sub-tab Payload. You should see your request's payload as a list of key/value...
...used the square brackets in the payload keys to group all movie attributes into one sub-hash, params['movie']. Let's take a look at only the movie-related attributes...
...intrinsic width of your content play together. The attached article explains the differences. In summary: If a flex-basis is set, that is used as the basis
...basis is set, the width is used as the basis If neither flex-basis nor width is set, the content's computed width is used as the basis
...be answered with an empty response if the underlying content hasn't changed. This saves CPU time and reduces the bandwidth cost for a request/response exchange to about 1 KB...
...can be considered secure. Random masking of CSRF tokens was introduced to mitigate BREACH, a side-channel attack against HTTPS that was published in 2013. BREACH is pretty hard to...
Jasmine specs for the frontend often need some DOM elements to work with. Because creating them is such a common task, we should have an efficient way to do it...
...Let's say I need this HTML structure: item 1 item 2 This card compares various approaches to fabricating DOM elements for testing. Constructing individual elements While you can use...
By default, Rails views escape HTML in any strings you insert. If you want to insert HTML verbatim, you need to call #html_safe. However, #html_safe does not "unescape...
...a string. It merely marks a string as safe for unescaped insertion. How html_safe works Calling html_safe on a String returns a new object that looks and acts...
TL;DR When using Cache-Control on a Rails application, make sure the Vary: Accept header is set. Proxy caching is a good feature to serve your publicly visible application...
...server SHOULD include a Vary header field with any cacheable response that is subject to server-driven negotiation. Doing so allows a cache to properly interpret future requests on that...
...operators typeof and instanceof which work very differently. JavaScript has some primitive types, like string literals, that are not objects (as opposed to Ruby, where every value is an object...
...Some values are sometimes a primitive value (e.g. "foo") and sometimes an object (new String("foo")) and each form requires different checks There are three different types for null (null...
on the bash (issued as postgres user) Start/Stop/Restart PostgreSQL pg_ctl -D $configdir start|stop|restart Start/Stop/Restart the corresponding PostgreSQL using the given configuration directory. The configuration directory should contain...
...the postgresql.conf file. The following example would start the PostgreSQL of our governor instances: pg_ctl -D /var/lib/postgresql/config start PostgreSQL fast shutdown pg_ctl -D $configdir stop -m fast
I recently stumbled upon the Rails feature composed_of. One of our applications dealt with a lot of addresses and they were implemented as 7 separate columns in the DB...
...and Rails models. This seemed like a perfect use case to try out this feature. TLDR The feature is still a VERY leaky abstraction. I ran into a lot of...
For my computer science bachelor's thesis I programmed and evaluated a CLI Test Case Prioritization (TCP) tool for makandra. It has been written as a Ruby Gem and was...
...as T2 > T3> T1 > T4 > T5 > T6. Selection of a strategy In the preselection coverage-, search-based, model- and combinations of different prioritization methods. History- and fault-based approaches could...
This is a presentation from 2019-01-21. Summary We want to move away from jQuery in future projects Motivations are performance, bundle size and general trends for the web...
...can polyfill the missing pieces Unpoly 0.60.0 works with or without jQuery Is jQuery slow? From: Sven To: unpoly@googlegroups.com Subject: performance on smartphones and tablets Hello I just used your...
This is an attempt to list some of those things: On the server Always optimize: Don't do stupid things with the database. Avoid "n + 1" queries. Don...
...Use form models. Optimize on demand: Don't optimize without knowing what's actually slow. Measure first, for example by using a performance monitoring tool like NewRelic, Scout, AppSignal, Skylight...
Spreewald comes with a selector_for helper that matches an English term like the user's profile into a CSS selector. This is useful for steps that refer to a...
...particular section of the page, like the following: Then I should see "Bruce" within the user's profile ^^^^^^^^^^^^^^^^^^ If you're too lazy to manually translate English to a CSS...
...can use find and replace with capture groups (.*?) and backreferences $1 (if you have several groups: $[Capture-Group ID]). Named captures (? .*) are also supported. Examples Replace double quotes with single...
If you want to replace double quotes with single quotes, replacing every " with a ' is prone to errors. Regular expressions can help you out here. Open find and replace...
Embedding videos on a website is very easy, add a tag to your source code and it just works. Most of the time. The thing is: Both the operating...
...an 0.x version and has quite some development dependencies. It has the Apache license. streamio-ffmpeg seems to be perfect, but had its last release in 2016. It offers...
We recommend configuring Selenium's unhandled prompt behavior to { default: 'ignore' } with the monkey patch below. When running tests in a real browser, we use Selenium. Each browser...
...is controlled by a specific driver, e.g. Selenium::WebDriver::Chrome for Chrome. There is one quirk to all drivers (at least those following the W3C webdriver spec) that can be...