Skip to content

Instantly share code, notes, and snippets.

@knewter
Created August 7, 2016 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knewter/073696b6d0eca035513095a5a64ef2af to your computer and use it in GitHub Desktop.
Save knewter/073696b6d0eca035513095a5a64ef2af to your computer and use it in GitHub Desktop.
`assert_push` weirdness

If I run the tests with the code in bad.ex, I get the following:

warning: variable expected_song is unused
  test/channels/collusion_channel_test.exs:16

If I use good.ex, it works. (naming!)

This is a macro that's doing a match behind the scenes. If I am not careful to write a test that fails first, I'll think this works when it doesn't because it binds whatever I pass. For instance, if I change the test such that expected_song = %{}, which is not what the channel sends me, it will still pass without the hat obviously (though it does throw a warning)

This is super weird to me.

test "sends the collusion's state to the client on join", %{id: id} do
expected_song = Song.init(id)
assert_push "collusion:state", expected_song
end
test "sends the collusion's state to the client on join", %{id: id} do
expected_song = Song.init(id)
assert_push "collusion:state", ^expected_song
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment