Skip to content

Commit

Permalink
Check if Mix is present before using Mix.env()
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaszubowski authored and amatalai committed Oct 13, 2017
1 parent 4b6901a commit 8d87a8a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/mockery.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Mockery do
module | proxy
def of(mod, opts \\ []) when is_atom(mod)
when is_binary(mod) do
env = opts[:env] || Mix.env
env = opts[:env] || mix_env()

if env != :test do
to_mod(mod)
Expand Down Expand Up @@ -107,4 +107,8 @@ defmodule Mockery do

mod
end

defp mix_env do
if Kernel.function_exported?(Mix, :env, 0), do: Mix.env(), else: :prod
end
end

0 comments on commit 8d87a8a

Please sign in to comment.