Sha256: aff54898d8f455c7f1b6a45fb8a3763323132e176e7f820e6f08beb9c6e81ce7

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'
require 'rexml/document'
require 'open_tok/exception'

describe OpenTok::OpenTokException do

  subject { OpenTok::OpenTokException }

  describe "when inhereted" do
    it "should include the subclass in the internal structure" do
      length = OpenTok::OpenTokException.exceptions.length
      Foo = Class.new OpenTok::OpenTokException do
        def self.http_code
          1000
        end
      end
      OpenTok::OpenTokException.exceptions.length.should eq length+1
    end
  end

  describe "when creating an exception" do

    let(:body_error) { "<Errors><error code='404'><itemNotFound message='Archive foo not found'/></error></Errors>"}

    let(:body_unknown_error) { "<Errors><error code='100'></error></Errors>"}

    it "should find the relevant child using the HTTP error code" do
      response = REXML::Document.new body_error
      OpenTok::OpenTokException.from_error(response).should be_instance_of OpenTok::OpenTokNotFound
    end

    it "should return the general exception if unknown HTTP error code" do
      response = REXML::Document.new body_unknown_error
      OpenTok::OpenTokException.from_error(response).should be_instance_of OpenTok::OpenTokException
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opentok-0.1.3 spec/opentok_exception_spec.rb
opentok-0.1.2 spec/opentok_exception_spec.rb
opentok-0.1.1 spec/opentok_exception_spec.rb
opentok-0.1.0 spec/opentok_exception_spec.rb