← Graph

Three Lightning Talks: Stubbing Rails.env in Tests

talk 8 connections

wroclove.rb 2026 lightning talk with a three-lightning-talks framing. The first planned talk was abandoned — the speaker's intended material was a story about accidentally running `rm -rf` on their home directory while uninstalling Docker Desktop (missing quotes + a stray space) with no Time Machine backup. Pivoted to a second topic: testing code that depends on Rails.env, specifically branches gated on Rails.env.development? that normally can't run inside the test environment. Shows two helpers. In minitest, using stub_any_instance, a stub_environment(:development) block stubs Rails.env.development? to true and both .test? and .production? to false (and vice versa for :production), letting tests assert predicates and actually exercise the branch. In RSpec, a similar helper using RSpec mocks with temporary message-scoping and around-example hooks achieves the same result, though it measurably slows down the affected tests — likely because test-environment optimizations are bypassed when the Rails.env predicates are stubbed.

type
lightning-talk
talk Three Lightning Talks: Stubbing Rails.env in Tests
about
Used in the minitest variant of the Rails.env-stubbing helper
talk Three Lightning Talks: Stubbing Rails.env in Tests
about
Used with temporary message-scoping for the RSpec variant
talk Three Lightning Talks: Stubbing Rails.env in Tests
about
minitest tool
First helper implementation shown
talk Three Lightning Talks: Stubbing Rails.env in Tests
about
RSpec tool
Second helper implementation shown
talk Three Lightning Talks: Stubbing Rails.env in Tests
about
Docker tool
Opening anecdote about an rm -rf during Docker Desktop uninstall
from_talk
Three Lightning Talks: Stubbing Rails.env in Tests talk
Main technical takeaway
from_talk
Three Lightning Talks: Stubbing Rails.env in Tests talk
Abandoned-first-talk cautionary story
talk Three Lightning Talks: Stubbing Rails.env in Tests
presented_at
Lightning talk at wroclove.rb 2026

Provenance

Created in
wroclove.rb 2026 Lightning Talks 2026-04-22 08:41