サンプル
Read and write JSON in Ruby on an image with no C compiler, where oj cannot be installed, without the built-in json defaults changing the data
sha256:bec86395ce786b02c01ea89597d38d802ad97a4c997dc95aaa3f09e24aeeffe9
PUBLISHED
L3_CONTRACT_PASS
MIT-0
ケース
- ゴール
- Read and write JSON in Ruby on an image with no C compiler, where oj cannot be installed, without the built-in json defaults changing the data HOW
- パッケージ
- json 2.9.1 minitest 5.27.0
- 環境
- ruby 3
- 作成日
- 2026-08-14T13:05:58Z
コントラクト
- assert JSON.parse hands back String keys at every depth while symbolize_names: true changes keys only and leaves String values alone
- assert generate accepts symbol keys, so a Hash keyed by symbols round trips into string keys and stops equalling itself
- assert a non-String key is stringified by generate, symbolize_names then yields :"1" rather than 1, and two keys that stringify alike are both written and then collapsed by the parser, last one winning
- assert JSON.generate and to_json emit the same bytes for an object whose to_json accepts the state
- assert what to_json receives is a JSON::State that only a direct call omits, and that an object which accepts the state and drops it comes out compact inside a pretty document that still parses equal
- assert an arity-zero to_json works only on a direct call and raises ArgumentError through JSON.generate or from inside any container, including via Hash#to_json
- assert the generator splices in whatever to_json returned without checking it, so an invalid fragment builds a document JSON.parse rejects
- assert an object with no to_json is emitted as its to_s in quotes, symbols included, and only strict: true turns that back into a JSON::GeneratorError
- assert JSON.generate refuses NaN and Infinity, to_json refuses them identically, allow_nan writes them, and JSON.parse rejects that output unless it is given allow_nan too
- assert JSON::GeneratorError and JSON::ParserError are both JSON::JSONError, so one rescue covers both directions
- assert JSON.dump defaults to allow_nan and writes a document JSON.parse cannot read while JSON.load can, and that JSON.load defaults to allow_blank so an empty string is nil where JSON.parse raises
- assert a 2**53+1 integer and a thirty digit integer survive a round trip exactly, while the same digits with a decimal point lose the low bit and regenerate in exponent form
- assert bigdecimal is not visible under bundler at all, and that decimal_class: String keeps every digit of a fraction while leaving integers as Integer
- assert JSON.pretty_generate parses equal to the compact output, preserves key order in both, keeps empty containers on one line and writes no trailing newline
- assert json is absent from the bundle yet answers as a default gem at the version the purl names, and that the parser and generator actually loaded are .so files under the interpreter's own archdir
- assert no compiler and no make are on PATH and that requiring oj is a LoadError
ファイル
- Gemfile
- Gemfile.lock
- csx.json
- src/json_ops.rb
- test/contract.rb
オリジンシーダー
検証レシート
- ruby 3 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · gem@1 · 2026-08-14 · ed25519:a2ec939a4c60e243
- · CONTAINER_RUN · compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL · gem@1 · 2026-08-14 · ed25519:7da3f610facce8bf