test/test_protocol.rb in atom-tools-2.0.1 vs test/test_protocol.rb in atom-tools-2.0.2

- old
+ new

@@ -1,9 +1,12 @@ require "test/unit" require "atom/service" +# needed for hpricot +require "rubygems" + class FakeHTTP Response = Struct.new(:body, :code, :content_type) def initialize table @table = table @@ -23,10 +26,21 @@ res end end class AtomProtocolTest < Test::Unit::TestCase + attr_reader :have_hpricot + + def initialize *args + super + + require "hpricot" + @have_hpricot = true + rescue LoadError + puts "skipping hpricot tests" + end + def test_introspection doc = <<END <service xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom"> <workspace> @@ -121,10 +135,12 @@ assert_instance_of Atom::HTTP, collection.instance_variable_get("@http") end def test_autodiscover_service_link + return unless have_hpricot + http = FakeHTTP.new \ 'http://example.org/' => [ 'text/html', '<html><link rel="service" href="svc">' ], 'http://example.org/xhtml' => [ 'text/html', '<html><head><link rel="service" href="svc"/></head></html>' ], 'http://example.org/svc' => [ 'application/atomsvc+xml', '<service xmlns="http://www.w3.org/2007/app"/>' ] @@ -134,10 +150,12 @@ svc = Atom::Service.discover 'http://example.org/xhtml', http assert_instance_of Atom::Service, svc end def test_autodiscover_rsd + return unless have_hpricot + http = FakeHTTP.new \ 'http://example.org/' => [ 'text/html', '<html><link rel="EditURI" href="rsd">' ], 'http://example.org/svc' => [ 'application/atomsvc+xml', '<service xmlns="http://www.w3.org/2007/app"/>' ], 'http://example.org/rsd' => [ 'text/xml', '<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"><service><apis><api name="Atom" apiLink="svc" /></apis></service></rsd>' ] @@ -152,9 +170,11 @@ svc = Atom::Service.discover 'http://example.org/svc', http assert_instance_of Atom::Service, svc end def test_cant_autodiscover + return unless have_hpricot + http = FakeHTTP.new 'http://example.org/h' => [ 'text/html', '<html>' ], 'http://example.org/t' => [ 'text/plain', 'no joy.' ] assert_raises Atom::AutodiscoveryFailure do Atom::Service.discover 'http://example.org/h', http