Sha256: f4f5e438bfa1173cec9b35f9d84d165f642349cfaa602fc293bd154c6363efc3

Contents?: true

Size: 699 Bytes

Versions: 1

Compression:

Stored size: 699 Bytes

Contents

require 'multi_json'

to_inherit = Capybara.const_defined?("RackTest") ? Capybara::RackTest::Driver : Capybara::Driver::RackTest

class Capybara::RackTestJson::Driver < to_inherit
  def body
    MultiJson.decode(source) || {}
  end

  %w[ post put ].each do |method|
    class_eval %{
      def #{method}(path, json, env = {})
        json = MultiJson.encode(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)
        }.merge(env)
        
        super(path, {}, request_env)
      end
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capybara-json-0.0.2 lib/capybara/rack_test_json/driver.rb