In my phoenix controller testing, I am doing something like this,
describe "update/2" do
setup [:create_user]
test "Edits, and responds with the user if attributes are valid", %{conn: conn, user: user} do
response =
conn
|> put(user_path(conn, :update, user.id, @update_attrs))
|> json_response(200)
expected = %{
"data" =>
%{"currentCity" => "pune", "mobileNumber" => "1234567890"}
}
assert expected == response
end
And my response map is
%{
"data" => %{"currentCity" => "pune",
"mobileNumber" => "1234567890",
"name" => "xyz",
"gender" => "male"}}
Since my response map contains extra keys which is not present in expected map, so the assertion with ==
fails, so I am trying to do assertion with patter matching like this
assert expected = response
but In this case assertion is always true no matter what the are the values in expected and response.
I am confused what's happening with the pattern matching in the case of maps.