diff --git a/lib/wasabi/resolver.rb b/lib/wasabi/resolver.rb index bf15c62..91ab543 100644 --- a/lib/wasabi/resolver.rb +++ b/lib/wasabi/resolver.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "httpi" +require "faraday" module Wasabi @@ -22,7 +22,7 @@ def initialize(message, response=nil) def initialize(document, request = nil, adapter = nil) @document = document - @request = request || HTTPI::Request.new + @request = request || Faraday.new @adapter = adapter end @@ -41,10 +41,10 @@ def resolve private def load_from_remote - request.url = document - response = HTTPI.get(request, adapter) + request.adapter *adapter if adapter + response = request.get(document) - raise HTTPError.new("Error: #{response.code} for url #{request.url}", response) if response.error? + raise HTTPError.new("Error: #{response.status} for url #{document}", response) unless response.success? response.body end diff --git a/lib/wasabi/version.rb b/lib/wasabi/version.rb index 6aa4177..748ca90 100644 --- a/lib/wasabi/version.rb +++ b/lib/wasabi/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Wasabi - VERSION = '4.0.0' + VERSION = '5.0.0' end diff --git a/spec/support/adapter.rb b/spec/support/adapter.rb deleted file mode 100644 index 5794715..0000000 --- a/spec/support/adapter.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class FakeAdapterForTest < HTTPI::Adapter::Base - - register :fake_adapter_for_test - - def initialize(request) - @@requests ||= [] - @@requests.push request - @request = request - end - - attr_reader :client - - def request(method) - @@methods ||= [] - @@methods.push method - HTTPI::Response.new(200, {}, 'wsdl_by_adapter') - end -end diff --git a/spec/support/responses.rb b/spec/support/responses.rb new file mode 100644 index 0000000..1d4b005 --- /dev/null +++ b/spec/support/responses.rb @@ -0,0 +1,8 @@ +class Responses + class << self + def mock_faraday(code, headers, body) + env = Faraday::Env.from(status: code, response_headers: headers, response_body: body) + Faraday::Response.new(env) + end + end +end \ No newline at end of file diff --git a/spec/wasabi/document_spec.rb b/spec/wasabi/document_spec.rb index f1bb1ec..69aaac5 100644 --- a/spec/wasabi/document_spec.rb +++ b/spec/wasabi/document_spec.rb @@ -7,9 +7,13 @@ subject { Wasabi::Document.new fixture(:authentication).read } it "accepts a URL" do - expect(HTTPI).to receive(:get) { HTTPI::Response.new(200, {}, "wsdl") } + path = 'http://example.com?wsdl' + stubs = Faraday::Adapter::Test::Stubs.new + stubs.get(path) do + [200, {'Content-Type': 'application/xml'}, 'wsdl'] + end - document = Wasabi::Document.new("http://example.com?wsdl") + document = Wasabi::Document.new(path, [:test, stubs]) expect(document.xml).to eq("wsdl") end diff --git a/spec/wasabi/resolver_spec.rb b/spec/wasabi/resolver_spec.rb index 019df43..81cc646 100644 --- a/spec/wasabi/resolver_spec.rb +++ b/spec/wasabi/resolver_spec.rb @@ -6,20 +6,21 @@ describe "#resolve" do it "resolves remote documents" do - expect(HTTPI).to receive(:get) { HTTPI::Response.new(200, {}, "wsdl") } + expect(Faraday::Connection).to receive(:new).and_return( + connection = instance_double(Faraday::Connection, get: Responses.mock_faraday(200, {}, "wsdl")) + ) xml = Wasabi::Resolver.new("http://example.com?wsdl").resolve expect(xml).to eq("wsdl") end it "resolves remote documents with custom adapter" do - prev_logging = HTTPI.instance_variable_get(:@log) - HTTPI.log = false # Don't pollute rspec output by request logging - xml = Wasabi::Resolver.new("http://example.com?wsdl", nil, :fake_adapter_for_test).resolve - expect(xml).to eq("wsdl_by_adapter") - expect(FakeAdapterForTest.class_variable_get(:@@requests).size).to eq(1) - expect(FakeAdapterForTest.class_variable_get(:@@requests).first.url).to eq(URI.parse("http://example.com?wsdl")) - expect(FakeAdapterForTest.class_variable_get(:@@methods)).to eq([:get]) - HTTPI.log = prev_logging + path = 'http://example.com?wsdl' + stubs = Faraday::Adapter::Test::Stubs.new + stubs.get(path) do + [200, {'Content-Type': 'application/xml'}, 'wsdl'] + end + xml = Wasabi::Resolver.new("http://example.com?wsdl", nil, [:test, stubs]).resolve + expect(xml).to eq("wsdl") end it "resolves local documents" do @@ -38,19 +39,19 @@ "content-type" => "text/html" } body = "