Sha256: 1c9259665523ade417dafbc571aaa87afa42fd304567e46c1b7ba1d53ff1616a
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 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(string, number), e2: enum?(literal(1), literal(2))) end expect(s.enum.coerce(e1: "")).to eq(e1: "") 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: false) }.to raise_error(StrongJSON::Type::Error) expect{ s.enum.coerce(e1: "", e2: 3) }.to raise_error(StrongJSON::Type::Error) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
strong_json-0.7.0 | spec/json_spec.rb |