nug v0.3.1 Nug

Provides a macro for using Nug in tests

Link to this section Summary

Functions

with_proxy is convenience macro that will handle setup and teardown of your proxy server.

Link to this section Functions

Link to this macro

with_proxy(upstream_url, recording_file, test_body)

(macro)

with_proxy is convenience macro that will handle setup and teardown of your proxy server.

Usage

The with_proxy macro starts the proxy server and provides you with a variable in the block called address this is the server address that will be listening for requests made in the block

defmodule TestCase do
  use ExUnit.Case, async: true
  use Nug

  test "get response from API" do
    with_proxy("https://www.example.com", "test/fixtures/example.json") do
      # address is a variable that is created by the macro
      client = TestClient.new("http://#{address}")

      {:ok, response} = Tesla.get(client, "/", query: [q: "hello"])

      assert response.status == 200
    end
  end
end