Skip to content

Commit 6969618

Browse files
committed
Group all json specs together in spec/opal/json
1 parent dae89e5 commit 6969618

File tree

11 files changed

+48
-98
lines changed

11 files changed

+48
-98
lines changed

spec/opal/array/to_json_spec.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

spec/opal/boolean/to_json_spec.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

spec/opal/hash/allocate_spec.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.

spec/opal/hash/dup_spec.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.

spec/opal/hash/new_spec.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.

spec/opal/hash/to_json_spec.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

spec/opal/hash/to_s_spec.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

spec/opal/json/ext_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
require 'json'
2+
3+
describe "Hash#to_json" do
4+
it "returns a string of all key and value pairs" do
5+
{}.to_json.should == "{}"
6+
{"a" => 1, "b" => 2}.to_json.should == '{"a": 1, "b": 2}'
7+
8+
hash = {"a" => 1, "b" => false, "c" => nil, "d" => true}
9+
JSON.parse(hash.to_json).should == hash
10+
end
11+
end
12+
13+
describe "Array#to_json" do
14+
it "returns a string of all array elements converted to json" do
15+
[].to_json.should == "[]"
16+
[1, 2, 3].to_json.should == "[1, 2, 3]"
17+
[true, nil, false, "3", 42].to_json.should == '[true, null, false, "3", 42]'
18+
end
19+
end
20+
21+
describe "Boolean#to_json" do
22+
it "returns 'true' when true" do
23+
true.to_json.should == "true"
24+
end
25+
26+
it "returns 'false' when false" do
27+
false.to_json.should == "false"
28+
end
29+
end
30+
31+
describe "Kernel#to_json" do
32+
it "returns an escaped #to_s of the receiver" do
33+
self.to_json.should be_kind_of(String)
34+
end
35+
end
36+
37+
describe "NilClass#to_json" do
38+
it "returns 'null'" do
39+
nil.to_json.should == "null"
40+
end
41+
end
42+
43+
describe "String#to_json" do
44+
it "returns an escaped string" do
45+
"foo".to_json.should == "\"foo\""
46+
"bar\nbaz".to_json.should == "\"bar\\nbaz\""
47+
end
48+
end

spec/opal/kernel/to_json_spec.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

spec/opal/nil/to_json_spec.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)