Javascript: How to match text by Unicode properties
Unicode character class escapes let JavaScript regular expressions match letters, numbers, and symbols beyond ASCII, making password checks work with umlauts and non-Latin digits.
JavaScript: Testing whether the browser is online or offline
Browser connectivity can be misleading: navigator.onLine often stays true without usable internet. A real fetch with timeout can confirm whether requests actually work.
Reload the page in your Cucumber features
Reloading a GET page in Cucumber can preserve query parameters during feature tests. Capybara and Webrat variants use the current request data to revisit the same URL.
Katapult 0.3.0 released
Katapult 0.3.0 adds Rails 5.1.4 and Ruby 2.5.0 support, a new Bootstrap-based design, Webpacker, and workflow and test improvements.
CI Template for GitHub Actions
GitHub Actions CI template for Rails apps with parallel RSpec, RuboCop, ESLint, license checks, security scanning, and merged coverage reports.
Compare two jQuery objects for equality
jQuery creates a new wrapper on each $(...) call, so == fails for matching selections. Use .is() to test whether two jQuery objects wrap the same DOM elements.
Carrierwave: Built-in RSpec matchers
CarrierWave RSpec matchers simplify testing uploaded image versions and dimensions with have_dimensions, be_no_wider_than, and be_no_larger_than.
Rails 3/4: How to add routes for specs only
Test-only routes can help verify redirects and other edge cases without changing the normal route set. with_routing replaces existing routes, so evaluating a route block keeps both sets available.
Test that a select option is selected with Cucumber
Checks whether a form dropdown has a preselected value in HTML using Cucumber step definitions for Capybara or Webrat.
How to test your website for different versions of Internet Explorer or Edge
Browser compatibility testing for older Internet Explorer and Edge versions can be done with Microsoft virtual machines or paid cloud access from BrowserStack.
VCR: Inspecting a request
VCR can stub remote API calls in tests while still letting you inspect what was sent, including request payloads, through WebMock.
nruth/show_me_the_cookies - GitHub
Helpers for inspecting and manipulating Capybara browser cookies in integration tests, with support for rack-test and Selenium WebDriver.
ActiveRecord: How to use ActiveRecord standalone within a Ruby script
Run ActiveRecord without Rails in a tiny Ruby script to reproduce bugs or test associations with an in-memory SQLite database.
Geordi: Choose your firefox version for cuc
Geordi 0.16+ lets selenium tests use a project-specific Firefox version via .firefox-version, with geordi cucumber prompting installation of the chosen release.
Capybara: A step for finding images with filename and extension
Capybara step for checking an image by matching part of its src against a filename and extension during browser tests.
Common mistakes when storing file uploads with Rails
File uploads in Rails are easy to misconfigure, causing lost files, public exposure of confidential data, and environment collisions. Existing uploads also need migration when storage paths change.
Concurrent Tests
Install gem and plugin
sudo gem install parallel
script/plugin install git://github.com/grosser/parallel_tests.git
Adapt config/database.yml
test:
database: xxx_test<%= ENV['TEST_ENV_NUMBER'] %>
Create test databases
script/dbconsole -p
CREATE DATABASE `xxx_test2`;
...
Generate RSpec files
script/generate rspec
(you'll probably only let it overwrite files in script/)
Prepare test databases...
Force Google Chrome to run in English on Linux
Google Chrome can inherit a non-English browser language from the Linux locale, which affects sites and Selenium tests. Keeping only en locale files forces Chrome to use English.
Cucumber: Wait until CKEditor is loaded
Timing issues can cause undefined errors when interacting with CKEditor in Cucumber tests. Waiting for the editor to reach ready avoids flaky WYSIWYG input steps.
Capybara steps to match stuff within any selector
Capybara within scopes only the first matching element, so tests that need all matches use “inside any” Cucumber steps instead.
Automated "git bisect" will make your day
git bisect run automates regression hunting by repeatedly testing revisions and narrowing down the first bad commit from a command’s exit status.
Test that a form field is visible with Cucumber/Capybara
Capybara visibility checks can assert whether a form field is shown or hidden by label, using CSS- or JavaScript-based detection.
state_machine: Test whether an object can take a transition
Check whether an object can perform a state transition before calling it. can_transition_ab? only verifies that a matching transition exists; validations may still block it.
Webrat doesn't follow redirect because it considers the url external
Absolute URLs in Rails tests can be treated as external because the host is unknown, breaking redirect handling in Webrat. Use path-only matching or reset Webrat to the local site.