lib/capybara/httpclient_json/driver.rb in capybara-json-0.2.0 vs lib/capybara/httpclient_json/driver.rb in capybara-json-0.2.1
- old
+ new
@@ -1,9 +1,9 @@
require 'httpclient'
class Capybara::HTTPClientJson::Driver < Capybara::Json::Driver::Base
- attr_reader :app, :current_url, :rack_server, :response, :cookies
+ attr_reader :app, :options, :current_url, :response, :cookies
def client
unless @client
@client = HTTPClient.new
@client.follow_redirect_count = 5 + 1 # allows 5 redirection
@@ -17,12 +17,12 @@
@client.redirect_uri_callback = @client.method(:redirect_uri_callback_to_keep_new_uri)
end
@client
end
- def initialize(app)
- @app = app
+ def initialize(app, options = {})
+ @app, @options = app, { :follow_redirect => true }.merge(options)
@rack_server = Capybara::Server.new(@app)
@rack_server.boot if Capybara.run_server
end
def status_code
@@ -32,29 +32,29 @@
def source
response.body
end
def body
- MultiJson.decode(source) || {}
+ MultiJson.load(source) || {}
end
def response_headers
response.headers
end
def get(url, params = {}, headers = {})
- process :get, url, params, headers, true # follow_redirect
+ process :get, url, params, headers, options[:follow_redirect]
end
alias visit get
def post(url, json, headers = {})
- json = MultiJson.encode(json) unless json.is_a?(String)
+ json = MultiJson.dump(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
+ process :post, url, json, headers, options[:follow_redirect]
end
def put(url, json, headers = {})
- json = MultiJson.encode(json) unless json.is_a?(String)
+ json = MultiJson.dump(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 = {})