Module: Axn::Testing::SpecHelpers

Defined in:
lib/axn/testing/spec_helpers.rb

Instance Method Summary collapse

Instance Method Details

#build_axn(&block) ⇒ Object



8
9
10
11
12
# File 'lib/axn/testing/spec_helpers.rb', line 8

def build_axn(&block)
  action = Class.new.send(:include, Axn)
  action.class_eval(&block) if block
  action
end

#with_ambient_context(**attrs) ⇒ Object

Block-scoped injection for on: :ambient_context inputs. Swaps the global ambient_context_provider for the block, so the action under test AND any nested actions it calls resolve their ambient subfields from attrs — without touching Current / any CurrentAttributes. Restores the previous provider on exit (safe under nesting and when the block raises). An explicit ambient_context: kwarg on a specific call still overrides attrs (existing precedence in _resolve_ambient_context).



20
21
22
23
24
25
26
# File 'lib/axn/testing/spec_helpers.rb', line 20

def with_ambient_context(**attrs)
  previous = Axn.config.ambient_context_provider
  Axn.config.ambient_context_provider = -> { attrs }
  yield
ensure
  Axn.config.ambient_context_provider = previous
end