Exemple
Handle Sinatra route return value type boundaries where returning a bare Hash yields Enumerable key-value array pairs under text/html rather than serializing JSON, and returning a status-headers 2-tuple treats the Hash as the response body
sha256:4e6f5f2571bb3c814be0e5880976fec924aca91858ea0f43ac917eff250e2306
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Cas
- Objectif
- Handle Sinatra route return value type boundaries where returning a bare Hash yields Enumerable key-value array pairs under text/html rather than serializing JSON, and returning a status-headers 2-tuple treats the Hash as the response body HOW
- Paquets
- sinatra 4.2.1 rack-test 2.2.0 rack 3.2.7 mustermann 3.1.1 tilt 2.8.0
- Environnement
- ruby
- Créé
- 2026-08-17T01:21:15Z
Ce que l'on suppose souvent
Returning a Ruby Hash from a Sinatra route block either serializes to JSON or raises a type error, and returning a two-element array of a status integer and a hash sets the response status and headers.
L'auteur de l'échantillon a consigné ici ce qu'un développeur ou un modèle s'attendrait à voir. Le contrat ci-dessous est ce qui s'est réellement exécuté.
Contrat
- assert a bare Hash returned from a route is treated as an Enumerable body yielding key-value array pairs with text/html rather than serializing to JSON
- assert returning a status integer and a headers Hash in a two-element array pops the Hash as the body and leaves response headers unset
- assert returning a three-element array unpacks the first element as status, the last as body, and the middle as response headers
- assert returning a bare Integer status code sets the HTTP response status and resets the response body to empty
- assert returning an Array of Strings is treated as an Enumerable streaming body with 200 OK because the first element is not an Integer
- assert returning a Symbol is ignored by route dispatch and leaves the response body empty
- assert returning a custom object with only to_s is ignored while an Enumerable defining each streams yielded chunks
- assert calling the body helper and returning nil retains the explicitly set body while returning an Integer wipes it
- assert halt with a status integer and a Hash pops the Hash as the response body with no headers set
Fichiers
- Gemfile
- Gemfile.lock
- NOTES.md
- csx.json
- src/app.rb
- test/contract.rb
Télécharger l'artefact vérifié (tar.gz) — les octets exacts sur lesquels le contrat s'est exécuté
Seeder d'origine
Reçus de vérification
- ruby 3 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · rubygems@1 · 2026-08-17 · ed25519:d91480838ac982c9