Debouncing a method call delays its execution until after a specified time has passed. If it's called again before that time has passed, its execution is delayed again.
...would be run more often than it needs to. One example for that are scroll event handlers in JavaScript: You want to react to a user scrolling, but it's...
...for DOM elements, there are some footguns you should know about. Some lists are synchronized with the DOM Some DOM APIs return live lists that automagically update their contents as...
...reflects the change automatically: document.querySelector('#two').remove() console.log(liveList) // [#one] console.log(nonLiveList) // [#one, #two] Snapshotting a live list Lists that silently change their elements can be very surprising to work...
When ending a Selenium test Capybara resets the browser state by closing the tab, clearing cookies, localStorage, etc. It may be a good idea to wait for all in-flight...
...AJAX requests to finish before ending a scenario: You may have client-side JavaScript that freaks out when the tab closure kills their pending requests. If that JavaScript opens an...
min-width is known as a CSS property that can be set to define a least width for an element. Surprisingly, it can also be used to set something that...
...it is more like "auto". This can make block elements take up much more space than desired, even stretching their container beyond the screen edge on small screens.
...notice that the records you create are not deleted and will bleed into your specs the next time you run them. You probably have DatabaseCleaner configured to take care of...
...not bloating your test database with old records: RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:deletion) end config.before(:each) do DatabaseCleaner.strategy = :transaction end config.before(:each, transaction: false) do DatabaseCleaner.strategy...
...with two matchers that test for equality. The first is toBe: expect(first).toBe(second) toBe passes when first === second. Unfortunately this is useless for non-primitive values because JavaScript...
...is a horrible language. However, Jasmine comes with another matcher toEqual: expect(first).toEqual(second) This matcher behaves as a human would expect for types like the following: Arrays
Because your examples should not change global state, you should not need to care about the order in which RSpec processes your .rb files. However, in some cases you might...
...rb files in alphabetical order of their file paths by default (or when you specify --order defined). You run tests in random order by using --order random on the command...
When you're using feature branches, they will stack up if you don't delete them after the merge to master. Here's how to tidy them up. Delete feature...
...Find already-merged branches by running # On branch master git branch --merged You may safely delete each of the listed branches, because they point to commits that are contained in...
...been released just a few days ago, allowing us to use Webpack 4. I successfully upgraded an existing real-world Webpack 3 application. Below are notes on everything that I...
Note that we prefer not using the Rails asset pipeline at all and serving all assets through Webpack for the sake of consistency. Preparations Remove version locks in Gemfile...
This card is a short summary on different ways of assigning multiple attributes to an instance of a class. Using positional parameters Using parameters is the default when assigning attributes...
...It works good for a small number of attributes, but becomes more difficult to read when using multiple attributes. Example: class User def initialize(salutation, first_name, last_name, street...
...pretty_print method As an example, consider the following class. class MyClass # ... def inspect "#<#{self.class} attr1: #{attr1.inspect}, attr2: #{attr2.inspect}>" end end Instances of that class will inspect like #<MyClass attr1...
...Alice", attr2: "Bob">, but IRB will apply a single color (green) for everything. That is because MyClass implements only inspect. If it were to implement pretty_print, IRB would use...
When a user shares your content, a snippet with title, image, link and description appears in her timeline. By default social networks will use the window title, the first image...
...the current URL and some random text snippet for this purpose. This is often not what you want. Luckily Facebook, Twitter, etc. lets you control how your content appears in...
...Mocking the time zone You can't really change the local time zone of the Selenium-controlled browser. What you can do is change the time zone of the process...
...setting this from an individual test, since you don't know whether or not the Selenium-controlled browser has already launched. Note that we have only tested this with a...
I recently noticed a new kind of flaky tests on the slow free tier GitHub Action runners: Integration tests were running on smaller screen sizes than specified in the device...
...metrics. The root cause was the use of Selenium's page.driver.resize_window_to methods, which by design does not block until the resizing process has settled: We discussed this issue...
When you create a temporary file (e.g. to store a generated Excel sheet) and try to send it to the browser from a controller, it won't work by default...
...this controller action: class FoosController < ApplicationController def download file = Tempfile.new('foo') file.puts 'foo' file.close send_file file.path end end Accessing this controller action will usually raise a 404 not found...
...files. Those can be used to apply to a different repository [1] or by someone else (e.g. sent when sent to them via e-mail). Creating a patch in git...
...changes and commit them. Run git format-patch COMMIT_REFERENCE to convert all commits since the referenced commit (not including it) into patch files. For example, let's say you...
...upgrade tasks according to its actual value. Consider to create and periodically maintain a summary, which helps you and your team in the decision which refactoring task should be taken...
Estimated Efforts Visible customer value Customer value explained Developer value Developer value explained Short title for the task Score from 0-5 Score from 0-5 Explanation
Follow the installation guidelines at https://mise.jdx.dev/getting-started.html. Remove rbenv configuration Search for rbenv config in .bashrc and .profile and remove it: eval "$(rbenv init - bash)"
...rbenv config in .profile and remove it: source /home/$user/.rbenvrc Remove nvm configuration Search for nvm config in .bashrc and remove it: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM...
...posts; if you use pagination the queries will be more complicated, but the point still stands. Looks harmless enough? It is not. The problem ActiveRecord will rewrite this into a...
...query using LEFT JOINs which looks something like this: SELECT "blog_posts".*, "comments".*, "attachments".* FROM "blog_posts" LEFT OUTER JOIN "comments" ON "comments"."blog_post_id" = "blog_posts"."id"
...a global variable in Rails? Ugh, that's the worst. If you need global state, you've probably reached for Thread.current. When you're using Thread.current, you must make sure...
...yourself or your cached data will stay in Thread.current. For Sidekiq, you can use request_store-sidekiq. Cronjobs are unaffected, as a new process is created each time...
...tough challenge. To get more detailed insights consider using the rack-mini-profiler gem. Setup with Unpoly Add the following gems: group :development do gem 'memory_profiler' gem 'rack-mini...
If you have slow views (Haml/Partials can be slow), consider caching them. Remove code & sql-queries that are not needed to render the page. Calling to_a blindly on...
...block evaluates to true. first_post_with_image = posts.find do |post| post.image end However, sometimes it's not the item you're interested in, but some value depening on it...
...image).find(&:present?).url If the mapping is a costly operation or has undesirable side effects, you need to do it in a single iteration instead. Single iteration solution with...
If you want to switch to another ruby versions, you have several options, depending on what you want: Do you want to switch temporarily, per project, or globally?
Unlike RVM, rbenv does not offer a command like rvm use. By default, it respects your project's .ruby-version file. If you need to change manually...
Here are a few common patterns that will probably lead to flaky specs. If you notice them in your specs, please make sure that you have not introduced a flaky...
Using RSpec matchers One rule of thumb I try to follow in capybara tests is using capybara matchers and not plain rspec matchers. One example: visit(some_page)