diff --git a/src/assert.rs b/src/assert.rs index 175b843..e9422cb 100644 --- a/src/assert.rs +++ b/src/assert.rs @@ -154,7 +154,15 @@ impl Assert { /// .assert() /// .code(predicates::ord::eq(42)); /// ``` - pub fn code(self, pred: &predicates::Predicate) -> Self { + pub fn code(self, pred: I) -> Self + where + I: IntoCodePredicate

, + P: predicates::Predicate, + { + self.code_impl(&pred.into_code()) + } + + fn code_impl(self, pred: &predicates::Predicate) -> Self { let actual_code = self.output .status .code() diff --git a/tests/assert.rs b/tests/assert.rs new file mode 100644 index 0000000..e4173b9 --- /dev/null +++ b/tests/assert.rs @@ -0,0 +1,22 @@ +extern crate assert_cmd; +extern crate predicates; + +use std::process::Command; + +use assert_cmd::prelude::*; +use predicates::prelude::*; + +#[test] +fn code_example() { + Command::main_binary() + .unwrap() + .env("exit", "42") + .assert() + .code(42); + // which is equivalent to + Command::main_binary() + .unwrap() + .env("exit", "42") + .assert() + .code(predicate::eq(42)); +}