spec/builder_spec.rb in jsonify-0.3.1 vs spec/builder_spec.rb in jsonify-0.4.0
- old
+ new
@@ -106,11 +106,11 @@
json["foo"] = 'bar'
json.compile!.should == '{"foo":"bar"}'
end
it 'should support the store! message' do
json.store!( "foo", "bar" ).store!( 'no', "whar" )
- MultiJson.decode(json.compile!).should == MultiJson.decode('{"foo":"bar","no":"whar"}')
+ MultiJson.load(json.compile!).should == MultiJson.load('{"foo":"bar","no":"whar"}')
end
end
end
describe 'arrays' do
@@ -135,16 +135,16 @@
describe 'objects' do
it 'simple object should work' do
json.foo :bar
json.go :far
expected = '{"foo":"bar","go":"far"}'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
it 'should handle arrays' do
json[1] = [2, 3]
json[4] = 5
- MultiJson.decode(json.compile!).should == MultiJson.decode('{"1":[2,3],"4":5}')
+ MultiJson.load(json.compile!).should == MultiJson.load('{"1":[2,3],"4":5}')
end
end
describe 'using blocks' do
@@ -153,11 +153,11 @@
json.tag!("bar bar") do
json.tag!('buzz buzz','goo goo')
end
end
expected = '{"foo foo":{"bar bar":{"buzz buzz":"goo goo"}}}'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
it 'complex hash' do
json.foo do
json.bar do
@@ -214,21 +214,21 @@
json << 2012
end
end
end
expected = "{\"foo\":{\"bar\":{\"baz\":\"goo\",\"years\":[2011,2012]}}}"
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
describe 'without blocks' do
describe 'complex array' do
it 'should work' do
json.bar [1,2,{:foo => 'goo'}]
expected = "{\"bar\":[1,2,{\"foo\":\"goo\"}]}"
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
describe 'object with null' do
it 'should handle missing argument' do
@@ -257,54 +257,54 @@
json.href link.url
json.rel link.type
end
end
expected = "{\"result\":{\"person\":{\"fname\":\"George\",\"lname\":\"Burdell\"},\"links\":[{\"href\":\"example.com\",\"rel\":\"self\"},{\"href\":\"foo.com\",\"rel\":\"parent\"}]}}"
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
describe 'ingest!' do
context 'a json object' do
let(:json_string) { '{"my girl":"Friday","my daughter":"Wednesday"}' }
context 'into' do
it 'nothing -- should replace it' do
json.ingest! json_string
- MultiJson.decode(json.compile!).should == MultiJson.decode(json_string)
+ MultiJson.load(json.compile!).should == MultiJson.load(json_string)
end
it 'json object -- should merge' do
json["my boy"] = "Monday"
json["my girl"] = "Sunday"
json.ingest! json_string
expected = '{"my boy":"Monday","my girl":"Friday","my daughter":"Wednesday"}'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
it 'json array -- should add' do
json << 1 << 2
json.ingest! json_string
expected = '[1,2,{"my girl":"Friday","my daughter":"Wednesday"}]'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
end
context 'a json array' do
let(:json_string) { '[1,2,3]' }
context 'into' do
it 'nothing -- should replace it' do
json.ingest! json_string
- MultiJson.decode(json.compile!).should == MultiJson.decode(json_string)
+ MultiJson.load(json.compile!).should == MultiJson.load(json_string)
end
it 'json object -- should raise error' do
json["my boy"] = "Monday"
json["my girl"] = "Sunday"
lambda{ json.ingest! json_string }.should raise_error( ArgumentError )
end
it 'json array -- should add' do
json << 1 << 2
json.ingest! json_string
expected = '[1,2,[1,2,3]]'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
end
end
@@ -321,17 +321,17 @@
json.id kid[:id]
end
end
expected = '{"results":[{"id":1,"children":[{"id":"a"},{"id":"b"}]},{"id":2,"children":[{"id":"c"},{"id":"d"}]}]}'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
it 'simple append' do
json.letters('a'..'c') do |letter|
json << letter.upcase
end
expected = '{"letters":["A","B","C"]}'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
end