spy 0.2.0

Rust spy functions for testing purposes
Documentation
  • Coverage
  • 92.86%
    13 out of 14 items documented2 out of 13 items with examples
  • Size
  • Source code size: 28.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.77 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • AlexPikalov/spy
    11 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • AlexPikalov

Spy Build Status


Documentation

Spy crate is inspired by such famous Javascript testing tools as Jasmine and Sinon.js. It provides easy configurable spies with predefined behaviour.

#[test]
fn iterator_all_test() {
   let integers = vec![0i32, 1i32, 2i32];

   // create spy function that returns true if provided
   // argument is an even number
   let (spy_fn, spy) = spy!(|n| n % 2 == 0);

   // test call
   let res = integers.iter().all(spy_fn);

   // check Iterator::all result
   assert!(!res, "should be false");

   // take a snapshot of made calls
   let snapshot = spy.snapshot();

   // make assertions
   assert!(snapshot.called(), "should be called");
   assert!(
       snapshot.called_with(&(&1i32)),
       "should be called with 1i32 at least once"
   );
   assert!(
       !snapshot.each_called_with(&(&1i32)),
       "should be called with different arguments"
   );
   assert_eq!(snapshot.all_calls(), &vec![(&0i32), (&1i32)]);
   assert_eq!(snapshot.first_call().expect("should be Some"), &(&0i32));
   assert_eq!(snapshot.last_call().expect("should be Some"), &(&1i32));
   assert_eq!(snapshot.nth_call(1).expect("should be Some"), &(&1i32));
}

LICENSE

Spy is licensed under MIT and Apache-2.0 license