Closed Envek closed 10 years ago
Just thinking out loud, but it seems like the best way to test this might be to make a fake adapter that just records calls, then you could have an assertion that the fake adapter was called at some point with the expected arguments.
The fake might look something like this... (shamelessly stolen from the httpi docs)
class FakeAdapter < HTTPI::Adapter::Base
register :my_adapter, deps: %w(some_http_client)
def initialize(request)
@@requests ||= []
@@requests.push request
@request = request
@client = SomeHTTPClient.new
end
attr_reader :client
def request(method)
@@methods ||= []
@@methods.push method
response = @client.request(method, @request.url, @request.body)
Response.new(response.code, response.header, response.content)
end
end
# in test, you could assert on class variables after the requests have been made
expect(FakeAdapter.class_variable_get(:@@requests).size).to eq(1)
expect(FakeAdapter.class_variable_get(:@@requests)[0].url).to eq("http://example.org")
expect(FakeAdapter.class_variable_get(:@@methods)).to eq([:GET, :POST])
Also -- when this gets merged in, i'm probably going to bump the minor version number since this is a new feature. No need to bump it yourself.
It will be useful for those people who need to use different HTTPI adapters for different services, see savonrb/savon#564
I've bumped gem version as there is related pull request in savon that depend on it: savonrb/savon#566.
I don't know, how to test this, please tell me any ideas and suggestions, I'll write tests and append it to this request.