lib/capybara/rack_test_json/driver.rb in capybara-json-0.2.0 vs lib/capybara/rack_test_json/driver.rb in capybara-json-0.2.1
- old
+ new
@@ -1,21 +1,24 @@
class Capybara::RackTestJson::Driver < Capybara::Json::Driver::Base
- def initialize(app)
- @app = app
+ attr_reader :app, :options
+
+ def initialize(app, options = {})
+ @app, @options = app, { :follow_redirect => true }.merge(options)
end
def client
- @client ||= Capybara::RackTestJson::Client.new(@app)
+ @client ||= Capybara::RackTestJson::Client.new(app, options)
end
def last_request
client.last_request
end
def last_response
client.last_response
end
+ alias response last_response
%w[ get delete ].each do |method|
class_eval %{
def #{method}(path, params = {}, env = {})
client.#{method}(path, params, env_for_rack(env))
@@ -29,11 +32,11 @@
alias visit get
%w[ post put ].each do |method|
class_eval %{
def #{method}(path, json, env = {})
- json = MultiJson.encode(json) unless json.is_a?(String)
+ json = MultiJson.dump(json) unless json.is_a?(String)
request_env = {
'CONTENT_LENGTH' => json.size,
'CONTENT_TYPE' => "application/json; charset=\#{json.encoding.to_s.downcase}",
'rack.input' => StringIO.new(json)
@@ -55,10 +58,10 @@
def source
last_response.body
end
def body
- MultiJson.decode(source) || {}
+ MultiJson.load(source) || {}
end
def response_headers
last_response.headers
end