Skip to main content

assert_changes

Function assert_changes 

Source
pub fn assert_changes<T: PartialEq + Debug>(
    expression: impl FnMut() -> T,
    block: impl FnOnce(),
) -> (T, T)
Expand description

Asserts that block changes what expression returns (Rails’ assert_changes), and returns (before, after).

§Examples

let title = std::cell::RefCell::new("Draft".to_owned());
let (before, after) = ocre::testing::assert_changes(|| title.borrow().clone(), || *title.borrow_mut() = "Final".into());
assert_eq!((before.as_str(), after.as_str()), ("Draft", "Final"));