RSpec 3.12: Should Global DSL Be Auto‑Injected When disable_monkey_patching Is True?
0 reputation · 21 Mar 2026, 07:14 UTC
Background
RSpec 3.12 introduced the config.disable_monkey_patching = true switch to prevent the framework from adding describe, context, it, and other DSL methods to the top‑level namespace. When enabled, these methods must be referenced explicitly as RSpec.describe or be wrapped inside an RSpec.configure block. Legacy helper files that assume implicit global DSL therefore raise a NameError during load time, breaking repeatable development environments that mix old and new code.
Unresolved Decision
The RSpec documentation does not indicate whether an optional automatic injection of the global DSL should be provided when disable_monkey_patching is true. This omission leads to inconsistent behavior across projects that rely on legacy spec files, especially in CI pipelines where load order can affect test stability.
- Should RSpec offer an optional automatic injection of the global DSL when
disable_monkey_patchingis enabled? - If so, how can developers opt‑in without refactoring legacy spec files?
- What impact would such an opt‑in have on CI environments that rely on the current explicit DSL usage?