0
+require File.dirname(__FILE__) + "/spec_helper"
0
+describe FogbugzOffline::Connection, "#initialize" do
0
+ it "should accept a URL string" do
0
+ lambda { FogbugzOffline::Connection.new("http://my.project.com") }.should_not raise_error
0
+ it "should accept a URI object" do
0
+ lambda { FogbugzOffline::Connection.new(URI.parse("http://my.project.com")) }.should_not raise_error
0
+ it "should convert URL string to URI object" do
0
+ FogbugzOffline::Connection.new("http://my.project.com").root_uri.should be_kind_of(URI)
0
+describe FogbugzOffline::Connection, "#validate!" do
0
+ @url = "http://fogbugz.my-install.com/"
0
+ @connection = FogbugzOffline::Connection.new(@url)
0
+ @connection.stub!(:get).and_return(VALID_XML_RESPONSE)
0
+ it "should open the URI for reading" do
0
+ @connection.should_receive(:get).with(URI.parse(@url).merge("api.xml")).and_return(VALID_XML_RESPONSE)
0
+ it "should record the API URI" do
0
+ @connection.stub!(:get).and_return(NON_STANDARD_API_LOCATION_XML_RESPONSE)
0
+ @connection.api_uri.should == URI.parse(@url).merge("some-api-location.asp?")
0
+ it "should raise a NoApiAtLocation when the #get call raises a SystemException" do
0
+ @connection.stub!(:get).and_raise(Errno::ECONNREFUSED)
0
+ lambda { @connection.validate! }.should raise_error(FogbugzOffline::NoApiAtLocation)
0
+ it "should raise a NoApiAtLocation when the #get call raises an OpenURI::HTTPError" do
0
+ @connection.stub!(:get).and_raise(OpenURI::HTTPError.new("failed error", StringIO.new))
0
+ lambda { @connection.validate! }.should raise_error(FogbugzOffline::NoApiAtLocation)
0
+ it "should raise an InvalidApiResponse when the #get call returns a non-XML, non-XML valid document" do
0
+ @connection.stub!(:get).and_return(HTML_RESPONSE)
0
+ lambda { @connection.validate! }.should raise_error(FogbugzOffline::InvalidApiResponse)
0
+ it "should raise an InvalidApiResponse when the #get call returns a non-XML document" do
0
+ @connection.stub!(:get).and_return(VALID_HTML_RESPONSE)
0
+ lambda { @connection.validate! }.should raise_error(FogbugzOffline::InvalidApiResponse)
0
+ it "should raise an InvalidApiResponse when the #get call returns an XML document with no <url> element" do
0
+ @connection.stub!(:get).and_return(MISSING_URL_ELEMENT_XML_RESPONSE)
0
+ lambda { @connection.validate! }.should raise_error(FogbugzOffline::InvalidApiResponse)
0
+ it "should return self" do
0
+ @connection.validate!.should == @connection
0
+ VALID_XML_RESPONSE = <<EOF
0
+<?xml version="1.0" encoding="UTF-8" ?>
0
+ <minversion>1</minversion>
0
+ MISSING_URL_ELEMENT_XML_RESPONSE = <<EOF
0
+<?xml version="1.0" encoding="UTF-8" ?>
0
+ <minversion>1</minversion>
0
+ NON_STANDARD_API_LOCATION_XML_RESPONSE = <<EOF
0
+<?xml version="1.0" encoding="UTF-8" ?>
0
+ <minversion>1</minversion>
0
+ <url>some-api-location.asp?</url>
0
+ <title>Bleh, you missed!</title>
0
+ <p>This is the test, you stupid git!
0
+ VALID_HTML_RESPONSE = <<EOF
0
+ <title>Bleh, you missed!</title>
0
+ <p>This is the test, you stupid git!</p>
Comments
No one has commented yet.