funnybot

Crates.iofunnybot
lib.rsfunnybot
version0.1.0
sourcesrc
created_at2020-07-20 16:24:18.29116
updated_at2020-07-20 16:24:18.29116
descriptionSimple/naive helper for custom mocking: record arguments, return pre-recorded values
homepagehttps://github.com/elmarx/funnybot
repositoryhttps://github.com/elmarx/funnybot.git
max_upload_size
id267296
size17,937
Elmar Athmer (elmarx)

documentation

README

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, …);
}

Commit count: 5

cargo fmt