@@ -685,11 +685,8 @@ defmodule Mox do
685
685
:ok ->
686
686
:ok
687
687
688
- { :error , error } when is_binary ( error ) ->
689
- raise ArgumentError , error
690
-
691
688
{ :error , error } ->
692
- raise error
689
+ raise_cannot_add_expectation! ( error , mock )
693
690
end
694
691
end
695
692
@@ -700,14 +697,41 @@ defmodule Mox do
700
697
:ok ->
701
698
:ok
702
699
703
- { :error , error } when is_binary ( error ) ->
704
- raise ArgumentError , error
705
-
706
700
{ :error , error } ->
707
- raise error
701
+ raise_cannot_add_expectation! ( error , mock )
708
702
end
709
703
end
710
704
705
+ defp raise_cannot_add_expectation! (
706
+ % NimbleOwnership.Error { reason: { :already_allowed , owner_pid } } ,
707
+ mock
708
+ ) do
709
+ inspected = inspect ( self ( ) )
710
+
711
+ raise ArgumentError , """
712
+ cannot add expectations/stubs to #{ inspect ( mock ) } in the current process (#{ inspected } ) \
713
+ because the process has been allowed by #{ inspect ( owner_pid ) } . \
714
+ You cannot define expectations/stubs in a process that has been allowed
715
+ """
716
+ end
717
+
718
+ defp raise_cannot_add_expectation! (
719
+ % NimbleOwnership.Error { reason: { :not_shared_owner , global_pid } } ,
720
+ mock
721
+ ) do
722
+ inspected = inspect ( self ( ) )
723
+
724
+ raise ArgumentError , """
725
+ cannot add expectations/stubs to #{ inspect ( mock ) } in the current process (#{ inspected } ) \
726
+ because Mox is in global mode and the global process is #{ inspect ( global_pid ) } . \
727
+ Only the process that set Mox to global can set expectations/stubs in global mode
728
+ """
729
+ end
730
+
731
+ defp raise_cannot_add_expectation! ( error , _mock ) do
732
+ raise error
733
+ end
734
+
711
735
@ doc """
712
736
Allows other processes to share expectations and stubs
713
737
defined by owner process.
@@ -937,28 +961,8 @@ defmodule Mox do
937
961
update_fun = & { :ok , init_or_merge_expectations ( & 1 , key_expectation_list ) }
938
962
939
963
case get_and_update ( owner_pid , mock , update_fun ) do
940
- { :ok , value } ->
941
- value
942
-
943
- { :error , % NimbleOwnership.Error { reason: { :already_allowed , _ } } } ->
944
- inspected = inspect ( self ( ) )
945
-
946
- { :error ,
947
- """
948
- cannot add expectations/stubs to #{ inspect ( mock ) } in the current process (#{ inspected } ) \
949
- because the process has been allowed by #{ inspect ( owner_pid ) } . \
950
- You cannot define expectations/stubs in a process that has been allowed
951
- """ }
952
-
953
- { :error , % NimbleOwnership.Error { reason: { :not_shared_owner , global_pid } } } ->
954
- inspected = inspect ( self ( ) )
955
-
956
- { :error ,
957
- """
958
- cannot add expectations/stubs to #{ inspect ( mock ) } in the current process (#{ inspected } ) \
959
- because Mox is in global mode and the global process is #{ inspect ( global_pid ) } . \
960
- Only the process that set Mox to global can set expectations/stubs in global mode
961
- """ }
964
+ { :ok , _value } ->
965
+ :ok
962
966
963
967
{ :error , error } ->
964
968
{ :error , error }
0 commit comments