Implement assert a file matches a fixture on disk#43
Conversation
src/path/ft.rs
Outdated
| self | ||
| } | ||
|
|
||
| pub(crate) fn new(path: &path::Path) -> io::Result<FileTypePredicate> { |
There was a problem hiding this comment.
Would it be useful to make this pub?
What about naming it from_path or with_path?
src/path/ft.rs
Outdated
| }) | ||
| } | ||
|
|
||
| pub(crate) fn is_file(&self) -> bool { |
There was a problem hiding this comment.
I think I'd rather we just return the file type.
src/path/fs.rs
Outdated
|
|
||
| impl Predicate<path::Path> for StrFilePredicate { | ||
| fn eval(&self, path: &path::Path) -> bool { | ||
| let content = FileContent::new(path).unwrap().utf8(); |
src/path/fs.rs
Outdated
|
|
||
| impl fmt::Display for StrFilePredicate { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| write!(f, "content is {}", self.content) |
There was a problem hiding this comment.
- this should be
var is {} - Should we print
contentor path?
src/path/fs.rs
Outdated
|
|
||
| /// Predicate that compares file matches | ||
| #[derive(Clone, Debug)] | ||
| pub struct FileSystemEntryPredicate { |
There was a problem hiding this comment.
Should we make this only work with files? We can handle dirs like we handle symlinks or non-existent files
If we keep it handling dirs, maybe shorten the name to EntryPredicate?
src/path/fs.rs
Outdated
| impl Predicate<path::Path> for FileSystemEntryPredicate { | ||
| fn eval(&self, path: &path::Path) -> bool { | ||
| if self.file_type.is_file() { | ||
| if !self.file_type.eval(path) { |
There was a problem hiding this comment.
I feel like it might be simpler if we just reused FileType and not FileTypePredicate
src/path/fs.rs
Outdated
| if !self.file_type.eval(path) { | ||
| false | ||
| } else { | ||
| self.file_content.clone().unwrap() == FileContent::new(path).unwrap() |
There was a problem hiding this comment.
self.file_content.as_ref().unwrap() addresses the clone
The first unwrap should probably be an expect so you can document your assumption of why it is always safe to unwrap in this context.
Should the second unwrap instead have us return false?
src/path/fs.rs
Outdated
|
|
||
| impl fmt::Display for FileSystemEntryPredicate { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| write!(f, "var is {}", self.file_type) |
There was a problem hiding this comment.
Should it be file_type or the path? The downside being we'd have to store off the path
src/path/fs.rs
Outdated
| /// assert_eq!(false, predicate_dir.eval(Path::new("Cargo.toml"))); | ||
| /// assert_eq!(true, predicate_dir.eval(Path::new("src"))); | ||
| /// ``` | ||
| pub fn eq_file_system_entry(path: &path::Path) -> FileSystemEntryPredicate { |
There was a problem hiding this comment.
Again, we can shorten this to eq_entry if it accepts multiple types f eq_file if it only works with files
d223bb0 to
9c62111
Compare
|
I integrated all changes. |
|
For background, we decided to simplify the If someone wants to compare a dir, they can use |
epage
left a comment
There was a problem hiding this comment.
Some minor clean up that I thought I'd point out since you have to go back and address clippy.
If you already have addressed clippy. oh well, this PR can move forward and it can be cleaned up later.
src/prelude.rs
Outdated
| /// This module contains predicates specific to path handling. | ||
| pub mod path { | ||
| pub use path::eq_file; | ||
| pub use path::FileTypePredicate; |
There was a problem hiding this comment.
Why was FileTypePredicate added to the prelude?
The goal has been just to expose the minimum for creating predicates and not for general operation of the crate.
Was it because FileTypePredicate::from_path? I'd say remove the predicate from the prelude and lets worry later about how we want it exposed in to the user.
There was a problem hiding this comment.
Was it because FileTypePredicate::from_path? Correct!
src/path/mod.rs
Outdated
| mod fc; | ||
| pub use self::fc::{FileContentPredicate, PredicateFileContentExt}; | ||
| mod fs; | ||
| pub use self::fs::eq_file; |
There was a problem hiding this comment.
This should publicly expose BinaryFilePredicate and StrFilePredicate
9c62111 to
4d0569f
Compare
4d0569f to
a69f72f
Compare
|
Fixed both request and the clippy failure |
Implement assert a file matches a fixture on disk
Partial fixes #32