Sha256: a3bf5b233fe85e2e41d7fb6b510c402ce9ad96165ada7eb99f83e84643eed951
Contents?: true
Size: 1.82 KB
Versions: 1
Compression:
Stored size: 1.82 KB
Contents
require 'httpclient' class Capybara::HTTPClientJson::Driver < Capybara::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 end @client end def initialize(app) @app = app @rack_server = Capybara::Server.new(@app) @rack_server.boot if Capybara.run_server end def status_code response.code end def source response.body end def body MultiJson.decode(source) || {} end def response_headers response.headers end def get(url, params = {}, headers = {}) process :get, url, params, headers, true # follow_redirect end alias visit get def post(url, json, headers = {}) json = MultiJson.encode(json) unless json.is_a?(String) headers['Content-Type'] = "application/json; charset=#{json.encoding.to_s.downcase}" process :post, url, json, headers, true # follow_redirect end def put(url, json, headers = {}) json = MultiJson.encode(json) unless json.is_a?(String) headers['Content-Type'] = "application/json; charset=#{json.encoding.to_s.downcase}" process :put, url, json, headers end def delete(url, params = {}, headers = {}) process :delete, url, params, headers 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) rescue HTTPClient::BadResponseError => e if e.message == "retry count exceeded" raise Capybara::InfiniteRedirectError else @response = e.res end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
capybara-json-0.1.0 | lib/capybara/httpclient_json/driver.rb |