Random list of ActiveSupport goodies

Handy ActiveSupport helpers add callbacks, message signing and encryption, ordered options, array wrapping, deep hash merging, whitespace squishing, and zone-aware current time.

Know what makes your browser pant

Changing CSS properties can trigger different amounts of browser work, affecting performance when styles are updated.

How much should I refactor?

Balancing refactoring with complexity is difficult when new patterns promise cleaner, more testable Rails code. Choosing when to apply them keeps code maintainable without overengineering.

The Startup Toolkit

Practical crash courses for founding a startup, raising funding, and testing ideas before building too much.

Browsera - Automated Cross Browser Web Application Testing Service

Automated cross-browser testing finds layout problems and scripting errors on websites before users do.

RSpec 3 argument constraints use weak equality

RSpec 3 argument matching can accept broader values than strict equality, especially for classes, regexps, and ranges. Use eq or a block for exact expectations.

Bash script to list commits by Pivotal Tracker ID

Quickly list Git commits tied to one Pivotal Tracker story ID, making related changes easier to spot with a small Bash helper.

Three quick Rails console tips

Rails console access to routing helpers, request simulation, and view helpers speeds up debugging and quick checks without leaving rails console.

Cucumber pitfall: "Around" does not apply to your "Background" steps

Around hooks run only after Background steps, so setup or teardown placed there cannot affect background actions. Use Before and After hooks instead.

Using RSpec stubs and mocks in Cucumber

Cucumber can use RSpec doubles instead of Mocha; loading the integration in env.rb keeps stubs and mocks available after other After hooks.

Bug in Chrome 56+ prevents filling in fields with slashes using selenium-webdriver/Capybara

Chrome 56+ can drop slashes when fill_in runs through Selenium and Capybara, breaking form input for paths and HTML strings; a JavaScript workaround updates the field directly.

How to find out if you are in Cucumber or in RSpec

Feature and spec code may need different behavior when Rails env is unavailable. Capybara.current_driver can distinguish Cucumber scenarios from RSpec examples.

Ruby: How to measure code execution time in an IRB or Rails console

IRB and Rails console sessions can time code execution directly with measure; older versions can use Benchmark.measure for manual timing.

RSpec < 2.11: ActiveRecord scopes must be loaded before using the "=~" matcher

ActiveRecord scopes must be converted to arrays before using RSpec =~, or array comparison can fail. match_array and contain_exactly are preferred in RSpec 2.11 and later.

Spreewald: Old-school cucumber steps, freshly pickled

Spreewald keeps Cucumber-style web steps available while adding reusable steps for emails, tables and time travel in a Ruby gem.

Testing with IE6, IE7 and IE8 on VirtualBox | Shape Shed

Free browser testing setup on OSX or Ubuntu using VirtualBox makes legacy Internet Explorer versions available without Parallels.

Ruby: Enumerable#partition

Split an enumerable into matching and non-matching groups with Enumerable#partition, returning two arrays and working naturally with destructuring assignment.

Hack of the day: One-liner to run all Cucumber features matching a given string

Run only matching Cucumber feature files by searching .feature files for a string and passing the matches to geordi cucumber; similar xargs pipelines work without Geordi.

How to fix: WrongScopeError when using rspec_rails with Rails 6.1

rspec_rails with Rails 6.1 can raise WrongScopeError; upgrading the gem to 4.0.1 or later resolves the failure.

Output the descriptions of RSpec examples while they are running

RSpec’s nested documentation format prints example descriptions while specs run, making warnings and failures visible immediately and giving a quick view of core behavior.

Bash script to run specs and features

Run rspec and Cucumber from any project directory with optional spinner support; features are skipped when specs fail.

Migrating to RSpec 2 from RSpec 1

Rails 3 requires rspec and rspec-rails 2, with renamed namespaces, changed requires, and macro extensions that may break during migration.

Run your own code before specific RSpec examples

Run custom setup code before selected RSpec examples using metadata tags instead of Cucumber scenarios.

How to work around selenium chrome missing clicks to elements which are just barely visible

Chrome/Selenium can miss clicks on barely visible elements when the click target is outside the viewport. A scrollIntoViewIfNeeded patch can work around the issue.