Sha256: 8dfbb8182bd6ec79551350d6adb08278a09aac5b0e98d3ffdc5ebd488d9155d0

Contents?: true

Size: 893 Bytes

Versions: 5

Compression:

Stored size: 893 Bytes

Contents

describe JSON do
  describe ".parse" do
    it "parses correct json strings" do
      JSON.parse('{"a":1,"b":true,"c":["data"]}').should == {
        "a" => 1, "b" => true, "c" => ["data"]
      }
    end

    it "raises an exception on malformed data" do
      -> {
        JSON.parse("malformed")
      }.should.raise(JSON::Malformed)
    end
  end

  describe ".generate" do
    it "generates JSON string out of objects" do
      JSON.generate({a:1, b:true, c:[:data]}).should ==
        '{"a":1,"b":true,"c":["data"]}'
    end

    it "generates pretty print when asked" do
      JSON.generate({a:1, b:true, c:[:data]}, :pretty).should ==
        "{\n  \"a\" : 1,\n  \"b\" : true,\n  \"c\" : [\n    \"data\"\n  ]\n}"
    end

    it "allows to export things directly of objects" do
      {a:1, b:true, c:[:data]}.to_json.should ==
        '{"a":1,"b":true,"c":["data"]}'
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
under-os-core-1.4.0 spec/core/json_spec.rb
under-os-1.3.0 spec/lib/core/json_spec.rb
under-os-1.2.1 spec/lib/core/json_spec.rb
under-os-1.2.0 spec/lib/core/json_spec.rb
under-os-1.1.0 spec/lib/core/json_spec.rb