11//! ## A test specification DSL for deciders and views that supports the given-when-then format.
22
3+ use pretty_assertions:: assert_eq;
4+
35use crate :: {
46 decider:: { Decider , EventComputation , StateComputation } ,
57 view:: { View , ViewStateComputation } ,
4042
4143impl < ' a , Command , State , Event , Error > DeciderTestSpecification < ' a , Command , State , Event , Error >
4244where
45+ Command : std:: fmt:: Debug ,
4346 Event : PartialEq + std:: fmt:: Debug ,
4447 State : PartialEq + std:: fmt:: Debug ,
4548 Error : PartialEq + std:: fmt:: Debug ,
9194 panic ! ( "Events were expected but the decider returned an error instead: {error:?}" )
9295 }
9396 } ;
94- assert_eq ! ( new_events, expected_events) ;
97+ assert_eq ! (
98+ new_events, expected_events,
99+ "Actual and Expected events do not match!\n Command: {command:?}\n " ,
100+ ) ;
95101 }
96102
97103 #[ allow( dead_code) ]
@@ -113,7 +119,10 @@ where
113119 panic ! ( "State was expected but the decider returned an error instead: {error:?}" )
114120 }
115121 } ;
116- assert_eq ! ( new_state, expected_state) ;
122+ assert_eq ! (
123+ new_state, expected_state,
124+ "Actual and Expected states do not match.\n Command: {command:?}\n "
125+ ) ;
117126 }
118127
119128 #[ allow( dead_code) ]
@@ -135,7 +144,10 @@ where
135144 }
136145 Err ( error) => error,
137146 } ;
138- assert_eq ! ( error, expected_error) ;
147+ assert_eq ! (
148+ error, expected_error,
149+ "Actual and Expected errors do not match.\n Command: {command:?}\n "
150+ ) ;
139151 }
140152}
141153
@@ -168,6 +180,7 @@ where
168180impl < ' a , State , Event > ViewTestSpecification < ' a , State , Event >
169181where
170182 State : PartialEq + std:: fmt:: Debug ,
183+ Event : std:: fmt:: Debug ,
171184{
172185 #[ allow( dead_code) ]
173186 /// Specify the view you want to test
@@ -197,6 +210,9 @@ where
197210 let event_refs: Vec < & Event > = events. iter ( ) . collect ( ) ;
198211 let new_state_result = view. compute_new_state ( Some ( initial_state) , & event_refs) ;
199212
200- assert_eq ! ( new_state_result, expected_state) ;
213+ assert_eq ! (
214+ new_state_result, expected_state,
215+ "Actual and Expected states do not match.\n Events: {events:?}\n "
216+ ) ;
201217 }
202218}
0 commit comments