chaperon v0.3.1 Chaperon.Action View Source

Helper functions to be used with Chaperon.Actionable.

Link to this section Summary

Functions

Every Chaperon.Actionable can expose a callback field.

Returns a Chaperon.Action.Error for the given arguments.

Retries action within session by calling Chaperon.Actionable.abort/2 followed by Chaperon.Actionable.run/2.

Link to this section Functions

Every Chaperon.Actionable can expose a callback field.

callback can be either:

  • a callback function or atom naming the callback function inside the session's current scenario module:

    atom | ((Chaperon.Session.t, any | {:error, any}) -> any)

  • a map containing callback and error functions:

      %{
        ok:    atom | ((Chaperon.Session.t, any) -> any),
        error: atom | ((Chaperon.Session.t, any) -> any)
      }

When defining just a single callback function, it will be called in both success and error cases (passed in as {:error, reason}). To handle each case individually, you can just use pattern matching:

session
|> post("/greet", json: [hello: "world!"], with_result: fn
  (session, {:error, reason}) ->
    # handle error case here
    session
    |> log_error("Failed to greet")

  (session, %HTTPoison.Response{body: response}) ->
    # do something with successful response here
    session
    |> log_info("Greeted successfully!")
end)
Link to this function

error(action, session, reason)

View Source

Returns a Chaperon.Action.Error for the given arguments.

Retries action within session by calling Chaperon.Actionable.abort/2 followed by Chaperon.Actionable.run/2.