Whenever you have to deal with randomness in a jasmine test there are some spy strategies to help you out! Let's say we have a method Random.shuffle(array) to...
...shuffle an array randomly and a class that uses shuffle within the constructor. returnValue & returnValues it('shuffles the array', () => { spyOn(Random, 'shuffle').and.returnValue([3, 2, 1])
...driver_opts directly. However, this is deprecated and will be removed in version 4 of selenium-webdriver. Version 5.x will drop support for passing the service options as hash...
...Option 2: Connect tests to a manually started chromedriver Warning This does not work with selenium-webdriver > 4 anymore. You can pass in a specific port as attribute of the...
When using Rails to truncate strings, you may end up with strings that are still too long for their container or are not as long as they could be. You...
...did not use it. Since Firefox 7 you can! Note that this only works for single-line texts. If you want to truncate tests across multiple lines, use a JavaScript...
Option 1: Creating a self-signed certificate with the openssl binary As igalic commented on this gist. openssl req -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout server.key...
make it an X.509 certificate, not a Certificate Signing Request. Option 2: Creating a self-signed certificate with the mkcert binary The linked tool mkcert helps you to setup...
If you're using a Redis cache in Rails (e.g. :redis_cache_store), it's possible to configure additional parameters for your Redis connection. Example config for Rails 7.2
...store = :redis_cache_store, { pool: { timeout: 0.5 }, read_timeout: 0.2, # default 1 second write_timeout: 0.2, # default 1 second # Attempt two reconnects with some wait time in between reconnect_attempts...
This RailsCast demonstrated a very convenient method to activate VCR for a spec by simply tagging it with :vcr. For RSpec3 the code looks almost the same with a few...
...minor changes. If you have the vcr and webmock gems installed, simply include: # spec/support/vcr.rb VCR.configure do |c| c.cassette_library_dir = Rails.root.join("spec", "vcr") c.hook_into :webmock end RSpec.configure do |c...
...use heredoc to avoid endlessly long lines of code that nobody can read. Heredoc strings preserve linebreaks and can be used like this: def long_message puts(<<-EOT)
...a very long message... Sincerely, foobear EOT end <<-EOT will be somewhat of a placeholder: anything you write in the line after you used it will be its value until...
...loading associations. By preloading associations you can prevent the n+1 query problem that slows down a many index view. You might have noticed that using :include randomly seems to...
...involved table with a condition like...
...WHERE id IN (123, 125, 170). Execute a single query for a huge table joined from all involved tables. ActiveRecord prefers option 1, probably...
...not necessary to add a version constraint next to your packages in the package.json. Since all versions are saved in a lockfile, everyone running yarn install will get exactly the...
...within the yarn install command: Before: unpoly@^2.7.2: version "2.7.2" resolved "https://registry.yarnpkg.com/unpoly/-/unpoly-2.7.2.tgz#55044c08bce0984c000f7cd32450af39271727de" integrity sha512-jfBbBRBQMCZZcNS6fckKpFunfdiTDBXW8yxRKqLs09jSrYYUDPd+YuyDoXjABXOro0aDUIMcmyTc7moc1/Z5Tw== After: unpoly@x: version "2.7.2" resolved "https://registry.yarnpkg.com/unpoly/-/unpoly-2.7.2.tgz#55044c08bce0984c000f7cd32450af39271727de" integrity sha512-jfBbBRBQMCZZcNS6fckKpFunfdiTDBXW8yxRKqLs09jSrYYUDPd...
This is a short overview of things that are required to upgrade a project from the Asset Pipeline to Webpacker. Expect this upgrade to take a few days even the...
Cleanup Remove all gems you used for assets and the Asset Pipeline itself, e.g. sass-rails, uglifier, autoprefixer-rails, sprockets-rails, jquery-rails, bootstrap-sass and many more.
...are using the routing-filter gem in your Rails 7.1 app for managing URL segments for locales or suffixes, you will notice that the filters do no longer apply, routes...
...your controller action. This way you receive a locale parameter from a matching URL segment. Before Rails 7.1, this method returned all associated routes (as enumerable) and the using methods...
...for an option like Yarn's --frozen-lockfile which validates that. Here is what seems to be the way to do it. Using npm clean-install Running npm clean-install...
...versions while npm clean-install will complain. You can use npm ci as a shortcut for npm clean-install. Combine with a cache The idea of a "clean install" is...
...s possible you get this "error" message: *** [err :: example.com] There are no Phusion Passenger-served applications running whose paths begin with '/var/www/example.com'. *** [err :: example.com] This is just because there were...
...no running passenger process for this application on the server which could be restarted. It's not a real error. The application process will start if the first request for...
...they reach approx. 100MB: $ ls -lh log/ -rw-r--r-- 1 user group 55M Sep 15 09:54 development.log -rw-r--r-- 1 user group 101M Aug...
...development.log.0 This behavior is a built-in feature of Ruby's standard Logger class, which Rails uses by default. To control the maximum file size, set config.log_file_size...
...from the app/models folder to the lib/ folder. The approach is applicable to arbitrary scenarios and not limited to API clients. Example Let's say we have a Rails application...
...that synchronizes its users with the Github API: . └── app └── models ├── user │ ├── github_client.rb │ └── sychronizer.rb └── user.rb In this example the app folder contains domain dependent code (user.rb and sychronizer.rb) and domain independent...
Most of the time, when you are interested in any log output, you see the logs directly on your console or you tail / grep some logfile in a separate terminal...
...In rare cases it's helpful to redirect the Logger output temporary to e.g. STDOUT. Rails.logger = Logger.new(STDOUT) ActiveRecord::Base.logger = Logger.new(STDOUT) User.save! #=> D, [2025-09-08T11...
...set the Sass options. Webpacker const sassLoaderConfig = environment.loaders.get('sass') const sassLoaderIndex = sassLoaderConfig.use.findIndex(config => { return config.loader === 'sass-loader' }) // Disable deprecation warnings inside dependencies sassLoaderConfig.use[sassLoaderIndex].options.sassOptions.quietDeps = true sassLoaderConfig.use[sassLoaderIndex].options.sassOptions.silenceDeprecations = ['import...
module.exports = { module: { rules: [ { test: /\.s[ac]ss$/i, use: [ "style-loader", "css-loader", { loader: "sass-loader", options: { sassOptions: { quietDeps: true, silenceDeprecations: ['import'], }, }, }, ], }, ], }, }; ESBuild esbuild.build({ // ... plugins: [ sassPlugin({ quietDeps: true, silenceDeprecations...
...the test, as if the callback function is not executed in the test. However, since the test does not fail, the method :my_method must have been called during the...
...where the method :my_method should be called This will execute the original implementation (see here...
This guide shows how to create an AngularJS application that consumes more and more memory until, eventually, the browser process crashes on your users. Although this guide has been written...
...for Angular 1 originally, most of the advice is relevant for all client-side JavaScript code. How to observe memory consumption To inspect the amount of memory consumed by your...
...to add some custom functionality. This card contains some tips how to achieve this. Setup Basically, follow the guide in the Rails documentation. The automated script may not work with...
...it should be easy to fix. If you don't want the default css shipped with Action Text, you can copy the stylesheet from basecamp's github into your project...
...t easily customizable. Example usage /slackfont Comic Neue to use "Comic Neue" (if installed) /slackfont system-ui to use your desktop's system font in Slack. /slackfont (without an argument...
...the default font. Some fonts may be unavailable If you installed Slack through Snap, only system-wide installed fonts (i.e. fonts located in /usr/share/fonts/ or /usr/local/share/fonts/) are available.
All major browsers (IE8+, FF3.5+, Safari 4+, any Chrome) support sessionStorage, a JavaScript storage object that survives page reloads and browser restores, but is different per new tab/window (in contrast...
...to localStorage which is shared across all tabs). MDN says: The sessionStorage object is most useful for hanging on to temporary data that should be saved and restored if the...
...Before merging back: reinstate reverted features in a temporary branch, then merge that branch. Scenario Consider your team has been working on several features in a branch, made many changes...
...fix them, if necessary. Maybe tests were added that expect the removed functionality as a side-effect. Merge the master into your branch regularly, especially when you have multiple teams...
tl;dr When browsers start to adapt proposals from Open UI, it might not be necessary to use any 3rd party libraries to have nice components and controls in web...
...applications e.g. selects. It would require only a minimum of CSS and Javascript to get them working and looking good. The purpose of the Open UI, a W3C Community Group...