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.
How to solve Selenium focus issues
Browser focus loss makes Selenium tests flicker red and green, especially with Firefox and parallel runs. Explicit focus and blur handling and focus-independent tests improve stability.
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.
Single step and slow motion for cucumber scenarios using @javascript selenium
Pause Cucumber browser-driven tests between steps for debugging or demos, with single-step input and slower playback for @javascript Selenium runs.
Protip: Always leave a failing test
Leaving a failing test at the end of unfinished work makes it easier to resume later and quickly see what still needs attention.
Setup your terminal to not scroll when there is new output
Stop the terminal from jumping back to the bottom when new output appears, so you can inspect logs or test failures without losing your place.
CSS tests and experiments
Tests and experiments around CSS features, possibilities, and browser bugs across more than 200 cases.
Test that a CSS selector is present with Cucumber
Cucumber step for checking whether a CSS selector is present or absent on a page with Capybara or Webrat.
Stubbing out external services with an embedded Sinatra application
Test suites that depend on remote APIs can become brittle and slow; an embedded Sinatra app provides a lightweight stub server for isolated integration tests.
Using QEMU to quickly test an ISO or bootable USB drive
Bootable media can be tested quickly in QEMU instead of setting up VirtualBox, using an ISO or a USB drive directly.
Hunt down that elusive debug message in Ruby
Trace stray puts and p output in Ruby by inserting a temporary hook that prints a backtrace for a chosen message, then remove it after cleanup.
Use the back button in Cucumber
Navigate to the previous page in Cucumber feature tests when browser history is unavailable, using the HTTP referrer in Capybara or Webrat.
How to test if an element has scrollbars with JavaScript (Cucumber step inside)
Detecting overflow in an element matters when layout must avoid hidden content and unwanted scroll bars; comparing scrollHeight and offsetHeight reveals whether content exceeds the visible area.
How to test whether your device has a true Retina display
A simple visual test gauges how close a screen comes to true Retina quality by comparing fine line sharpness in two images.
Airbrake notification in Rake tasks
Rake tasks can report exceptions to Airbrake without notifying in development or test environments, using the usual notification rules for tasks that depend on :environment.
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.
Updated: Capybara: Check that a page element is hidden via CSS
Hidden-element checks in Capybara can fail in Selenium when visibility is inferred too loosely. A JavaScript-based step works across Selenium, jQuery, Prototype, and Rack::Test.
Stub methods on any instance of a class in Rspec 1 and Rspec 2
Stub a method on every instance of a class to control behavior in tests, using stub_any_instance, any_instance.stub, or allow_any_instance_of.
FactoryGirl: How to easily create users with first and last name
Create a user factory that accepts one full-name value and splits it into first and last name automatically, reducing repetitive test setup.
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.
Create and send any HTTP request using the Postman request builder
Postman provides a graphical way to build and send HTTP requests, with collections, environments, history, and a cookie manager for API testing.
Updated: Test a gem in multiple versions of Rails
Testing a gem across Rails versions is easier with shared app code and specs via symlinks, keeping one test setup aligned with current best practice.
How to inspect controller filter chains in specs
Inspecting callback chains in controller specs helps verify before- and after-action behavior, especially when tests need to confirm filter order or presence.