-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed the dependency on HTTPI /cc #27
Since Wasabi only does GET requests, it only needs a very simple interface for sending HTTP requests which works great with testing and allows you to use any HTTP client via a very simple adapter. see spec/support/http_mock.rb for an example.
- Loading branch information
Showing
9 changed files
with
82 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("<xml/>") | ||
xml.should == "<xml/>" | ||
end | ||
|
||
it "raises HTTPError when #load_from_remote gets a response error" do | ||
code = 404 | ||
headers = { | ||
"content-type" => "text/html" | ||
} | ||
body = "<html><head><title>404 Not Found</title></head><body>Oops!</body></html>" | ||
|
||
failed_response = HTTPI::Response.new(code, headers, body) | ||
HTTPI.stubs(:get).returns(failed_response) | ||
|
||
expect { Wasabi::Resolver.new.resolve("http://example.com?wsdl") }.to raise_error { |error| | ||
error.should be_a(Wasabi::Resolver::HTTPError) | ||
error.message.should == "Error: #{code}" | ||
error.response.should == failed_response | ||
} | ||
end | ||
subject(:resolver) { Wasabi::Resolver.new(http_test_client) } | ||
|
||
let(:http_test_client) { | ||
Class.new { | ||
|
||
def get(url) | ||
"raw_response for #{url}" | ||
end | ||
|
||
}.new | ||
} | ||
|
||
it 'resolves remote files using a simple HTTP client interface' do | ||
url = 'http://example.com?wsdl' | ||
|
||
xml = resolver.resolve(url) | ||
expect(xml).to eq("raw_response for #{url}") | ||
end | ||
|
||
it 'resolves local files' do | ||
fixture = fixture(:authentication) | ||
|
||
xml = resolver.resolve(fixture.path) | ||
expect(xml).to eq(fixture.read) | ||
end | ||
|
||
it 'simply returns any raw input' do | ||
string = '<xml/>' | ||
|
||
xml = resolver.resolve(string) | ||
expect(xml).to eq(string) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters