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 55 56 57 58 59
|
require File.dirname(__FILE__) + '/../../spec_helper'
describe "OEmbed::Formatter::XML::Backends::Nokogiri" do
include OEmbedSpecHelper
before(:all) do
expect {
OEmbed::Formatter::XML.backend = 'Nokogiri'
}.to raise_error(LoadError)
require 'nokogiri'
expect {
OEmbed::Formatter::XML.backend = 'Nokogiri'
}.to_not raise_error
end
it "should support XML" do
expect {
OEmbed::Formatter.supported?(:xml)
}.to_not raise_error
end
it "should be using the Nokogiri backend" do
expect(OEmbed::Formatter::XML.backend).to eq(OEmbed::Formatter::XML::Backends::Nokogiri)
end
it "should decode an XML String" do
decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
# We need to compare keys & values separately because we don't expect all
# non-string values to be recognized correctly.
expect(decoded.keys).to eq(valid_response(:object).keys)
expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
end
it "should raise an OEmbed::ParseError when decoding an invalid XML String" do
expect {
decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_container', :xml))
}.to raise_error(OEmbed::ParseError)
expect {
decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_tag', :xml))
}.to raise_error(OEmbed::ParseError)
expect {
decode = OEmbed::Formatter.decode(:xml, invalid_response('invalid_syntax', :xml))
}.to raise_error(OEmbed::ParseError)
end
it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
error_to_raise = ArgumentError
expect(OEmbed::Formatter::XML.backend.parse_error).to_not be_kind_of(error_to_raise)
expect(::Nokogiri::XML::Document).to receive(:parse).
and_raise(error_to_raise.new("unknown error"))
expect {
decode = OEmbed::Formatter.decode(:xml, valid_response(:xml))
}.to raise_error(OEmbed::ParseError)
end
end
|