Sha256: 6135bf0f5f1c73a2bdc9690d5db6f793f662c71681fe5f37969943458218b1a3

Contents?: true

Size: 801 Bytes

Versions: 2

Compression:

Stored size: 801 Bytes

Contents

require "json"

module Rack
  module Minitest
    module JSON
      def last_json_response
        ::JSON.parse(last_response.body)
      end

      def get_json(path, params = {}, headers = {})
        json_request :get, path, params, headers
      end

      def post_json(path, params = {}, headers = {})
        json_request :post, path, params, headers
      end

      def put_json(path, params = {}, headers = {})
        json_request :put, path, params, headers
      end

      def delete_json(path, params = {}, headers = {})
        json_request :delete, path, params, headers
      end

      private

      def json_request(verb, path, params = {}, headers = {})
        send verb, path, params.to_json, headers.merge({ "CONTENT_TYPE" => "application/json" })
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rack-minitest-0.0.10 lib/rack-minitest/json.rb
rack-minitest-0.0.9 lib/rack-minitest/json.rb