elixir-cldr / cldr

Elixir implementation of CLDR/ICU
Other
451 stars 34 forks source link

No configured locale could be matched #111

Closed sergey-chechaev closed 5 years ago

sergey-chechaev commented 5 years ago

I have the warning: [warn] Elixir.Cldr.NoMatchingLocale: No configured locale could be matched to "test" in my Phoenix test case:

 test "when wrong locale sets to default_locale" do
    header_locale = "test"
    build_conn()
    |> put_req_header("accept", "application/json")
    |> put_req_header("accept-language", header_locale)
    |> AcceptLanguage.call(%{})
    |> SetLocale.call(%{})

    assert Cldr.get_current_locale == Cldr.default_locale
  end

How I can test this case without warning?

kipcole9 commented 5 years ago

@sergey-chechaev, wrapping the test in capture_log should do it. For example:

import ExUnit.CaptureLog

test "when wrong locale sets to default_locale" do
  capture_log(fn ->
    header_locale = "test"
    build_conn()
    |> put_req_header("accept", "application/json")
    |> put_req_header("accept-language", header_locale)
    |> AcceptLanguage.call(%{})
    |> SetLocale.call(%{})
  end)
  assert Cldr.get_current_locale == Cldr.default_locale
end