Skip to content

Commit 9f7ad2b

Browse files
committed
improved test specififcation DSL to pretty print/assert
1 parent d2de602 commit 9f7ad2b

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "Apache-2.0"
77

88
[dependencies]
99
serde = {version = "1.0.200", features = ["derive"]}
10-
10+
pretty_assertions = "1.4.1"
1111

1212
[dev-dependencies]
1313
derive_more = { version = "2", features = ["display"] }

src/specification.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! ## A test specification DSL for deciders and views that supports the given-when-then format.
22
3+
use pretty_assertions::assert_eq;
4+
35
use crate::{
46
decider::{Decider, EventComputation, StateComputation},
57
view::{View, ViewStateComputation},
@@ -40,6 +42,7 @@ where
4042

4143
impl<'a, Command, State, Event, Error> DeciderTestSpecification<'a, Command, State, Event, Error>
4244
where
45+
Command: std::fmt::Debug,
4346
Event: PartialEq + std::fmt::Debug,
4447
State: PartialEq + std::fmt::Debug,
4548
Error: PartialEq + std::fmt::Debug,
@@ -91,7 +94,10 @@ where
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!\nCommand: {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.\nCommand: {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.\nCommand: {command:?}\n"
150+
);
139151
}
140152
}
141153

@@ -168,6 +180,7 @@ where
168180
impl<'a, State, Event> ViewTestSpecification<'a, State, Event>
169181
where
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.\nEvents: {events:?}\n"
216+
);
201217
}
202218
}

0 commit comments

Comments
 (0)