@@ -47,25 +47,34 @@ def cleaned_value
4747
4848 # Is this observation equivalent to another?
4949 #
50- # other - the other Observation in question
51- # comparator - an optional comparison block. This observation's value and the
52- # other observation's value are yielded to this to determine
53- # their equivalency. Block should return true/false.
50+ # other - the other Observation in question
51+ # comparator - an optional comparison proc. This observation's value and the
52+ # other observation's value are passed to this to determine
53+ # their equivalency. Proc should return true/false.
54+ # error_comparator - an optional comparison proc. This observation's Error and the
55+ # other observation's Error are passed to this to determine
56+ # their equivalency. Proc should return true/false.
5457 #
5558 # Returns true if:
5659 #
5760 # * The values of the observation are equal (using `==`)
5861 # * The values of the observations are equal according to a comparison
59- # block, if given
62+ # prod, if given
63+ # * The exceptions raised by the obeservations are equal according to the
64+ # error comparison proc, if given.
6065 # * Both observations raised an exception with the same class and message.
6166 #
6267 # Returns false otherwise.
63- def equivalent_to? ( other , & comparator )
68+ def equivalent_to? ( other , comparator = nil , error_comparator = nil )
6469 return false unless other . is_a? ( Scientist ::Observation )
6570
6671 if raised? || other . raised?
67- return other . exception . class == exception . class &&
68- other . exception . message == exception . message
72+ if error_comparator
73+ error_comparator . call ( exception , other . exception )
74+ else
75+ return other . exception . class == exception . class &&
76+ other . exception . message == exception . message
77+ end
6978 end
7079
7180 if comparator
0 commit comments