Sha256: f262bee046304a7b39b97103e99c649fb90fe7340bdcd9b9ec63a8acca7117d0
Contents?: true
Size: 1.28 KB
Versions: 6
Compression:
Stored size: 1.28 KB
Contents
require 'json' describe "Hash#to_json" do it "returns a string of all key and value pairs" do {}.to_json.should == "{}" {"a" => 1, "b" => 2}.to_json.should == '{"a":1, "b":2}' hash = {"a" => 1, "b" => false, "c" => nil, "d" => true} JSON.parse(hash.to_json).should == hash end end describe "Array#to_json" do it "returns a string of all array elements converted to json" do [].to_json.should == "[]" [1, 2, 3].to_json.should == "[1, 2, 3]" [true, nil, false, "3", 42].to_json.should == '[true, null, false, "3", 42]' end end describe "Boolean#to_json" do it "returns 'true' when true" do true.to_json.should == "true" end it "returns 'false' when false" do false.to_json.should == "false" end end describe "Kernel#to_json" do it "returns an escaped #to_s of the receiver" do self.to_json.should be_kind_of(String) end end describe "NilClass#to_json" do it "returns 'null'" do nil.to_json.should == "null" end end describe "String#to_json" do it "returns an escaped string" do "foo".to_json.should == "\"foo\"" "bar\nbaz".to_json.should == "\"bar\\nbaz\"" end end describe "Numeric#to_json" do it "returns a string representing the number" do 42.to_json.should == "42" 3.142.to_json.should == "3.142" end end
Version data entries
6 entries across 6 versions & 1 rubygems