示例
Handle Sinatra error dispatch, status code handlers, show_exceptions modes, and route return value coercion without uncaught test exceptions, overwritten halt bodies, or symbol template lookups
sha256:6e3c39259c903ef98aa1a3a0b9b3c1dad0a3af159e7e3d689ce10e03f43cf009
PUBLISHED
L3_CONTRACT_PASS
MIT-0
案例
- 目标
- Handle Sinatra error dispatch, status code handlers, show_exceptions modes, and route return value coercion without uncaught test exceptions, overwritten halt bodies, or symbol template lookups HOW
- 包
- sinatra 4.2.1 rack-test 2.2.0 rack 3.2.7 rack-protection 4.2.1 mustermann 3.1.1
- 环境
- ruby
- 创建时间
- 2026-08-17T01:20:49Z
常见的想当然
Raising a custom exception in a route is handled by its error block in development mode while unhandled exceptions return 500 in test mode, halt bodies are never replaced by status handlers, and returning a Symbol or Integer sets the body or status identically to the status helper.
这是本样本作者记下的、开发者或模型在此处通常会有的预期。下面的契约才是真正运行过的东西。
契约
- assert in development mode default show_exceptions intercepts custom exceptions with an HTML backtrace rather than running the error handler
- assert setting show_exceptions to :after_handler executes custom error handlers while leaving unhandled exceptions to the debug page
- assert in test mode with raise_errors enabled, unhandled exceptions are re-raised out of the Rack call rather than returning 500
- assert defining an error 404 or not_found handler silently overwrites the custom body passed to halt 404
- assert returning a status code with a string body in a route is superseded by the registered status error handler
- assert returning a Symbol from a route block performs a template lookup and produces an empty body rather than setting the status code or string body
- assert returning an Integer from a route sets the HTTP status code and an empty body, including when status 201 is the final expression
- assert returning a Hash serves concatenated key-value array chunks as text/html rather than JSON
- assert pass throws to the next matching route within the same request instance, preserving instance variables while resetting route params
文件
- Gemfile
- Gemfile.lock
- NOTES.md
- csx.json
- src/app.rb
- test/contract.rb
下载已验证的构件 (tar.gz) — 契约实际运行的那些字节
原始种子者
验证回执
- ruby 3 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · rubygems@1 · 2026-08-17 · ed25519:d91480838ac982c9