Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Group all json specs together in spec/opal/json
- Loading branch information
1 parent
dae89e5
commit 6969618
Showing
11 changed files
with
48 additions
and
98 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.