|
6 | 6 |
|
7 | 7 | describe "#resolve" do |
8 | 8 | it "resolves remote documents" do |
9 | | - expect(HTTPI).to receive(:get) { HTTPI::Response.new(200, {}, "wsdl") } |
| 9 | + expect(Faraday::Connection).to receive(:new).and_return( |
| 10 | + connection = instance_double(Faraday::Connection, get: Responses.mock_faraday(200, {}, "wsdl")) |
| 11 | + ) |
10 | 12 | xml = Wasabi::Resolver.new("http://example.com?wsdl").resolve |
11 | 13 | expect(xml).to eq("wsdl") |
12 | 14 | end |
13 | 15 |
|
14 | 16 | it "resolves remote documents with custom adapter" do |
15 | | - prev_logging = HTTPI.instance_variable_get(:@log) |
16 | | - HTTPI.log = false # Don't pollute rspec output by request logging |
17 | | - xml = Wasabi::Resolver.new("http://example.com?wsdl", nil, :fake_adapter_for_test).resolve |
18 | | - expect(xml).to eq("wsdl_by_adapter") |
19 | | - expect(FakeAdapterForTest.class_variable_get(:@@requests).size).to eq(1) |
20 | | - expect(FakeAdapterForTest.class_variable_get(:@@requests).first.url).to eq(URI.parse("http://example.com?wsdl")) |
21 | | - expect(FakeAdapterForTest.class_variable_get(:@@methods)).to eq([:get]) |
22 | | - HTTPI.log = prev_logging |
| 17 | + path = 'http://example.com?wsdl' |
| 18 | + stubs = Faraday::Adapter::Test::Stubs.new |
| 19 | + stubs.get(path) do |
| 20 | + [200, {'Content-Type': 'application/xml'}, 'wsdl'] |
| 21 | + end |
| 22 | + xml = Wasabi::Resolver.new("http://example.com?wsdl", nil, [:test, stubs]).resolve |
| 23 | + expect(xml).to eq("wsdl") |
23 | 24 | end |
24 | 25 |
|
25 | 26 | it "resolves local documents" do |
|
38 | 39 | "content-type" => "text/html" |
39 | 40 | } |
40 | 41 | body = "<html><head><title>404 Not Found</title></head><body>Oops!</body></html>" |
41 | | - failed_response = HTTPI::Response.new(code, headers, body) |
42 | | - |
43 | | - expect(HTTPI).to receive(:get) { failed_response } |
44 | | - |
| 42 | + failed_response = Responses.mock_faraday(code, headers, body) |
| 43 | + expect(Faraday::Connection).to receive(:new).and_return( |
| 44 | + connection = instance_double(Faraday::Connection, get: failed_response) |
| 45 | + ) |
45 | 46 | url = "http://example.com?wsdl" |
46 | 47 |
|
47 | 48 | expect do |
48 | 49 | Wasabi::Resolver.new(url).resolve |
49 | | - end.to raise_error { |ex| |
| 50 | + end.to(raise_error{ |ex| |
50 | 51 | expect(ex).to be_a(Wasabi::Resolver::HTTPError) |
51 | 52 | expect(ex.message).to eq("Error: #{code} for url #{url}") |
52 | 53 | expect(ex.response).to eq(failed_response) |
53 | | - } |
| 54 | + }) |
54 | 55 | end |
55 | 56 | end |
56 | 57 |
|
|
0 commit comments