If I start up an instance of my phoenix app and hit it with requests, my plugs will halt appropriately. However, doing the same in a test environment, halt doesn't stop plugs downstream from being invoked which causes my tests to fail. I think the issue might come from the way I'm invoking the router during my test. Here's the helper function I'm using that is heavily borrowed from a similar function in the phoenix framework itself:
def call(router, verb, path, params \\ nil, headers \\ []) do
add_headers(conn(verb, path, params), headers)
|> Plug.Conn.fetch_params
|> Plug.Parsers.call(parsers: [Plug.Parsers.JSON],
pass: ["*/*"],
json_decoder: Poison)
|> router.call(router.init([]))
end
Any ideas as to why calling my router like this causes halting to stop working?
EDIT: So I'm upgrading to Phoenix 0.13.1 in order to use their new endpoint testing module instead of the helper I rolled. I'll report back as to whether this fixes the issue or not.
halt
only works inside the plug pipeline. If you are manually piping then you would need to manually check for halt.
Honestly, I would drop your current pipeline and just invoke the actual endpoint from your tests. The endpoint pipeline is very fast, you shouldn't see any slow down really.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With