github.com

Capybara-screenshot can automatically save screenshots and the HTML for failed Capybara tests in Cucumber, RSpec or Minitest. Requires Capybara-Webkit, Selenium or poltergeist for making screenshots. They're saved...

...into $APPLICATION_ROOT/tmp/capybara The attached files contain config for cucumber integration and a Then show me a screenshot step. If your project uses Spreewald, you can use its Then show...

makandra dev

...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...

You need to update a lof gems. Make sure you don't have any version constraints in your Gemfile or your bundle update won't do anything!

...cucumber_priority: bundle update cucumber_priority Upgrade spreewald: bundle update spreewald Upgrade cucumber_factory: bundle update cucumber_factory Upgrade parallel_tests: bundle update parallel_tests Even on the latest version...

options.add_option(:web_socket_url, true) options.add_option(:page_load_strategy, 'none') # required for selenium-webdriver 4.27+ end Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) In combination with...

...Note that you also need to set the :page_load_strategy to "none" for modern selenium-webdriver ≥ 4.27 since those follow the spec more closely than previous versions and respect...

...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...

morris-photographics.com

Some browsers render PNG images with color profiles and other shenanigans, some don't. The cleanest way to have consistent colors across browsers is to convert all your images to...

...a standard color profile, strip the image's original profile and attach the standard profile. If you can't be bothered to convert color profiles, a quicker (but less effective...

Detecting if a Javascript is running under Selenium WebDriver is super-painful. It's much easier to detect the current Rails environment instead. You might be better of checking against...

...the name of the current Rails environment. To do this, store the environment name in a data-environment of your . E.g., in your application layout: <html data-environment=<%= Rails.env %>>

...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...

For searching in large database tables we usually use PostgreSQL's fulltext search capabilities. While this works reasonably well for content primarily consisting of prose, it is not necessarily a...

...good solution for all use cases. The main issue is that it is only possible to search for prefixes of text tokens, which can potentially be unexpected for users.

Native promises have no methods to inspect their state. You can use the promiseState function below to check whether a promise is fulfilled, rejected or still pending: promiseState(promise, function...

// `state` now either "pending", "fulfilled" or "rejected" }); Note that the callback passed to promiseState will be called asynchronously in the next microtask. Usage example: Tests Note Since this card...

...will tell you if there are any and you should not commit when you see them. So go ahead and switch your editor/IDE to automatically remove them for you.

Note that except for RubyMine, the following changes will remove trailing white-space on all lines, not only those that you changed. While this should not be a...

makandra dev

YJIT is Ruby's default just-in-time compiler. It is considered production-ready since Ruby 3.2 (source). To activate YJIT you need two steps: Your ruby binary needs to...

...be compiled with YJIT support. You need to enable YJIT. Getting a Ruby with YJIT support We usually install Ruby with tools like rbenv or asdf. This compiles the ruby...

...popup on all browsers. When you integrate a date picker popup, remember to also set autocomplete="off" on the text input that opens the calendar on click. Otherwise the autocomplete...

...suggestions will cover the calendar box and make it unusable: If you are using a tool like Unpoly you might want to set autocomplete="off" in the JavaScript that also...

Somewhat regularly, you will need to filter a list down to some items and then map them to another value. You can of course chain map and compact, or select/filter...

...if i.even? }.compact => [4, 8, 12] or >> [1, 2, 3, 4, 5, 6].select(&:even?).map { |i| i * 2 } => [4, 8, 12] you can just do...

bundler.io

Bundler so far ignored the version specified under BUNDLED_WITH in the Gemfile.lock. This had two annoying consequences: If the bundler version on your system was lower than in the...

...and had to manually install the correct version. If the bundler version on your system was higher than in the Gemfile.lock, bundler silently updated the version in the Gemfile.lock to...

If your app does not need to support IE11, you can use most ES6 features without a build step. Just deliver your plain JavaScript without transpilation through Babel or TypeScript...

...and modern browsers will run them natively. Features supported by all modern browsers include: fat arrow functions (() => { expr }) let / const class async / await Promises Generators Symbols Rest arguments (...args)

...and how to normalize them. In the example below, the Movie#title attribute is stripped from leading and trailing whitespace automatically: class Movie < ApplicationRecord normalizes :title, with: -> { _1.strip } end

...a class. Which could look like this: class Movie < ApplicationRecord normalizes :title, with: Normalizers::StripNormalizer end The with keyword accepts any callable object that takes the attribute’s value as...

If you are using our opscomplete.com hosting we can set all environment variables mentioned below for your deployment on request. If you're lucky DO_NOT_TRACK=1 opts...

...are collecting data only after you opt into that. ng analytics --global disable Storybook https://storybook.js.org/docs/configure/telemetry npm run storybook -- --disable-telemetry npm run storybook -- --disable-crash-reports export STORYBOOK...

When you have string contents (e.g. a generated binary stream, or data from a remote source) that you want to store as a file using Carrierwave, here is a simple...

While you could write your string to a file and pass that file to Carrierwave, why even bother? You already have your string (or stream). However, a plain StringIO...

...to run JS tests. Given a Vue project that uses Jest (via vue-cli-service) with the following package.json: { "scripts": { "test": "vue-cli-service test:unit --testMatch='**/tests/**/*.test.js' --watch...

...allows us to run Jest tests with yarn test. The only downside of this setup is that debugger statements are ignored with the CLI approach - there are no Browser Devtools...

regular-expressions.info

...ae]y => grey or gray => but NOT graay or graey [0-9] matches a SINGLE digit in the range from 0 to 9 [0-9a-fA-F] hexadecimal digit...

...with caution. Mostly you'll want to use it for small expressions, e.g. for nested sub-regexes. For more details have a look at the card on quantifier modes.

tenderlovemaking.com

...are usually believed to have worse performance than those defined via def. Hence, developers sometimes prefer using class_eval to define methods using def, like this: class_eval "def #{attribute...

...for_realsies?; do_things; end" You can benchmark methods defined like this and will see that those defined via def actually do perform better. Basically, it ranks like this:

Tested on Ubunut 22.04 1. Opener script Create a file ~/.local/bin/coverage_zip_opener with: #!/bin/bash tmp_folder="/tmp/coverage-report-opener" if [ -z "$1" ] then echo "Usage: coverage_zip_opener [filename]" exit -1 fi

index_filename=$(find /tmp/coverage-report-opener -name "index.html" | awk '{ print length, $0 }' | sort -n -s | cut -d" " -f2- | head -1) if [ -z "$index_filename" ] then echo "No index file...

makandra dev

We structure our CSS using the BEM pattern. Our naming convention for blocks, elements and modifiers has evolved over the years. This card shows our current style and various alternative...

...styles that you might encounter in older projects. The difference between the various styles are mostly a matter of taste and optics. I do recommend to not mix styles and...