Sha256: e815d306409fa5b63076a9fef6023e4ccf2d9b50a84c442dea387f649aa17093
Contents?: true
Size: 1.03 KB
Versions: 3
Compression:
Stored size: 1.03 KB
Contents
require "strong_json" describe "StrongJSON.new" do it "tests the structure of a JSON object" do s = StrongJSON.new do let :item, object(name: string, count: numeric, price: numeric, comment: ignored) let :checkout, object(items: array(item), change: optional(number), type: enum(literal(1), symbol)) end expect(s.checkout.coerce(items: [ { name: "test", count: 1, price: "2.33", comment: "dummy" }], type: 1)).to eq(items: [ { name: "test", count: 1, price: "2.33" }], type: 1) end it "tests enums" do s = StrongJSON.new do let :enum, object(e1: enum(boolean, number), e2: enum?(literal(1), literal(2))) end expect(s.enum.coerce(e1: false)).to eq(e1: false) expect(s.enum.coerce(e1: 0)).to eq(e1: 0) expect(s.enum.coerce(e1: 0, e2: 1)).to eq(e1: 0, e2: 1) expect(s.enum.coerce(e1: 0, e2: 2)).to eq(e1: 0, e2: 2) expect{ s.enum.coerce(e1: "", e2: 3) }.to raise_error(StrongJSON::Type::Error) expect{ s.enum.coerce(e1: false, e2: "") }.to raise_error(StrongJSON::Type::Error) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
strong_json-0.9.0 | spec/json_spec.rb |
strong_json-0.8.0 | spec/json_spec.rb |
strong_json-0.7.1 | spec/json_spec.rb |