Skip to content

Commit

Permalink
feat: add clear opt with test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubashwer committed Mar 12, 2023
1 parent d907e0f commit ab96375
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 0 deletions.
153 changes: 153 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ description = "A CLI app which can help users automatically add co-author(s) to
[dependencies]
clap = { version = "4.1.8", features = ["derive"] }
inquire = "0.6.0"

[dev-dependencies]
mockall = "0.11.3"
3 changes: 3 additions & 0 deletions src/coauthor_repo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::process::Command;

#[cfg(test)]
use mockall::{automock, predicate::*};
#[cfg_attr(test, automock)]
pub trait CoauthorRepo {
fn list(&self) -> Vec<String>;
fn get(&self, key: &str) -> String;
Expand Down
33 changes: 33 additions & 0 deletions src/commands/mob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ pub struct Mob {
/// Sets active co-author(s) for pair/mob programming
#[arg(short='w', long="with", num_args=0.., value_name="COAUTHOR_KEY")]
with: Option<Vec<String>>,
/// Clears mob/pair programming session. Going solo!
#[arg(short = 'c', long = "clear")]
clear: bool,
}

impl Mob {
pub fn handle(&self, coauthor_repo: &dyn CoauthorRepo) {
if self.clear {
coauthor_repo.deactivate_all();
}

if self.with.is_none() {
return;
}

let coauthor_keys = self.with.as_ref().unwrap();

match coauthor_keys.len() {
Expand Down Expand Up @@ -51,3 +62,25 @@ impl Mob {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::coauthor_repo::MockCoauthorRepo;

#[test]
fn test_clear_deactivates_all_coauthors() {
let mut mock_coauthor_repo = MockCoauthorRepo::new();
mock_coauthor_repo
.expect_deactivate_all()
.once()
.return_const({});

let mob = Mob {
with: None,
clear: true,
};

mob.handle(&mock_coauthor_repo);
}
}

0 comments on commit ab96375

Please sign in to comment.