Sha256: e067f30a5950cc15bb4919b2265fc6f2d89ad85f31bd1d98896447e017a65b33

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '../../../',  'spec_helper'))

describe Exception do
  
  it "should be able to create json with empty backtrace" do
    e = Exception.new "message"
    e.to_json.should == "{\"json_class\":\"Exception\",\"message\":\"message\",\"backtrace\":null}"
  end

  it "should be able to create a json encodable representation of the exception" do
    e = Exception.new "message"
    e.as_json.should == {"json_class" => "Exception", "message" => "message", "backtrace" => nil}
  end
  
  it "should be able to create json with backtrace" do
    e = Exception.new "message"
    e.set_backtrace ["back", "trace"]
    e.to_json.should == "{\"json_class\":\"Exception\",\"message\":\"message\",\"backtrace\":[\"back\",\"trace\"]}"
  end
  
  it "should be able to deserialize exception from json" do
    e = Exception.new "message"
    e.set_backtrace ["back", "trace"]
    deserialized = JSON(e.to_json)
    deserialized.message.should == "message"
    deserialized.backtrace.should == ["back", "trace"]
  end
  
  it "should be able to serialize and deserialize descendants of the Exception class" do
    class ExceptionSpec <  Exception; end
    e = ExceptionSpec.new "message"
    e.set_backtrace ["back", "trace"]
    deserialized = JSON(e.to_json)
    deserialized.message.should == "message"
    deserialized.backtrace.should == ["back", "trace"]
    deserialized.should be_a ExceptionSpec
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hoth-0.4.2 spec/unit/extension/core/exception_spec.rb
hoth-0.4.1 spec/unit/extension/core/exception_spec.rb
hoth-0.4.0 spec/unit/extension/core/exception_spec.rb
hoth-0.3.4 spec/unit/extension/core/exception_spec.rb