From cd5421e9867f00272788eed5822c2351b21a329f Mon Sep 17 00:00:00 2001 From: lridge Date: Thu, 4 Jan 2024 14:41:10 -0500 Subject: [PATCH 1/4] bump version; replace httpi with faraday; --- lib/wasabi/resolver.rb | 10 +++++----- lib/wasabi/version.rb | 2 +- wasabi.gemspec | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) 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/wasabi.gemspec b/wasabi.gemspec index 26a07fd..e47751d 100644 --- a/wasabi.gemspec +++ b/wasabi.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.license = 'MIT' - s.add_dependency "httpi", "~> 3.0" + s.add_dependency "faraday", ">= 2.8" s.add_dependency "nokogiri", ">= 1.13.9" s.add_dependency "addressable" From d7ee517226ebc9562e6f00eca7786d7496eccb4f Mon Sep 17 00:00:00 2001 From: lridge Date: Fri, 5 Jan 2024 07:43:07 -0500 Subject: [PATCH 2/4] constrain faraday --- wasabi.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasabi.gemspec b/wasabi.gemspec index e47751d..fa0a15f 100644 --- a/wasabi.gemspec +++ b/wasabi.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.license = 'MIT' - s.add_dependency "faraday", ">= 2.8" + s.add_dependency "faraday", "~> 2.8" s.add_dependency "nokogiri", ">= 1.13.9" s.add_dependency "addressable" From 15d7f0732393dc60dfd24adbd8368c509e7d7e3f Mon Sep 17 00:00:00 2001 From: lridge Date: Fri, 5 Jan 2024 08:27:10 -0500 Subject: [PATCH 3/4] update wasabi web specs --- spec/support/adapter.rb | 20 -------------------- spec/support/responses.rb | 8 ++++++++ spec/wasabi/document_spec.rb | 8 ++++++-- spec/wasabi/resolver_spec.rb | 31 ++++++++++++++++--------------- 4 files changed, 30 insertions(+), 37 deletions(-) delete mode 100644 spec/support/adapter.rb create mode 100644 spec/support/responses.rb 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..f0c3ea2 --- /dev/null +++ b/spec/support/responses.rb @@ -0,0 +1,8 @@ +class Responses + class << self + def mock_faraday(code, headers, body) + env = Faraday::Env.new(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 = "404 Not FoundOops!" - failed_response = HTTPI::Response.new(code, headers, body) - - expect(HTTPI).to receive(:get) { failed_response } - + failed_response = Responses.mock_faraday(code, headers, body) + expect(Faraday::Connection).to receive(:new).and_return( + connection = instance_double(Faraday::Connection, get: failed_response) + ) url = "http://example.com?wsdl" expect do Wasabi::Resolver.new(url).resolve - end.to raise_error { |ex| + end.to(raise_error{ |ex| expect(ex).to be_a(Wasabi::Resolver::HTTPError) expect(ex.message).to eq("Error: #{code} for url #{url}") expect(ex.response).to eq(failed_response) - } + }) end end From 410f05f27a78e4bc5fff01fd4ab6bce1199c3466 Mon Sep 17 00:00:00 2001 From: lridge Date: Mon, 8 Jan 2024 12:39:51 -0500 Subject: [PATCH 4/4] use from initializer for faraday env since they provide it. --- spec/support/responses.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/responses.rb b/spec/support/responses.rb index f0c3ea2..1d4b005 100644 --- a/spec/support/responses.rb +++ b/spec/support/responses.rb @@ -1,7 +1,7 @@ class Responses class << self def mock_faraday(code, headers, body) - env = Faraday::Env.new(status: code, response_headers: headers, response_body: body) + env = Faraday::Env.from(status: code, response_headers: headers, response_body: body) Faraday::Response.new(env) end end