Skip to content

Commit

Permalink
feat(#36): creates_new_ignore_file, tempdir
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Aug 26, 2024
1 parent adc92ab commit 73f2bfc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ testing_logger = "0.1.1"

[dev-dependencies]
assert_cmd = "2.0.14"
tempdir = "0.3.7"

[features]
default = ["cli"]
Expand Down
37 changes: 31 additions & 6 deletions src/args/ignore_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,36 @@ impl IgnoreFile {

/// Facts.
pub fn facts(self) -> HashMap<String, Vec<String>> {
let file = File::open(self.name);
let reader = BufReader::new(file);
let facts: Vec<String> = reader.lines()
.filter_map(Result::ok)
.collect();
parse_facts(facts)
match File::open(self.name.clone()) {
Ok(file) => {
let reader = BufReader::new(file);
let facts: Vec<String> =
reader.lines().filter_map(Result::ok).collect();
parse_facts(facts)
}
Err(err) => {
panic!("Can not read facts from {}, due to: {}", self.name, err)
}
}
}
}

#[cfg(test)]
mod tests {
use crate::args::ignore_file::IgnoreFile;
use anyhow::Result;
use hamcrest::{equal_to, is, HamcrestMatcher};
use tempdir::TempDir;

#[test]
fn creates_new_ignore_file() -> Result<()> {
let temp = TempDir::new("temp")?;
let name = "ignore.ghiqc";
let path = temp.path().join(name);
let ignore = IgnoreFile::new(String::from(
path.to_str().expect("Path does not exists"),
));
assert_that!(ignore.name.is_empty(), is(equal_to(false)));
Ok(())
}
}

0 comments on commit 73f2bfc

Please sign in to comment.