1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe "Yajl" do
context "dump" do
it "should exist as a class-method" do
expect(Yajl).to respond_to(:dump)
end
it "should be able to encode to a string" do
expect(Yajl.dump({:a => 1234})).to eql('{"a":1234}')
end
it "should be able to encode to an IO" do
io = StringIO.new
Yajl.dump({:a => 1234}, io)
io.rewind
expect(io.read).to eql('{"a":1234}')
end
it "should be able to encode with a block supplied" do
Yajl.dump({:a => 1234}) do |chunk|
expect(chunk).to eql('{"a":1234}')
end
end
end
context "load" do
it "should exist as a class-method" do
expect(Yajl).to respond_to(:load)
end
it "should be able to parse from a string" do
expect(Yajl.load('{"a":1234}')).to eql({"a" => 1234})
end
it "should be able to parse from an IO" do
io = StringIO.new('{"a":1234}')
expect(Yajl.load(io)).to eql({"a" => 1234})
end
it "should be able to parse from a string with a block supplied" do
Yajl.load('{"a":1234}') do |h|
expect(h).to eql({"a" => 1234})
end
end
it "should be able to parse from an IO with a block supplied" do
io = StringIO.new('{"a":1234}')
Yajl.load(io) do |h|
expect(h).to eql({"a" => 1234})
end
end
end
end
|