funnybot 0.1.0

Simple/naive helper for custom mocking: record arguments, return pre-recorded values
Documentation
  • Coverage
  • 80%
    8 out of 10 items documented0 out of 9 items with examples
  • Size
  • Source code size: 17.56 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.3 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • elmarx/funnybot
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • elmarx

Rust build crates.io badge docs.rs badge

Funnybot

Simple/naive helper for custom mocking: record arguments, return pre-recorded values.

Since recording requires arguments, funnybot's main job is to hide that behind RwLock, and generally to take out verbosity out of manual mocking.

Example


struct MockRepository<'a> {
    // funnybot-instance to hold recorded arguments (here: `String`) and return-values (here: list of String)
    pub group_members: FunnyBot<'a, String, Vec<String>>
}

impl<'a> Repository for MockRepository<'a> {
    async fn list_group_members(&self, group_id: &str) -> Vec<String> {
        self.group_members.call(group_id.to_owned())
    }   
}

#[test]
fn test_something() {
    let mock_repository = MockRepositry {
        group_members: FunnyBot::repeat(vec!["stan", "kyle", "eric", "kenny"])
    };

    let subject = Subject::new(&mock_repository);
  
    let actual = subject.my_function();
  
    assert_eq!(mock_repository.group_members.args(), vec["main-characters"]);
    assert_eq!(actual,);
}