Prefer using Dir.mktmpdir when dealing with temporary directories in Ruby
Unique scratch directories prevent flaky tests and stale files in parallel Ruby test runs. Dir.mktmpdir creates them safely and can use a custom base path.
Using regular expressions in JavaScript
Regular expressions in JavaScript use RegExp objects or regex literals, and global matches keep state between test() calls.
Use DatabaseCleaner with multiple test databases
Rails apps with multiple databases need separate test cleanup, or records bleed between specs and migrations. DatabaseCleaner can target each connection via a model-backed database key.
Cucumber: Skipping steps in a scenario outline, based on the current example
Scenario outlines can conditionally run steps per example row, avoiding duplicated long tests when only some inputs need extra actions.
RSpec: how to prevent the Rails debug page if you want to actually test for 404s
Rails development and test environments often replace real 404s with the debug page, which can hide authorization failures in request specs.
RubyMine: Adjust Code Templates
RubyMine test file generation can produce excessive boilerplate, and file templates let you tailor the output to project needs.
Version 5 of the Ruby Redis gem removes Redis.current
Redis.current is removed in redis-rb 5.0; code using shared clients needs a replacement pattern for per-use, test, or threaded access.
Specify Gemfile for bundle
BUNDLE_GEMFILE selects a nondefault Gemfile for Bundler, making it possible to work with multiple Gemfiles in one project and test against different Rails versions.
Creating a Rails application in a single file
Running Rails in one file is useful for quick experiments, debugging bugs, or embedding an app in tests, but version and dependency drift can cause surprises.
VCR: Alternative way of mocking remote APIs
VCR records real HTTP interactions and replays them from YAML, making network-dependent tests run offline without manual stubs.
Adding Jasmine JavaScript specs to a Webpack(er) project
Browser-based unit tests in a Rails app can run with Jasmine and Webpacker by separating test runner and spec packs; a /jasmine page makes the setup easy to open.
Mock the browser time or time zone in Selenium features
Selenium browser tests see real system time unless the client clock is patched; timemachine.js and Timecop keep browser time aligned, while TZ can align the process time zone.
Cucumber steps to travel through time with Timecop
Cucumber step definitions for Timecop provide date and time travel in tests, including relative shifts into the past or future; Selenium browser time needs timemachine.js.
Rails: How to test the parsed response body
Rails response tests can parse bodies by MIME type with parsed_body, replacing manual JSON.parse(response.body) in many cases and enabling cleaner assertions.
Aruba: Stubbing binaries
Command-line tests with Aruba can accidentally run real external executables; Aruba Doubles provides stubs for those binaries when PATH is adjusted with Aruba's official API.
Heads Up: Selenium 4 uses a binary to determine the chromedriver
Selenium WebDriver 4 can pick an incompatible browser binary in CI, breaking feature tests when Chromium and Chrome versions differ. Setting binary avoids selenium-manager selecting or downloading the wrong browser.
Jasmine: Testing complex types for equality
toBe only checks reference identity; toEqual handles arrays, objects, dates, regular expressions, NaN, exceptions, and custom equality testers.
Setup Sidekiq and Redis
Sidekiq needs a Redis connection configured separately for client and server environments. A REDIS_URL constant and startup load path keep staging, production, and test settings consistent.
How to access Chrome Devtools when running JavaScript tests via CLI
Running JavaScript tests from the CLI bypasses browser DevTools, so debugger statements are ignored. node --inspect-brk lets Chrome DevTools attach to Jest and pause execution.
Test if all your favicons exist
Favicon variants can break silently when some image sizes or platform-specific tags point to missing files. An integration check can verify that every icon URL returns 200.
Mailcatcher: An alternative to inaction_mailer
Local email capture for Rails development avoids lost test messages and lets sent mail be viewed in a browser via MailCatcher.
RSpec: Efficiently rerunning failed examples during development
Persisting RSpec example status lets failed tests be rerun quickly during development with --only-failures or --next-failure.
How to make Webpacker compile once for parallel tests, and only if necessary
Compile Webpacker assets once in parallel test runs and skip recompilation when files are unchanged, avoiding duplicate work and Capybara timeouts.
How to accept or deny JavaScript confirmation dialogs in Capybara/Selenium
JavaScript confirmation dialogs in Capybara/Selenium can block tests or auto-dismiss unexpectedly. Direct alert handling restores accept, dismiss, and text access.