-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better documentation for find_case #71
Comments
Yeah, this is an area that needs some work. assert_fs and assert_cmd have some examples, for example: https://github.com/assert-rs/assert_cmd/blob/master/src/assert.rs#L255 Something else I've been meaning to do is write a hamcrest-like crate for so you can just do |
btw the |
@epage I have created a simple pub use predicates;
pub use predicates_tree;
#[macro_export]
macro_rules! assert_that {
($item:expr, $pred:expr $(,)?) => {{
use $crate::predicates::prelude::*;
use $crate::predicates_tree::CaseTreeExt;
if let Some(case) = $pred.find_case(false, $item) {
panic!("{}", case.tree());
};
}};
} Is this good enough for a first pass at inclusion to the library? I'd be happy to adapt it and open a PR if so. I'm not sure if this would be part of |
Sounds great, thanks!
Hmm, thats an interesting point. It should either go in
Thoughts? |
Hmm, maybe a separate crate does make sense. Without it, users would need to either opt-in or opt-out of using this macro, since it creates a new dependency. Having a feature flag for a single convenience macro seems a little heavy-handed to me, but so does a new crate for that matter. I think it is generally a somewhat common practice to have macro-only crates as conveniences for working with library crates, although in my experience those tend to be complex procedural macros which generate a lot of boilerplate code, rather than something simple like this. For what it's worth, it seems the name extern crate assert_that;
use assert_that::assert_that;
#[test]
fn does_it_work() {
// expands to use re-exported predicate, i.e.
// `assert_that::predicates::prelude::predicate::str::similar`
assert_that!("Hello world", str::similar("Goodbye, world"));
} I could see some additional extensions potentially being added to this, although I think most code changes would be made in the Perhaps future extensions could include helper macros for writing custom predicates ("matchers") like their Assuming that a separate crate makes sense – would you prefer to create a separate repo, or just a subcrate within this repo's Cargo workspace? |
Like with the other crates (assert_fs, assert_cmd), I'm thinking separate crate but can also live in this org. |
@epage I have created and published a 0.1 version of I also created ian-h-chamberlain/assert_that#2 where we can discuss whether or not it makes sense to move it to this organization. I'm inclined to wait and see if the crate gets much/any usage or new use cases arise before transferring ownership, but if you'd rather transfer it sooner I think that would be fine. |
Thanks! Excited to see this develop! |
It sounds like
Predicate::find_case
is important, but for the life of me I can't figure out how to use it. Could you please expand its documentation? What I'm looking for is a way to do something like this, so I can print a useful message whenever a predicate fails.The text was updated successfully, but these errors were encountered: