-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: test helpers #59
Comments
Hi @KushalP! Are you using Ecto? If so you can use the Ecto repo integration and then you can just query the database as per usual, the sandbox takes care of the rest. This is great because the entire queuing system is tested and there's no mocks that result in a difference between tests and production. I'm querying it using this module: defmodule MyApp.Job do
use Ecto.Schema
defmodule ETF do
@behaviour Ecto.Type
def type, do: :bytea
def load(serialized_mfa) when is_binary(serialized_mfa) do
{:ok, :erlang.binary_to_term(serialized_mfa)}
end
def load(nil, _), do: {:ok, nil}
def load(_, _), do: :error
def dump(mfa) do
{:ok, :erlang.term_to_binary(mfa)}
end
def cast(mfa = {mod, fun, args}) when is_atom(mod) and is_atom(fun) and is_list(args) do
{:ok, mfa}
end
def cast(_), do: :error
end
schema Rihanna.Job.table() do
field(:term, __MODULE__.ETF)
field(:due_at, :utc_datetime)
end
def enqueued do
__MODULE__ |> MyApp.Repo.all()
end
end I could imagine this (and a few other Ecto query functions) being quite useful for introspection, perhaps we should publish a new hex package. |
@lpil that's interesting. Can you give an example of how you're using this module in tests please? |
assert MyApp.Job.enqueued() == [] No setup or teardown required. |
Interesting. Maybe it's worth making this step easier for our jobs? |
What would you be after to make it easier for you? :) |
Testing behaviour and outcomes is an important part of developing software for many teams. Making it easier to test
Rihanna
job behaviour inExUnit
tests would be helpful to this aim.Ideally we would have the following functions available:
There may be more that would be useful.
Example usage
I'd imagine the first of these functions to be used as part of the initialisation of a test. The second of these could be used to check that some event triggers a job being enqueued.
Attribution/Inspiration
This isn't a new idea. Most of this I'm stealing from rspec-que.
The text was updated successfully, but these errors were encountered: