Calling `rewire` in `setup` block fails
uberbrodt opened this issue · comments
When I put a call to rewire
in the setup block of my test suite, the tests use the original module instead of the generated one
You mean like this?
defmodule MyTest do
use ExUnit.Case, async: true
import Rewire
setup do
rewire MyModule, ...
end
test "start/0" do
# MyModule is still the same, not the mocked one
end
end
If that's the case, that would be expected behaviour. The rewire
essentially becomes an alias here and will only be active inside the setup
block's scope, not outside of it. Is there a reason you don't want to/can't put it outside of the setup block like in the README example?
Ah, I see now. Sorry, I just intuitively put it in the setup block and it seemed odd that it didn't work there. Putting it at the module level works for me 👍
Awesome! It's a good reminder for me to highlight this more in the README. I can totally see how you'd expect this.