diff --git a/lib/wasabi.rb b/lib/wasabi.rb
index 2f27130..9e338eb 100644
--- a/lib/wasabi.rb
+++ b/lib/wasabi.rb
@@ -13,8 +13,8 @@ class Wasabi
SOAP_1_1 = 'http://schemas.xmlsoap.org/wsdl/soap/'
SOAP_1_2 = 'http://schemas.xmlsoap.org/wsdl/soap12/'
- def initialize(wsdl, request = nil)
- resolver = Resolver.new(request)
+ def initialize(wsdl, http = nil)
+ resolver = Resolver.new(http)
importer = Importer.new(resolver, self)
@documents, @schemas = importer.import(wsdl)
diff --git a/lib/wasabi/errors.rb b/lib/wasabi/errors.rb
index 5ae3b2b..d662db9 100644
--- a/lib/wasabi/errors.rb
+++ b/lib/wasabi/errors.rb
@@ -2,15 +2,4 @@ class Wasabi
Error = Class.new(StandardError)
- HTTPError = Class.new(Error) do
-
- def initialize(message, response = nil)
- super(message)
- @response = response
- end
-
- attr_reader :response
-
- end
-
end
diff --git a/lib/wasabi/resolver.rb b/lib/wasabi/resolver.rb
index cfe994c..f44edad 100644
--- a/lib/wasabi/resolver.rb
+++ b/lib/wasabi/resolver.rb
@@ -1,13 +1,11 @@
-require 'httpi'
-
class Wasabi
class Resolver
URL_PATTERN = /^http[s]?:/
XML_PATTERN = /^
- def initialize(request = nil)
- @request = request || HTTPI::Request.new
+ def initialize(http)
+ @http = http
end
def resolve(location)
@@ -21,12 +19,7 @@ def resolve(location)
private
def load_from_remote(location)
- @request.url = location
- response = HTTPI.get(@request)
-
- raise HTTPError.new("Error: #{response.code}", response) if response.error?
-
- response.body
+ @http.get(location)
end
def load_from_disc(location)
diff --git a/spec/support/http_mock.rb b/spec/support/http_mock.rb
new file mode 100644
index 0000000..cf65961
--- /dev/null
+++ b/spec/support/http_mock.rb
@@ -0,0 +1,35 @@
+module SpecSupport
+
+ class HTTPMock
+
+ MockError = Class.new(StandardError)
+
+ def initialize
+ @fakes = {}
+ end
+
+ def get(url)
+ @fakes[url] or raise_mock_error! url
+ end
+
+ def fake_request(url, fixture)
+ @fakes[url] = load_fixture(fixture)
+ end
+
+ private
+
+ def load_fixture(fixture)
+ Fixture.new(fixture).read
+ end
+
+ def raise_mock_error!(url)
+ raise MockError, "Unmocked HTTP request to #{url.inspect}"
+ end
+
+ end
+
+ def http_mock
+ @http_mock ||= HTTPMock.new
+ end
+
+end
diff --git a/spec/support/mock_request.rb b/spec/support/mock_request.rb
deleted file mode 100644
index fb3d5c4..0000000
--- a/spec/support/mock_request.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-module SpecSupport
-
- def mock_request(url, fixture_name)
- response = HTTPI::Response.new 200, {}, fixture(fixture_name).read
- HTTPI.expects(:get).with { |r| r.url == URI(url) }.returns(response)
- end
-
-end
diff --git a/spec/wasabi/integration/bookt_spec.rb b/spec/wasabi/integration/bookt_spec.rb
index c742474..3fc07ef 100644
--- a/spec/wasabi/integration/bookt_spec.rb
+++ b/spec/wasabi/integration/bookt_spec.rb
@@ -3,22 +3,22 @@
describe Wasabi do
context 'with: bookt.wsdl' do
- subject(:wsdl) { Wasabi.new(wsdl_url) }
+ subject(:wsdl) { Wasabi.new(wsdl_url, http_mock) }
let(:wsdl_url) { 'http://connect.bookt.com/svc/connect.svc?wsdl' }
let(:wsdl2_url) { 'http://connect.bookt.com/svc/connect.svc?wsdl=wsdl1' }
let(:wsdl3_url) { 'http://connect.bookt.com/svc/connect.svc?wsdl=wsdl0' }
before do
- mock_request wsdl_url, 'bookt/bookt.wsdl'
- mock_request wsdl2_url, 'bookt/bookt2.wsdl'
- mock_request wsdl3_url, 'bookt/bookt3.wsdl'
+ http_mock.fake_request(wsdl_url, 'bookt/bookt.wsdl')
+ http_mock.fake_request(wsdl2_url, 'bookt/bookt2.wsdl')
+ http_mock.fake_request(wsdl3_url, 'bookt/bookt3.wsdl')
# 16 schemas to import
schema_import_base = 'http://connect.bookt.com/svc/connect.svc?xsd=xsd%d'
(0..15).each do |i|
url = schema_import_base % i
- mock_request url, "bookt/bookt#{i}.xsd"
+ http_mock.fake_request(url, "bookt/bookt#{i}.xsd")
end
end
diff --git a/spec/wasabi/integration/bydexchange_spec.rb b/spec/wasabi/integration/bydexchange_spec.rb
index 000e186..b255102 100644
--- a/spec/wasabi/integration/bydexchange_spec.rb
+++ b/spec/wasabi/integration/bydexchange_spec.rb
@@ -3,20 +3,20 @@
describe Wasabi do
context 'with: bydexchange.wsdl' do
- subject(:wsdl) { Wasabi.new(wsdl_url) }
+ subject(:wsdl) { Wasabi.new(wsdl_url, http_mock) }
let(:wsdl_url) { 'http://bydexchange.nbs-us.com/BYDExchangeServer.svc?wsdl' }
let(:wsdl2_url) { 'http://bydexchange.nbs-us.com/BYDExchangeServer.svc?wsdl=wsdl0' }
before do
- mock_request wsdl_url, 'bydexchange/bydexchange.wsdl'
- mock_request wsdl2_url, 'bydexchange/bydexchange2.wsdl'
+ http_mock.fake_request(wsdl_url, 'bydexchange/bydexchange.wsdl')
+ http_mock.fake_request(wsdl2_url, 'bydexchange/bydexchange2.wsdl')
# 8 schemas to import
schema_import_base = 'http://bydexchange.nbs-us.com/BYDExchangeServer.svc?xsd=xsd%d'
(0..8).each do |i|
url = schema_import_base % i
- mock_request url, "bydexchange/bydexchange#{i}.xsd"
+ http_mock.fake_request(url, "bydexchange/bydexchange#{i}.xsd")
end
end
diff --git a/spec/wasabi/resolver_spec.rb b/spec/wasabi/resolver_spec.rb
index 1259c04..15ae036 100644
--- a/spec/wasabi/resolver_spec.rb
+++ b/spec/wasabi/resolver_spec.rb
@@ -1,40 +1,38 @@
-require "spec_helper"
+require 'spec_helper'
describe Wasabi::Resolver do
- describe "#resolve" do
- it "resolves remote documents" do
- HTTPI.expects(:get).returns HTTPI::Response.new(200, {}, "wsdl")
- xml = Wasabi::Resolver.new.resolve("http://example.com?wsdl")
- xml.should == "wsdl"
- end
-
- it "resolves local documents" do
- xml = Wasabi::Resolver.new.resolve(fixture(:authentication).path)
- xml.should == fixture(:authentication).read
- end
-
- it "simply returns raw XML" do
- xml = Wasabi::Resolver.new.resolve("