Testing dynamic data in controller tests

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
 end

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.

1 Like

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