lib/capybara/httpclient_json/driver.rb in capybara-json-0.1.2 vs lib/capybara/httpclient_json/driver.rb in capybara-json-0.2.0

- old
+ new

@@ -1,15 +1,22 @@ require 'httpclient' -class Capybara::HTTPClientJson::Driver < Capybara::Driver::Base +class Capybara::HTTPClientJson::Driver < Capybara::Json::Driver::Base attr_reader :app, :current_url, :rack_server, :response, :cookies def client unless @client @client = HTTPClient.new @client.follow_redirect_count = 5 + 1 # allows 5 redirection @client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE + + # hack for redirect + def @client.redirect_uri_callback_to_keep_new_uri(uri, res) + new_uri = default_redirect_uri_callback(uri, res) + @new_uri = new_uri + end + @client.redirect_uri_callback = @client.method(:redirect_uri_callback_to_keep_new_uri) end @client end def initialize(app) @@ -68,20 +75,26 @@ def #{method}!(url, json, headers = {}) handle_error { #{method}(url, json, headers) } end } end - + def reset! @client = nil end protected def process(method, path, params = {}, headers = {}, options = {}) @current_url = @rack_server.url(path) begin @response = client.__send__(method, @current_url, params, headers, options) + + # hack for redirect + if new_uri = client.instance_variable_get(:@new_uri) + @current_url = new_uri.to_s + client.instance_variable_set(:@new_uri, nil) + end rescue HTTPClient::BadResponseError => e if e.message == "retry count exceeded" raise Capybara::InfiniteRedirectError else @response = e.res