Sha256: 0546b9d97e180df5db4c6981595305bc86418cea0947c2120409511b71f73b4b

Contents?: true

Size: 677 Bytes

Versions: 2

Compression:

Stored size: 677 Bytes

Contents

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

2 entries across 2 versions & 1 rubygems

Version Path
capybara-json-0.1.0 lib/capybara/rack_test_json/driver.rb
capybara-json-0.0.3 lib/capybara/rack_test_json/driver.rb