Testing dynamic data in controller tests

Tags: #<Tag:0x00007f113e60e0b8> #<Tag:0x00007f113e60df78>


I’m trying to test dynamic data in a controller test but it doesn’t seem to work.
This is my test

  test ":show renders the right article", %{conn: conn} do
    article = Repo.insert! %Article{}
    conn = get conn, article_path(conn, :show, article)
    assert html_response(conn, 200) =~ article.title

And here is the test failing

** (FunctionClauseError) no function clause matching in Regex.match?/2

It also comes with a long stacktrace which is just the page’s html.

How exactly should I assert article.title?


looking at %Article{}, your article is gonna have a nil title and that breaks Regex.match?/2. try setting a non-nil title.


Now it makes sense.
Thanks, I fixed the test and now it passes.