Bookish spork

Alexey Nikitin

Elixir Moscow meetup

6 March 2019

About me

tank-bohr

tank_bohr

If you need to send

  • email
  • sms
  • slack notification
  • error to sentry
  • payment to stripe
  • ...

HTTP request

Testing

  • there is no a canonical way in elixir
  • mocks
  • we can do better

I maked these

Bookish spork

test "sends a short message" do
  :bookish_spork.stub_request([200, [], "{\"status\": \"sent\"}"])

  {:ok, message} = ExTwilio.Message.create(
    to: "+15017122661",
    from: "bookish",
    body: "Hello"
  )
  {:ok, request} = :bookish_spork.capture_request

  assert message.status == "sent"
  assert request.uri == '/2010-04-01/Messages.json'
  assert request.body == "To=%2B15017122661&From=bookish&Body=Hello"
end

Bookish spork is

  • http-client agnostic
  • zero-dependencies
  • test setup is close to the test as possible

Thank you

Bookish spork

By Alexey Nikitin