Sha256: 818f0984fb14f7a6cc2f3e3471bc6bdae089ac7530135733d011025473576d86
Contents?: true
Size: 1.46 KB
Versions: 13
Compression:
Stored size: 1.46 KB
Contents
require File.dirname(__FILE__) + '/spec_helper' require File.dirname(__FILE__) + '/../lib/g5k/parsing' include G5K::Parsing describe "Parsing" do before do require 'rubygems' end it "should add the json parser" do Parser.add(JSONParser).available_parsers.should include(JSONParser) end it "should return an error if a parser is not available for the required format" do Parser.add(JSONParser) lambda{Parser.select(:xml)}.should raise_error(UnsupportedFormat) end it "should raise an UnsupportedFormat if the given format is nil" do lambda{Parser.select(nil)}.should raise_error(UnsupportedFormat) end it "should select the parser for the given format, if made available" do Parser.add(JSONParser) Parser.select(:json).should == JSONParser end end describe JSONParser do before do require 'rubygems' end it "should successfully parse a json object" do object = {'a' => 1, 'b' => {'c' => 2, 'd' => [3]}} JSONParser.load(object.to_json).should == object end it "should pretty generate an object" do object = {'a' => 1, 'b' => {'c' => 2, 'd' => [3]}} JSON.should_receive(:pretty_generate).with(object) JSONParser.dump(object, :format => :pretty) end it "should not pretty generate an object" do object = {'a' => 1, 'b' => {'c' => 2, 'd' => [3]}} JSON.should_not_receive(:pretty_generate).with(object) object.should_receive(:to_json) JSONParser.dump(object, :format => :raw) end end
Version data entries
13 entries across 13 versions & 1 rubygems