thoughtbot/shoulda-matchers · error · ArgumentError
When specifying a value as a block, a context must be specif
Error message
When specifying a value as a block, a context must be specified beforehand, e.g., #{store.name}.in_context(context).to { ... } What it means
Error "When specifying a value as a block, a context must be specified beforehand, e.g., #{store.name}.in_context(context).to { ... }" thrown in thoughtbot/shoulda-matchers.
Source
Thrown at lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb:26
end
def in_context(context)
@context = context
self
end
def [](key)
@key = key
self
end
def to(expected_value = nil, &block)
if block
unless context_set?
message = 'When specifying a value as a block, a context must be'\
' specified beforehand,'\
" e.g., #{store.name}.in_context(context).to { ... }"
raise ArgumentError, message
end
@expected_value = context.instance_eval(&block)
else
@expected_value = expected_value
end
self
end
def description
"should #{expectation_description}"
end
def matches?(controller)
@controller = store.controller = controller
!store.empty? && key_matches? && expected_value_matches?
endView on GitHub (pinned to 79cdfbc326)
When it happens
Trigger: Thrown at lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb:26 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of thoughtbot/shoulda-matchers@79cdfbc326 (2026-08-23).
Data as JSON: /api/errors/8d67fe5141150617.
Report an issue: GitHub.