dm1try / jequalson

helpers for a testing JSON responses

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JequalSON

Build Status Coverage Status

Usage

For example, lets check that a first user in twitter response matches a provided schema:

  # assume that you use Poison to parse responses
  response = Poison.Parser.parse!(twitter_response)

  JequalSON.match? response, "statuses[0].user", %{
    name: "Sean Cummings",
    id_str: :string,
    followers_count: :integer,
    entities: %{
      url: :object
    }
  }

See specs for more examples.

Path

Path can include specific characters for collections: * - means all, ? - means any

  # all statuses
  JequalSON.match? response, "statuses[*]", %{...}

  # any of statuses
  JequalSON.match? response, "statuses[?]", %{...}

Schema

Matching can be done for a value ifself or for its type. Also you can define own matching function.

    hex_color = fn(v)->
      Regex.match?(~r/^[A-F0-9]{6}$/, v)
        or {:failure, "#{v} is not hex a color"}
    end

    JequalSON.match? response, "statuses[0].user", %{
        name: "Sean Cummings",
        id_str: :string, # use the atom to specify a type
        profile_background_color: hex_color # use the func defined above
      }

Installation

  1. Add JequalSON to your list of dependencies in mix.exs:

    def deps do [{:jequalson, "~> 0.1"}] end

ESpec/ExUnit matchers

TODO

Inspirations

API testing framework Airborne

About

helpers for a testing JSON responses


Languages

Language:Elixir 100.0%