Questions tagged [ex-unit]

ExUnit is a unit testing library that ships as part of the Elixir standard library.

ExUnit Docs

117 questions
0
votes
1 answer

Why is params_for not going through the changeset?

Why is params_for not going through the changeset model is the main question. params_for generates 4 digits and 2 letters for postal_code (could be lowercase or uppercase). If the params_for would be going trough the changeset, it would be all…
Robert
  • 504
  • 5
  • 27
0
votes
1 answer

Ecto Sandbox use checked out connection for existing process

I have a Phoenix Test Application with a Product schema. I have a GenServer started by the main application supervisor that gets a list of the products with handle_call. def handle_call(:get_products, _from, _state) products = Repo.all(Product) …
iacobSon
  • 133
  • 10
0
votes
1 answer

Elixir List Comprehension to Create a New List of Structs

I'm quite new to Elixir, and trying to yield a new list of structs using list comprehension, and for the life of me I can't seem to get this right: holdings = ServiceX.update_holdings( fn() -> for n <- 1..3, do: n end, &(for n <-…
J du Preez
  • 145
  • 9
0
votes
1 answer

Passing tests with Guardian.Plug.EnsureAuthenticated when authenticating with LDAP

I followed the guide at http://rny.io/elixir/phoenix/ldap/2016/09/20/ldap-authenication-with-phoenix.html to setup LDAP authentication with Guardian in Phoenix. I am fairly new to Phoenix and Elixir so I am going through the motions of setting…
willfore
  • 170
  • 1
  • 10
0
votes
2 answers

How to flush your database using Repo

More specifically I have a Phoenix Application using Ecto and Repo. I would like to flush my database after running each Exunit test which alters the database. One way I could accomplish this would be to run all of the change functions in the…
Sam Houston
  • 3,413
  • 2
  • 30
  • 46
0
votes
1 answer

Why are objects inserted in database in the setup_all block not appearing in a test block?

I have similar tests in controllers and the setup_all inserts are available in the test blocks. Here I'm trying to allow the same thing in my models and I can't seem to make it work. I have a test as follows: defmodule Faq.QuestionTest do use…
Gary Haran
  • 677
  • 1
  • 8
  • 16
0
votes
0 answers

How to test channel with Phoenix.ChannelTest.close/2

I have a test that starts up a socket connection and subscribes and joins a topic. I then push a message to the channel which does some work and persist some data. I then use ChannelTest.close/2 on the socket which simulates the client closing the…
Alejandro Huerta
  • 1,135
  • 2
  • 17
  • 35
0
votes
1 answer

Elixir / Phoenix - Run code at the very beginning of a test run, shared data for ALL tests

I'd like to run a block of code right at the beginning of my test suite (that inserts data into the database!), and persists across the entirety of the test suite. Is something like this possible? I tried running the code in a setup_all block,…
Brandon
  • 3,091
  • 2
  • 34
  • 64
0
votes
1 answer

How to implement some command before ExUnit test with some tag starts

I have a test suite which uses wallaby library which needs a heavyweight webpack build for usage. The problem is that I this webpack build is too heavy to use it before only model test, for example. So, I decided about this feature: Tag all wallaby…
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142
0
votes
1 answer

How can I specify format in the Phoenix.ConnTest?

I have a pretty simple code in the phoenix controller. It does some stuff and returns content depending on the format: def delete(conn, _params) do # some stuff here if get_format(conn) == "json" do conn |> put_status(200) |> json(%{}) …
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142
0
votes
1 answer

How do I make an invalid attributes test pass with zero allowed or required attributes

Using Ecto 2.0 I'm trying to make this test pass: defmodule PlexServer.FleetInstanceTest do use PlexServer.ModelCase alias PlexServer.FleetInstance @invalid_attrs %{some_random_data: "random data"} test "changeset with invalid attributes"…
Alejandro Huerta
  • 1,135
  • 2
  • 17
  • 35
-1
votes
1 answer

Message passing with state[:pid] fails, freshly generated pid works

My second test is failing. 1) test it jumps when it can (RunnerTest) test/runner_test.exs:15 No message matching %{y: 1} after 100ms. The process mailbox is empty. stacktrace: test/runner_test.exs:18: (test) defmodule…
quantumpotato
  • 9,637
  • 14
  • 70
  • 146
1 2 3 4 5 6 7
8