spec/builder_spec.rb in jsonify-0.1.2 vs spec/builder_spec.rb in jsonify-0.1.3
- old
+ new
@@ -140,11 +140,11 @@
JSON.parse(json.compile!).should == JSON.parse(expected)
end
it 'should handle arrays' do
json[1] = [2, 3]
json[4] = 5
- json.compile!.should == '{"1":[2,3],"4":5}'
+ JSON.parse(json.compile!).should == JSON.parse('{"1":[2,3],"4":5}')
end
end
describe 'using blocks' do
@@ -187,10 +187,19 @@
json.foo(ary) do |n|
n * 2
end
json.compile!.should == '{"foo":[2,4,6]}'
end
+
+ it 'hash with empty array by iteration' do
+ ary = []
+ json.foo(ary) do |n|
+ n * 2
+ end
+ expected = '{"foo":[]}'
+ JSON.parse(json.compile!).should == JSON.parse(expected)
+ end
it 'simple array with object' do
json << 1
json << {:foo => :bar}
json.compile!.should == '[1,{"foo":"bar"}]'
@@ -221,10 +230,11 @@
describe 'without blocks' do
describe 'complex array' do
it 'should work' do
json.bar [1,2,{:foo => 'goo'}]
- json.compile!.should == "{\"bar\":[1,2,{\"foo\":\"goo\"}]}"
+ expected = "{\"bar\":[1,2,{\"foo\":\"goo\"}]}"
+ JSON.parse(json.compile!).should == JSON.parse(expected)
end
end
describe 'object with null' do
it 'should handle missing argument' do
\ No newline at end of file